diff --git a/package_manager/src/InstalledPackage.php b/package_manager/src/InstalledPackage.php index 17e357fa36254a67d7a4f8331c5b9bd51553069b..f3cff37081d70c956d4d0a20e4019123ab4921c2 100644 --- a/package_manager/src/InstalledPackage.php +++ b/package_manager/src/InstalledPackage.php @@ -98,7 +98,7 @@ final class InstalledPackage { $info = file_get_contents($match[0]); $info = Yaml::decode($info); - if (is_string($info['project']) && !empty($info['project'])) { + if (!empty($info['project'])) { return $info['project']; } } diff --git a/package_manager/tests/src/Kernel/InstalledPackagesListTest.php b/package_manager/tests/src/Kernel/InstalledPackagesListTest.php index a9cdbddab5a942d88c6216e642ff9b3e0a44b40a..6a9fffd534a712a707d3b21233b004799c3931ad 100644 --- a/package_manager/tests/src/Kernel/InstalledPackagesListTest.php +++ b/package_manager/tests/src/Kernel/InstalledPackagesListTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\package_manager\Kernel; +use Drupal\Component\Serialization\Yaml; use Drupal\fixture_manipulator\ActiveFixtureManipulator; use Drupal\package_manager\InstalledPackage; use Drupal\package_manager\InstalledPackagesList; @@ -121,6 +122,25 @@ class InstalledPackagesListTest extends PackageManagerKernelTestBase { $this->assertNull($list->getPackageByDrupalProjectName('custom_module')); $this->assertNull($list->getPackageByDrupalProjectName('custom_theme')); + // The `project` key has been removed from the info file. + (new ActiveFixtureManipulator()) + ->addProjectAtPath('projects/no_project_key') + ->commitChanges(); + $list = new InstalledPackagesList([ + 'drupal/no_project_key' => InstalledPackage::createFromArray([ + 'name' => 'drupal/no_project_key', + 'version' => '1.0.0', + 'type' => 'drupal-module', + 'path' => $projects_path . '/no_project_key', + ]), + ]); + $info_file = $list['drupal/no_project_key']->path . '/no_project_key.info.yml'; + $this->assertFileIsWritable($info_file); + $info = Yaml::decode(file_get_contents($info_file)); + unset($info['project']); + file_put_contents($info_file, Yaml::encode($info)); + $this->assertNull($list->getPackageByDrupalProjectName('no_project_key')); + // The project name is repeated. (new ActiveFixtureManipulator()) ->addProjectAtPath('projects/duplicate_project')