From 4e44cb93fd18ae2fcd8fbad134c6aa956781425e Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Mon, 8 Oct 2018 13:31:40 +0200 Subject: [PATCH 1/6] 12696 Delete all test modules after integration tests Several test modules are created on the fly during startup of every integration test run, but they have never been deleted. This commit changes this, modules are deleted when the process ends --- .../framework/deployTestModules.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index 4c894d80f9800..fe0d91b81f142 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -38,3 +38,25 @@ foreach ($files as $file) { include $file; } + +register_shutdown_function('deleteTestModules', $pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules); + +/** + * Delete all test module directories which have been created before + * + * @param string $pathToCommittedTestModules + * @param string $pathToInstalledMagentoInstanceModules + */ +function deleteTestModules($pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules) +{ + $filesystem = new \Symfony\Component\Filesystem\Filesystem(); + $iterator = new DirectoryIterator($pathToCommittedTestModules); + /** @var SplFileInfo $file */ + foreach ($iterator as $file) { + if ($file->isDir() && !in_array($file->getFilename(), ['.', '..'])) { + $targetDirPath = $pathToInstalledMagentoInstanceModules . '/' . $file->getFilename(); + $filesystem->remove($targetDirPath); + } + } + unset($iterator, $file); +} \ No newline at end of file From 03667812817331309c81bfebcb643f8ee0d389c4 Mon Sep 17 00:00:00 2001 From: Andreas von Studnitz Date: Mon, 8 Oct 2018 14:57:30 +0200 Subject: [PATCH 2/6] 12696 Don't delete test module files if tests are run in parallel Without this check, the module files were deleted when the first test runner finishs. The second test runner might still need the module files. --- dev/tests/integration/framework/bootstrap.php | 6 +++--- dev/tests/integration/framework/deployTestModules.php | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 1cae393dc01c3..c67049ee8482d 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -19,15 +19,15 @@ define('INTEGRATION_TESTS_DIR', $testsBaseDir); } -$testFrameworkDir = __DIR__; -require_once 'deployTestModules.php'; - try { setCustomErrorHandler(); /* Bootstrap the application */ $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); + $testFrameworkDir = __DIR__; + require_once 'deployTestModules.php'; + if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { $filesystem = new \Magento\Framework\Filesystem\Driver\File(); $exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem); diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index fe0d91b81f142..4d358597395a7 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -5,7 +5,8 @@ */ /** - * @var $testFrameworkDir string - Must be defined in parent script. + * @var string $testFrameworkDir - Must be defined in parent script. + * @var \Magento\TestFramework\Bootstrap\Settings $settings - Must be defined in parent script. */ /** Copy test modules to app/code/Magento to make them visible for Magento instance */ @@ -39,7 +40,10 @@ include $file; } -register_shutdown_function('deleteTestModules', $pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules); +if (!$settings->get('TESTS_PARALLEL_THREAD', 0)) { + // Only delete modules if we are not using parallel executions + register_shutdown_function('deleteTestModules', $pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules); +} /** * Delete all test module directories which have been created before From 140d27b95a5e3517fff8c58cabb93628e97f42f7 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Thu, 11 Oct 2018 11:38:33 +0300 Subject: [PATCH 3/6] Fixed code style issues --- dev/tests/integration/framework/deployTestModules.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index 4d358597395a7..07ff80bd753d2 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -42,7 +42,11 @@ if (!$settings->get('TESTS_PARALLEL_THREAD', 0)) { // Only delete modules if we are not using parallel executions - register_shutdown_function('deleteTestModules', $pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules); + register_shutdown_function( + 'deleteTestModules', + $pathToCommittedTestModules, + $pathToInstalledMagentoInstanceModules + ); } /** @@ -63,4 +67,4 @@ function deleteTestModules($pathToCommittedTestModules, $pathToInstalledMagentoI } } unset($iterator, $file); -} \ No newline at end of file +} From 2ff2c4e5048794635c16c2294ed1684b4023a6fd Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 24 Apr 2019 13:28:45 +0300 Subject: [PATCH 4/6] Fix static tests. --- dev/tests/integration/framework/bootstrap.php | 7 ++++++- dev/tests/integration/framework/deployTestModules.php | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index c67049ee8482d..a29e875d01f69 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -5,7 +5,9 @@ */ use Magento\Framework\Autoload\AutoloaderRegistry; +// phpcs:ignore Magento2.Security.IncludeFile require_once __DIR__ . '/../../../../app/bootstrap.php'; +// phpcs:ignore Magento2.Security.IncludeFile require_once __DIR__ . '/autoload.php'; $testsBaseDir = dirname(__DIR__); @@ -26,6 +28,7 @@ $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); $testFrameworkDir = __DIR__; + // phpcs:ignore Magento2.Security.IncludeFile require_once 'deployTestModules.php'; if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { @@ -51,7 +54,7 @@ if (!file_exists($globalConfigFile)) { $globalConfigFile .= '.dist'; } - $sandboxUniqueId = md5(sha1_file($installConfigFile)); + $sandboxUniqueId = hash('sha256', sha1_file($installConfigFile)); $installDir = TESTS_TEMP_DIR . "/sandbox-{$settings->get('TESTS_PARALLEL_THREAD', 0)}-{$sandboxUniqueId}"; $application = new \Magento\TestFramework\Application( $shell, @@ -99,7 +102,9 @@ /* Unset declared global variables to release the PHPUnit from maintaining their values between tests */ unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap); } catch (\Exception $e) { + // phpcs:ignore Magento2.Security.LanguageConstruct.DirectOutput echo $e . PHP_EOL; + // phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage exit(1); } diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index 07ff80bd753d2..bfe3243f49ee9 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -37,6 +37,7 @@ throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\''); } foreach ($files as $file) { + // phpcs:ignore Magento2.Security.IncludeFile include $file; } From d039298d36c86141b0281e1d947d46a4cc748e30 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Fri, 10 May 2019 10:38:34 +0300 Subject: [PATCH 5/6] Fix integration tests run. squash! Fix integration tests run. --- dev/tests/integration/framework/deployTestModules.php | 2 +- dev/tests/integration/phpunit.xml.dist | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index bfe3243f49ee9..73092ca2166db 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -41,7 +41,7 @@ include $file; } -if (!$settings->get('TESTS_PARALLEL_THREAD', 0)) { +if ((int)$settings->get('TESTS_PARALLEL_RUN') !== 1) { // Only delete modules if we are not using parallel executions register_shutdown_function( 'deleteTestModules', diff --git a/dev/tests/integration/phpunit.xml.dist b/dev/tests/integration/phpunit.xml.dist index 815abde6ac26b..858de7a9873e7 100644 --- a/dev/tests/integration/phpunit.xml.dist +++ b/dev/tests/integration/phpunit.xml.dist @@ -74,6 +74,7 @@ + From efbf1545028330517ea82e710ccef188db8264f9 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 31 May 2019 15:21:35 +0300 Subject: [PATCH 6/6] magento/magento2#18459: Static test fix. --- dev/tests/integration/framework/bootstrap.php | 11 ++++++++--- dev/tests/integration/framework/deployTestModules.php | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index a29e875d01f69..59fb1535d1884 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -5,11 +5,15 @@ */ use Magento\Framework\Autoload\AutoloaderRegistry; -// phpcs:ignore Magento2.Security.IncludeFile +/** + * phpcs:disable PSR1.Files.SideEffects + * phpcs:disable Squiz.Functions.GlobalFunction + * phpcs:disable Magento2.Security.IncludeFile + */ require_once __DIR__ . '/../../../../app/bootstrap.php'; -// phpcs:ignore Magento2.Security.IncludeFile require_once __DIR__ . '/autoload.php'; +// phpcs:ignore Magento2.Functions.DiscouragedFunction $testsBaseDir = dirname(__DIR__); $fixtureBaseDir = $testsBaseDir. '/testsuite'; @@ -28,7 +32,6 @@ $settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants()); $testFrameworkDir = __DIR__; - // phpcs:ignore Magento2.Security.IncludeFile require_once 'deployTestModules.php'; if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) { @@ -47,10 +50,12 @@ } $installConfigFile = $settings->getAsConfigFile('TESTS_INSTALL_CONFIG_FILE'); + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (!file_exists($installConfigFile)) { $installConfigFile .= '.dist'; } $globalConfigFile = $settings->getAsConfigFile('TESTS_GLOBAL_CONFIG_FILE'); + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (!file_exists($globalConfigFile)) { $globalConfigFile .= '.dist'; } diff --git a/dev/tests/integration/framework/deployTestModules.php b/dev/tests/integration/framework/deployTestModules.php index 73092ca2166db..34e1aa9b4e23f 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -5,6 +5,8 @@ */ /** + * phpcs:disable PSR1.Files.SideEffects + * phpcs:disable Squiz.Functions.GlobalFunction * @var string $testFrameworkDir - Must be defined in parent script. * @var \Magento\TestFramework\Bootstrap\Settings $settings - Must be defined in parent script. */ @@ -21,10 +23,14 @@ $source = $file->getPathname(); $relativePath = substr($source, strlen($pathToCommittedTestModules)); $destination = $pathToInstalledMagentoInstanceModules . $relativePath; + // phpcs:ignore Magento2.Functions.DiscouragedFunction $targetDir = dirname($destination); + // phpcs:ignore Magento2.Functions.DiscouragedFunction if (!is_dir($targetDir)) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction mkdir($targetDir, 0755, true); } + // phpcs:ignore Magento2.Functions.DiscouragedFunction copy($source, $destination); } } @@ -32,6 +38,7 @@ // Register the modules under '_files/' $pathPattern = $pathToInstalledMagentoInstanceModules . '/TestModule*/registration.php'; +// phpcs:ignore Magento2.Functions.DiscouragedFunction $files = glob($pathPattern, GLOB_NOSORT); if ($files === false) { throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\''); @@ -43,6 +50,7 @@ if ((int)$settings->get('TESTS_PARALLEL_RUN') !== 1) { // Only delete modules if we are not using parallel executions + // phpcs:ignore Magento2.Functions.DiscouragedFunction register_shutdown_function( 'deleteTestModules', $pathToCommittedTestModules,