Skip to content
Snippets Groups Projects
Commit 3891174c authored by Ted Bowman's avatar Ted Bowman
Browse files

Issue #3322589 by tedbow: Assert 'type' key is set in FixtureUtilityTrait::addPackage

parent 491930a1
No related branches found
No related tags found
1 merge request!600Issue #3322589: Assert minimum keys in FixtureUtilityTrait::addPackage
......@@ -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',
......
......@@ -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);
}
......
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