Skip to content
Snippets Groups Projects
Commit 6bf619d5 authored by Kunal Sachdev's avatar Kunal Sachdev Committed by Ted Bowman
Browse files

Issue #3318313 by kunal.sachdev, tedbow: Make OverwriteExistingPackagesValidatorTest fixture-less

parent ec07415b
No related branches found
No related tags found
1 merge request!571Issue #3318313: Make OverwriteExistingPackagesValidatorTest fixture less
Showing
with 50 additions and 107 deletions
{
"_readme": [
"See \\Drupal\\Tests\\package_manager\\Kernel\\OverwriteExistingPackagesValidatorTest::testNewPackagesOverwriteExisting()."
],
"packages": []
}
<?php
/**
* @file
* Simulates that no packages are installed by Composer.
*
* @see \Drupal\Tests\package_manager\Kernel\OverwriteExistingPackagesValidatorTest::testNewPackagesOverwriteExisting()
*/
return [
'versions' => [],
];
{
"_readme": [
"See \\Drupal\\Tests\\package_manager\\Kernel\\OverwriteExistingPackagesValidatorTest::testNewPackagesOverwriteExisting()."
],
"packages": [
{
"name": "drupal/module_1",
"version": "1.3.0",
"type": "drupal-module"
},
{
"name": "drupal/module_2",
"version": "1.3.0",
"type": "drupal-module"
},
{
"name": "drupal/module_3",
"version": "1.3.0",
"type": "drupal-module"
},
{
"name": "drupal/module_4",
"version": "1.3.0",
"type": "drupal-module"
},
{
"name": "drupal/module_5",
"version": "1.3.0",
"type": "drupal-module"
}
]
}
<?php
/**
* @file
* Simulates several modules installed by Composer.
*
* @see \Drupal\Tests\package_manager\Kernel\OverwriteExistingPackagesValidatorTest::testNewPackagesOverwriteExisting()
*/
$modules_dir = __DIR__ . '/../../modules';
return [
'versions' => [
'drupal/module_1' => [
'type' => 'drupal-module',
'install_path' => $modules_dir . '/module_1',
],
'drupal/module_2' => [
'type' => 'drupal-module',
'install_path' => $modules_dir . '/module_2',
],
'drupal/module_3' => [
'type' => 'drupal-module',
'install_path' => $modules_dir . '/module_3',
],
'drupal/module_4' => [
'type' => 'drupal-module',
'install_path' => $modules_dir . '/module_1',
],
'drupal/module_5' => [
'type' => 'drupal-module',
'install_path' => $modules_dir . '/module_5_different_path',
],
],
];
...@@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel; ...@@ -4,6 +4,7 @@ namespace Drupal\Tests\package_manager\Kernel;
use Drupal\package_manager\Exception\StageValidationException; use Drupal\package_manager\Exception\StageValidationException;
use Drupal\package_manager\ValidationResult; use Drupal\package_manager\ValidationResult;
use Drupal\Tests\package_manager\Traits\FixtureUtilityTrait;
/** /**
* @covers \Drupal\package_manager\Validator\OverwriteExistingPackagesValidator * @covers \Drupal\package_manager\Validator\OverwriteExistingPackagesValidator
...@@ -12,6 +13,8 @@ use Drupal\package_manager\ValidationResult; ...@@ -12,6 +13,8 @@ use Drupal\package_manager\ValidationResult;
*/ */
class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBase { class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBase {
use FixtureUtilityTrait;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -27,32 +30,60 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas ...@@ -27,32 +30,60 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas
* *
* The fixture simulates a scenario where the active directory has three * The fixture simulates a scenario where the active directory has three
* modules installed: module_1, module_2, and module_5. None of them are * modules installed: module_1, module_2, and module_5. None of them are
* managed by Composer. * managed by Composer. These modules will be moved into the staging directory
* * by the 'package_manager_bypass' module.
* The staging area has four modules: module_1, module_2, module_3, and
* module_5_different_path. All of them are managed by Composer. We expect the
* following outcomes:
*
* - module_1 and module_2 will raise errors because they would overwrite
* non-Composer managed paths in the active directory.
* - module_3 will cause no problems, since it doesn't exist in the active
* directory at all.
* - module_4, which is defined only in the staged installed.json and
* installed.php, will cause an error because its path collides with
* module_1.
* - module_5_different_path will not cause a problem, even though its package
* name is drupal/module_5, because its project name and path in the staging
* area differ from the active directory.
*/ */
public function testNewPackagesOverwriteExisting(): void { public function testNewPackagesOverwriteExisting(): void {
$fixtures_dir = __DIR__ . '/../../fixtures/overwrite_existing_validation'; $fixtures_dir = __DIR__ . '/../../fixtures/overwrite_existing_validation';
$this->copyFixtureFolderToActiveDirectory("$fixtures_dir/active"); $this->copyFixtureFolderToActiveDirectory("$fixtures_dir/active");
$this->copyFixtureFolderToStageDirectoryOnApply("$fixtures_dir/staged");
$stage = $this->createStage(); $stage = $this->createStage();
$stage->create(); $stage->create();
$stage->require(['drupal/core:9.8.1']); $stage_dir = $stage->getStageDirectory();
// module_1 and module_2 will raise errors because they would overwrite
// non-Composer managed paths in the active directory.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_1',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
]);
$this->addPackage($stage_dir, [
'name' => 'drupal/module_2',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_2',
]);
// module_3 will cause no problems, since it doesn't exist in the active
// directory at all.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_3',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_3',
]);
// module_4 doesn't exist in the active directory but the 'install_path' as
// known to Composer in the staged directory collides with module_1 in the
// active directory which will cause an error.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_4',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_1',
]);
// module_5_different_path will not cause a problem, even though its package
// name is drupal/module_5, because its project name and path in the staging
// area differ from the active directory.
$this->addPackage($stage_dir, [
'name' => 'drupal/module_5',
'version' => '1.3.0',
'type' => 'drupal-module',
'install_path' => '../../modules/module_5_different_path',
]);
$expected_results = [ $expected_results = [
ValidationResult::createError([ ValidationResult::createError([
'The new package drupal/module_1 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.', 'The new package drupal/module_1 will be installed in the directory /vendor/composer/../../modules/module_1, which already exists but is not managed by Composer.',
...@@ -65,6 +96,7 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas ...@@ -65,6 +96,7 @@ class OverwriteExistingPackagesValidatorTest extends PackageManagerKernelTestBas
]), ]),
]; ];
$stage->require(['drupal/core:9.8.1']);
try { try {
$stage->apply(); $stage->apply();
// If no exception occurs, ensure we weren't expecting any errors. // If no exception occurs, ensure we weren't expecting any errors.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment