Skip to content

Commit

Permalink
Merge pull request #28768 from magento/storefront-2.4-merge
Browse files Browse the repository at this point in the history
[17] Merge api-proto with develop #71
  • Loading branch information
le0n4ik authored Jun 18, 2020
2 parents d946618 + a3d3fe2 commit 7a812cd
Show file tree
Hide file tree
Showing 12 changed files with 180 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function setUp(): void
*
* @magentoApiDataFixture Magento/SalesRule/_files/rules_rollback.php
* @magentoApiDataFixture Magento/Sales/_files/quote.php
* @magentoAppIsolation enabled
*/
public function testGetList()
{
Expand Down Expand Up @@ -87,6 +88,7 @@ public function testGetList()

/**
* @magentoApiDataFixture Magento/Sales/_files/invoice.php
* @magentoAppIsolation enabled
*/
public function testAutoGeneratedGetList()
{
Expand Down Expand Up @@ -131,6 +133,7 @@ public function testAutoGeneratedGetList()
* Test get list of orders with extension attributes.
*
* @magentoApiDataFixture Magento/Sales/_files/order.php
* @magentoAppIsolation enabled
*/
public function testGetOrdertList()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,12 @@ public function __construct(
$loadTestExtensionAttributes = false
) {
if (getcwd() != BP . '/dev/tests/integration') {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
chdir(BP . '/dev/tests/integration');
}
$this->_shell = $shell;
$this->installConfigFile = $installConfigFile;
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$this->_globalConfigDir = realpath($globalConfigDir);
$this->_appMode = $appMode;
$this->installDir = $installDir;
Expand Down Expand Up @@ -251,6 +253,7 @@ public function getDbInstance()
protected function getInstallConfig()
{
if (null === $this->installConfig) {
// phpcs:ignore Magento2.Security.IncludeFile
$this->installConfig = include $this->installConfigFile;
}
return $this->installConfig;
Expand Down Expand Up @@ -293,6 +296,7 @@ public function getInitParams()
*/
public function isInstalled()
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return is_file($this->getLocalConfig());
}

Expand Down Expand Up @@ -419,11 +423,23 @@ public function initialize($overriddenParams = [])
$sequence = $objectManager->get(\Magento\TestFramework\Db\Sequence::class);
$sequence->generateSequences();
}

$this->createDynamicTables();
$objectManager->create(\Magento\TestFramework\Config::class, ['configPath' => $this->globalConfigFile])
->rewriteAdditionalConfig();
}

/**
* Create dynamic tables
*
* @return void
*/
protected function createDynamicTables()
{
/** @var \Magento\TestFramework\Db\DynamicTables $dynamicTables */
$dynamicTables = Helper\Bootstrap::getObjectManager()->get(\Magento\TestFramework\Db\DynamicTables::class);
$dynamicTables->createTables();
}

/**
* Reset and initialize again an already installed application
*
Expand Down Expand Up @@ -552,8 +568,10 @@ private function copyAppConfigFiles()
);
foreach ($globalConfigFiles as $file) {
$targetFile = $this->_configDir . str_replace($this->_globalConfigDir, '', $file);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$this->_ensureDirExists(dirname($targetFile));
if ($file !== $targetFile) {
// phpcs:ignore Magento2.Functions.DiscouragedFunction
copy($file, $targetFile);
}
}
Expand All @@ -567,6 +585,7 @@ private function copyAppConfigFiles()
private function copyGlobalConfigFile()
{
$targetFile = $this->_configDir . '/config.local.php';
// phpcs:ignore Magento2.Functions.DiscouragedFunction
copy($this->globalConfigFile, $targetFile);
}

Expand Down Expand Up @@ -636,10 +655,13 @@ protected function _resetApp()
*/
protected function _ensureDirExists($dir)
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
if (!file_exists($dir)) {
$old = umask(0);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
mkdir($dir, 0777, true);
umask($old);
// phpcs:ignore Magento2.Functions.DiscouragedFunction
} elseif (!is_dir($dir)) {
throw new \Magento\Framework\Exception\LocalizedException(__("'%1' is not a directory.", $dir));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestFramework\Db\DymanicTables;

use Magento\Framework\App\ResourceConnection;
use Magento\Store\Model\Store;

/**
* Class to pre-create category product index tables
*/
class CategoryProductIndexTables
{

/**
* @var string
*/
private $prototype = 'catalog_category_product_index';

/**
* @var ResourceConnection
*/
private $resourceConnection;

/**
* @param ResourceConnection $resourceConnection
*/
public function __construct(
ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

/**
* Creates category product index tables
*/
public function createTables(): void
{
$connection = $this->resourceConnection->getConnection();
for ($storeId = 0; $storeId <= 256; $storeId++) {
$connection->createTable(
$connection->createTableByDdl(
$this->resourceConnection->getTableName($this->prototype),
$this->resourceConnection->getTableName($this->prototype) . '_' . Store::ENTITY . $storeId
)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\TestFramework\Db;

use Magento\TestFramework\Db\DymanicTables\CategoryProductIndexTables;

/**
* Class to pre-create dynamic tables
*/
class DynamicTables
{
/**
* @var CategoryProductIndexTables
*/
private $categoryProductIndexTables;

/**
* @param CategoryProductIndexTables $categoryProductIndexTables
*/
public function __construct(
CategoryProductIndexTables $categoryProductIndexTables
) {
$this->categoryProductIndexTables = $categoryProductIndexTables;
}

/**
* Create dynamic tables before the test to preserve integration tests isolation
*/
public function createTables()
{
$this->categoryProductIndexTables->createTables();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/
namespace Magento\TestFramework\TestCase;

use Magento\Framework\Authorization;
use Magento\TestFramework\ObjectManager;

/**
* A parent class for backend controllers - contains directives for admin user creation and authentication.
*
Expand Down Expand Up @@ -63,7 +66,7 @@ protected function setUp(): void
* If it will be created on test bootstrap we will have invalid RoleLocator object.
* As tests by default are run not from adminhtml area...
*/
\Magento\TestFramework\ObjectManager::getInstance()->removeSharedInstance(\Magento\Framework\Authorization::class);
ObjectManager::getInstance()->removeSharedInstance(Authorization::class);
$this->_auth = $this->_objectManager->get(\Magento\Backend\Model\Auth::class);
$this->_session = $this->_auth->getAuthStorage();
$credentials = $this->_getAdminCredentials();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ public function testAlreadyExistsExceptionProcessingWhenGroupCodeIsDuplicated():
*/
public function testRemoveAttributeFromAttributeSet(): void
{
$this->markTestSkipped('ECP-739');
$message = 'Attempt to load value of nonexistent EAV attribute';
$this->removeSyslog();
$attributeSet = $this->getAttributeSetByName('new_attribute_set');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$appDir = dirname(\Magento\TestFramework\Helper\Bootstrap::getInstance()->getAppTempDir());
// phpcs:ignore Magento2.Security.InsecureFunction
exec("php -f {$appDir}/bin/magento indexer:reindex");
12 changes: 8 additions & 4 deletions dev/tests/integration/testsuite/Magento/Sales/_files/quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

\Magento\TestFramework\Helper\Bootstrap::getInstance()->loadArea('frontend');

$storeManager = Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Store\Model\StoreManagerInterface::class);
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId('simple')
->setId(1)
Expand All @@ -23,7 +27,9 @@
'is_in_stock' => 1,
'manage_stock' => 1,
]
)->save();
)
->setWebsiteIds([$storeManager->getStore()->getWebsiteId()])
->save();

$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
Expand All @@ -39,9 +45,7 @@
$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');

$store = Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get(\Magento\Store\Model\StoreManagerInterface::class)
->getStore();
$store = $storeManager->getStore();

/** @var \Magento\Quote\Model\Quote $quote */
$quote = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Quote\Model\Quote::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
$indexer = Bootstrap::getObjectManager()->create(\Magento\Indexer\Model\Indexer::class);
$indexer->load('catalog_product_price');
$indexer->reindexList([$product->getId()]);

Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ class SetupApplication extends Application
protected $canInstallSequence = false;

/**
* {@inheritdoc}
* @inheritdoc
*/
public function run()
{
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception("Can't start application.");
}

/**
* Create dynamic tables
*
* @return null
*/
protected function createDynamicTables()
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/
namespace Magento\TestFramework\Dependency;

/**
* Class to get DB dependencies information
*/
class DbRule implements \Magento\TestFramework\Dependency\RuleInterface
{
/**
Expand Down Expand Up @@ -37,7 +40,7 @@ public function __construct(array $tables)
*/
public function getDependencyInfo($currentModule, $fileType, $file, &$contents)
{
if ('php' != $fileType || !preg_match('#.*/(Setup|Resource)/.*\.php$#', $file)) {
if ('php' != $fileType || !preg_match('#.*/(Setup|Resource|Query)/.*\.php$#', $file)) {
return [];
}

Expand Down
29 changes: 25 additions & 4 deletions dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,19 @@ public function testCodeStyle()
touch($reportFile);
}
$codeSniffer = new CodeSniffer('Magento', $reportFile, new Wrapper());
$result = $codeSniffer->run(
$this->isFullScan() ? $this->getFullWhitelist() : self::getWhitelist(['php', 'phtml'])
);
$fileList = $this->isFullScan() ? $this->getFullWhitelist() : self::getWhitelist(['php', 'phtml']);
$ignoreList = Files::init()->readLists(__DIR__ . '/_files/phpcs/ignorelist/*.txt');
if ($ignoreList) {
$ignoreListPattern = sprintf('#(%s)#i', implode('|', $ignoreList));
$fileList = array_filter(
$fileList,
function ($path) use ($ignoreListPattern) {
return !preg_match($ignoreListPattern, $path);
}
);
}

$result = $codeSniffer->run($fileList);
$report = file_get_contents($reportFile);
$this->assertEquals(
0,
Expand All @@ -348,8 +358,19 @@ public function testCodeMess()
if (!$codeMessDetector->canRun()) {
$this->markTestSkipped('PHP Mess Detector is not available.');
}
$fileList = self::getWhitelist(['php']);
$ignoreList = Files::init()->readLists(__DIR__ . '/_files/phpmd/ignorelist/*.txt');
if ($ignoreList) {
$ignoreListPattern = sprintf('#(%s)#i', implode('|', $ignoreList));
$fileList = array_filter(
$fileList,
function ($path) use ($ignoreListPattern) {
return !preg_match($ignoreListPattern, $path);
}
);
}

$result = $codeMessDetector->run(self::getWhitelist(['php']));
$result = $codeMessDetector->run($fileList);

$output = "";
if (file_exists($reportFile)) {
Expand Down

0 comments on commit 7a812cd

Please sign in to comment.