From 3891174c8f6306a8364759b991d19ba29195c80b Mon Sep 17 00:00:00 2001 From: tedbow <tedbow@240860.no-reply.drupal.org> Date: Fri, 18 Nov 2022 21:20:20 +0000 Subject: [PATCH] Issue #3322589 by tedbow: Assert 'type' key is set in FixtureUtilityTrait::addPackage --- .../src/Kernel/FixtureUtilityTraitTest.php | 20 ++++++++++++++++++- .../tests/src/Traits/FixtureUtilityTrait.php | 6 ++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/package_manager/tests/src/Kernel/FixtureUtilityTraitTest.php b/package_manager/tests/src/Kernel/FixtureUtilityTraitTest.php index fb078d62e4..6d933c42d6 100644 --- a/package_manager/tests/src/Kernel/FixtureUtilityTraitTest.php +++ b/package_manager/tests/src/Kernel/FixtureUtilityTraitTest.php @@ -33,10 +33,12 @@ class FixtureUtilityTraitTest extends PackageManagerKernelTestBase { $this->addPackage($this->dir, [ 'name' => 'my/package', + 'type' => 'library', ]); $this->addPackage($this->dir, [ 'name' => 'my/dev-package', 'version' => '2.1.0', + 'type' => 'library', 'install_path' => '../relative/path', ], TRUE, @@ -56,9 +58,21 @@ class FixtureUtilityTraitTest extends PackageManagerKernelTestBase { $this->assertSame("Failed asserting that an array has the key 'name'.", $e->getMessage()); } + // Packages cannot be added without a type. + try { + $this->addPackage($this->dir, ['name' => 'unknown']); + $this->fail('Adding an package without a type should raise an error.'); + } + catch (AssertionFailedError $e) { + $this->assertSame("Failed asserting that an array has the key 'type'.", $e->getMessage()); + } + // We should not be able to add an existing package. try { - $this->addPackage($this->dir, ['name' => 'my/package']); + $this->addPackage($this->dir, [ + 'name' => 'my/package', + 'type' => 'library', + ]); $this->fail('Trying to add an existing package should raise an error.'); } catch (AssertionFailedError $e) { @@ -71,6 +85,7 @@ class FixtureUtilityTraitTest extends PackageManagerKernelTestBase { $this->addPackage($this->dir, [ 'name' => 'absolute/path', 'install_path' => '/absolute/path', + 'type' => 'library', ]); $this->fail('Add package should have failed.'); } @@ -81,10 +96,12 @@ class FixtureUtilityTraitTest extends PackageManagerKernelTestBase { $installed_json_expected_packages = [ 'my/package' => [ 'name' => 'my/package', + 'type' => 'library', ], 'my/dev-package' => [ 'name' => 'my/dev-package', 'version' => '2.1.0', + 'type' => 'library', ], ]; $installed_php_expected_packages = $installed_json_expected_packages; @@ -174,6 +191,7 @@ class FixtureUtilityTraitTest extends PackageManagerKernelTestBase { 'my/dev-package' => [ 'name' => 'my/dev-package', 'version' => '3.2.1', + 'type' => 'library', ], 'my/other-package' => [ 'name' => 'my/other-package', diff --git a/package_manager/tests/src/Traits/FixtureUtilityTrait.php b/package_manager/tests/src/Traits/FixtureUtilityTrait.php index 1740dd1e69..5a5517dd93 100644 --- a/package_manager/tests/src/Traits/FixtureUtilityTrait.php +++ b/package_manager/tests/src/Traits/FixtureUtilityTrait.php @@ -92,12 +92,14 @@ trait FixtureUtilityTrait { * area). * @param array $package * The package info that should be added to installed.json and - * installed.php. Must include a `name` key. + * installed.php. Must include the `name` and `type` keys. * @param bool $is_dev_requirement * Whether or not the package is a development requirement. */ protected function addPackage(string $dir, array $package, bool $is_dev_requirement = FALSE): void { - $this->assertArrayHasKey('name', $package); + foreach (['name', 'type'] as $required_key) { + $this->assertArrayHasKey($required_key, $package); + } $this->setPackage($dir, $package['name'], $package, FALSE, $is_dev_requirement); } -- GitLab