From a3d3fe211c440f22527c27f4615c6f7df0e7fd83 Mon Sep 17 00:00:00 2001 From: Leonid Poluianov Date: Fri, 12 Jun 2020 14:18:50 -0500 Subject: [PATCH] [17] Merge api-proto with develop #71 --- .../Magento/Webapi/JoinDirectivesTest.php | 3 ++ .../Magento/TestFramework/Application.php | 24 ++++++++- .../CategoryProductIndexTables.php | 53 +++++++++++++++++++ .../TestFramework/Db/DynamicTables.php | 38 +++++++++++++ .../TestCase/AbstractBackendController.php | 5 +- .../Adminhtml/Product/Set/SaveTest.php | 1 + .../Magento/Indexer/_files/reindex.php | 9 ++++ .../testsuite/Magento/Sales/_files/quote.php | 12 +++-- .../Magento/Wishlist/_files/wishlist.php | 1 - .../TestFramework/SetupApplication.php | 13 ++++- .../TestFramework/Dependency/DbRule.php | 5 +- .../Magento/Test/Php/LiveCodeTest.php | 29 ++++++++-- 12 files changed, 180 insertions(+), 13 deletions(-) create mode 100644 dev/tests/integration/framework/Magento/TestFramework/Db/DymanicTables/CategoryProductIndexTables.php create mode 100644 dev/tests/integration/framework/Magento/TestFramework/Db/DynamicTables.php create mode 100644 dev/tests/integration/testsuite/Magento/Indexer/_files/reindex.php diff --git a/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php b/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php index 4d89e3a0b582a..5e278e6058dc9 100644 --- a/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Webapi/JoinDirectivesTest.php @@ -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() { @@ -87,6 +88,7 @@ public function testGetList() /** * @magentoApiDataFixture Magento/Sales/_files/invoice.php + * @magentoAppIsolation enabled */ public function testAutoGeneratedGetList() { @@ -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() { diff --git a/dev/tests/integration/framework/Magento/TestFramework/Application.php b/dev/tests/integration/framework/Magento/TestFramework/Application.php index f0ce2e24545eb..8d0514215622a 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/Application.php +++ b/dev/tests/integration/framework/Magento/TestFramework/Application.php @@ -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; @@ -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; @@ -293,6 +296,7 @@ public function getInitParams() */ public function isInstalled() { + // phpcs:ignore Magento2.Functions.DiscouragedFunction return is_file($this->getLocalConfig()); } @@ -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 * @@ -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); } } @@ -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); } @@ -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)); } diff --git a/dev/tests/integration/framework/Magento/TestFramework/Db/DymanicTables/CategoryProductIndexTables.php b/dev/tests/integration/framework/Magento/TestFramework/Db/DymanicTables/CategoryProductIndexTables.php new file mode 100644 index 0000000000000..b60a71a00e8e2 --- /dev/null +++ b/dev/tests/integration/framework/Magento/TestFramework/Db/DymanicTables/CategoryProductIndexTables.php @@ -0,0 +1,53 @@ +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 + ) + ); + } + } +} diff --git a/dev/tests/integration/framework/Magento/TestFramework/Db/DynamicTables.php b/dev/tests/integration/framework/Magento/TestFramework/Db/DynamicTables.php new file mode 100644 index 0000000000000..1c31506450585 --- /dev/null +++ b/dev/tests/integration/framework/Magento/TestFramework/Db/DynamicTables.php @@ -0,0 +1,38 @@ +categoryProductIndexTables = $categoryProductIndexTables; + } + + /** + * Create dynamic tables before the test to preserve integration tests isolation + */ + public function createTables() + { + $this->categoryProductIndexTables->createTables(); + } +} diff --git a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php index e93e07d768fdf..4cd3034f88029 100644 --- a/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php +++ b/dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractBackendController.php @@ -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. * @@ -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(); diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php index cdbc9bc90362f..c31266f06225e 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Set/SaveTest.php @@ -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'); diff --git a/dev/tests/integration/testsuite/Magento/Indexer/_files/reindex.php b/dev/tests/integration/testsuite/Magento/Indexer/_files/reindex.php new file mode 100644 index 0000000000000..a618bec3b77ed --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Indexer/_files/reindex.php @@ -0,0 +1,9 @@ +getAppTempDir()); +// phpcs:ignore Magento2.Security.InsecureFunction +exec("php -f {$appDir}/bin/magento indexer:reindex"); diff --git a/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php b/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php index 5be2fcefbde26..ea39a8bf78b4e 100644 --- a/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php +++ b/dev/tests/integration/testsuite/Magento/Sales/_files/quote.php @@ -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) @@ -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); @@ -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); diff --git a/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist.php b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist.php index 3cd71fe36ffe3..e7284f3d650be 100644 --- a/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist.php +++ b/dev/tests/integration/testsuite/Magento/Wishlist/_files/wishlist.php @@ -38,4 +38,3 @@ $indexer = Bootstrap::getObjectManager()->create(\Magento\Indexer\Model\Indexer::class); $indexer->load('catalog_product_price'); $indexer->reindexList([$product->getId()]); - diff --git a/dev/tests/setup-integration/framework/Magento/TestFramework/SetupApplication.php b/dev/tests/setup-integration/framework/Magento/TestFramework/SetupApplication.php index 719979c83db39..69005ec82433b 100644 --- a/dev/tests/setup-integration/framework/Magento/TestFramework/SetupApplication.php +++ b/dev/tests/setup-integration/framework/Magento/TestFramework/SetupApplication.php @@ -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; + } } diff --git a/dev/tests/static/framework/Magento/TestFramework/Dependency/DbRule.php b/dev/tests/static/framework/Magento/TestFramework/Dependency/DbRule.php index cb3a9e2cc9c35..b0d3d861a4cf7 100644 --- a/dev/tests/static/framework/Magento/TestFramework/Dependency/DbRule.php +++ b/dev/tests/static/framework/Magento/TestFramework/Dependency/DbRule.php @@ -7,6 +7,9 @@ */ namespace Magento\TestFramework\Dependency; +/** + * Class to get DB dependencies information + */ class DbRule implements \Magento\TestFramework\Dependency\RuleInterface { /** @@ -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 []; } diff --git a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php index ffc991572addf..324753b4bd4ec 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php +++ b/dev/tests/static/testsuite/Magento/Test/Php/LiveCodeTest.php @@ -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, @@ -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)) {