diff --git a/dev/tests/integration/framework/bootstrap.php b/dev/tests/integration/framework/bootstrap.php index 1cae393dc01c3..59fb1535d1884 100644 --- a/dev/tests/integration/framework/bootstrap.php +++ b/dev/tests/integration/framework/bootstrap.php @@ -5,9 +5,15 @@ */ use Magento\Framework\Autoload\AutoloaderRegistry; +/** + * phpcs:disable PSR1.Files.SideEffects + * phpcs:disable Squiz.Functions.GlobalFunction + * phpcs:disable Magento2.Security.IncludeFile + */ require_once __DIR__ . '/../../../../app/bootstrap.php'; require_once __DIR__ . '/autoload.php'; +// phpcs:ignore Magento2.Functions.DiscouragedFunction $testsBaseDir = dirname(__DIR__); $fixtureBaseDir = $testsBaseDir. '/testsuite'; @@ -19,15 +25,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); @@ -44,14 +50,16 @@ } $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'; } - $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 +107,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 4c894d80f9800..34e1aa9b4e23f 100644 --- a/dev/tests/integration/framework/deployTestModules.php +++ b/dev/tests/integration/framework/deployTestModules.php @@ -5,7 +5,10 @@ */ /** - * @var $testFrameworkDir string - Must be defined in parent script. + * 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. */ /** Copy test modules to app/code/Magento to make them visible for Magento instance */ @@ -20,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); } } @@ -31,10 +38,42 @@ // 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 . '\''); } foreach ($files as $file) { + // phpcs:ignore Magento2.Security.IncludeFile include $file; } + +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, + $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); +} 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 @@ +