Skip to content

Commit 54aedfd

Browse files
authored
ENGCOM-3132: 12696 Delete all test modules after integration tests magento#18459
2 parents 3e3cb84 + 42fc7d3 commit 54aedfd

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

dev/tests/integration/framework/bootstrap.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
*/
66
use Magento\Framework\Autoload\AutoloaderRegistry;
77

8+
// phpcs:ignore Magento2.Security.IncludeFile
89
require_once __DIR__ . '/../../../../app/bootstrap.php';
10+
// phpcs:ignore Magento2.Security.IncludeFile
911
require_once __DIR__ . '/autoload.php';
1012

1113
$testsBaseDir = dirname(__DIR__);
@@ -19,15 +21,16 @@
1921
define('INTEGRATION_TESTS_DIR', $testsBaseDir);
2022
}
2123

22-
$testFrameworkDir = __DIR__;
23-
require_once 'deployTestModules.php';
24-
2524
try {
2625
setCustomErrorHandler();
2726

2827
/* Bootstrap the application */
2928
$settings = new \Magento\TestFramework\Bootstrap\Settings($testsBaseDir, get_defined_constants());
3029

30+
$testFrameworkDir = __DIR__;
31+
// phpcs:ignore Magento2.Security.IncludeFile
32+
require_once 'deployTestModules.php';
33+
3134
if ($settings->get('TESTS_EXTRA_VERBOSE_LOG')) {
3235
$filesystem = new \Magento\Framework\Filesystem\Driver\File();
3336
$exceptionHandler = new \Magento\Framework\Logger\Handler\Exception($filesystem);
@@ -51,7 +54,7 @@
5154
if (!file_exists($globalConfigFile)) {
5255
$globalConfigFile .= '.dist';
5356
}
54-
$sandboxUniqueId = md5(sha1_file($installConfigFile));
57+
$sandboxUniqueId = hash('sha256', sha1_file($installConfigFile));
5558
$installDir = TESTS_TEMP_DIR . "/sandbox-{$settings->get('TESTS_PARALLEL_THREAD', 0)}-{$sandboxUniqueId}";
5659
$application = new \Magento\TestFramework\Application(
5760
$shell,
@@ -99,7 +102,9 @@
99102
/* Unset declared global variables to release the PHPUnit from maintaining their values between tests */
100103
unset($testsBaseDir, $logWriter, $settings, $shell, $application, $bootstrap);
101104
} catch (\Exception $e) {
105+
// phpcs:ignore Magento2.Security.LanguageConstruct.DirectOutput
102106
echo $e . PHP_EOL;
107+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
103108
exit(1);
104109
}
105110

dev/tests/integration/framework/deployTestModules.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
/**
8-
* @var $testFrameworkDir string - Must be defined in parent script.
8+
* @var string $testFrameworkDir - Must be defined in parent script.
9+
* @var \Magento\TestFramework\Bootstrap\Settings $settings - Must be defined in parent script.
910
*/
1011

1112
/** Copy test modules to app/code/Magento to make them visible for Magento instance */
@@ -36,5 +37,35 @@
3637
throw new \RuntimeException('glob() returned error while searching in \'' . $pathPattern . '\'');
3738
}
3839
foreach ($files as $file) {
40+
// phpcs:ignore Magento2.Security.IncludeFile
3941
include $file;
4042
}
43+
44+
if ((int)$settings->get('TESTS_PARALLEL_RUN') !== 1) {
45+
// Only delete modules if we are not using parallel executions
46+
register_shutdown_function(
47+
'deleteTestModules',
48+
$pathToCommittedTestModules,
49+
$pathToInstalledMagentoInstanceModules
50+
);
51+
}
52+
53+
/**
54+
* Delete all test module directories which have been created before
55+
*
56+
* @param string $pathToCommittedTestModules
57+
* @param string $pathToInstalledMagentoInstanceModules
58+
*/
59+
function deleteTestModules($pathToCommittedTestModules, $pathToInstalledMagentoInstanceModules)
60+
{
61+
$filesystem = new \Symfony\Component\Filesystem\Filesystem();
62+
$iterator = new DirectoryIterator($pathToCommittedTestModules);
63+
/** @var SplFileInfo $file */
64+
foreach ($iterator as $file) {
65+
if ($file->isDir() && !in_array($file->getFilename(), ['.', '..'])) {
66+
$targetDirPath = $pathToInstalledMagentoInstanceModules . '/' . $file->getFilename();
67+
$filesystem->remove($targetDirPath);
68+
}
69+
}
70+
unset($iterator, $file);
71+
}

dev/tests/integration/phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<!--<const name="MONGODB_DATABASE_NAME" value="magento_integration_tests"/>-->
7575
<!-- Connection parameters for RabbitMQ tests -->
7676
<!--<const name="RABBITMQ_MANAGEMENT_PORT" value="15672"/>-->
77+
<!--<const name="TESTS_PARALLEL_RUN" value="1"/>-->
7778
</php>
7879
<!-- Test listeners -->
7980
<listeners>

0 commit comments

Comments
 (0)