Skip to content

12696 Delete all test modules after integration tests #18459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions dev/tests/integration/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

Expand Down
41 changes: 40 additions & 1 deletion dev/tests/integration/framework/deployTestModules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -20,21 +23,57 @@
$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);
}
}
unset($iterator, $file);

// 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);
}
1 change: 1 addition & 0 deletions dev/tests/integration/phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
<!--<const name="MONGODB_DATABASE_NAME" value="magento_integration_tests"/>-->
<!-- Connection parameters for RabbitMQ tests -->
<!--<const name="RABBITMQ_MANAGEMENT_PORT" value="15672"/>-->
<!--<const name="TESTS_PARALLEL_RUN" value="1"/>-->
</php>
<!-- Test listeners -->
<listeners>
Expand Down