From 1e50a9ed1df8a69bdb8cf949b9c1e197302535a9 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 11 Feb 2022 11:42:08 -0800 Subject: [PATCH 1/2] Failing test: duplicate installer paths --- tests/Drupal8FinderTest.php | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/Drupal8FinderTest.php b/tests/Drupal8FinderTest.php index 2d00e44..f77d717 100644 --- a/tests/Drupal8FinderTest.php +++ b/tests/Drupal8FinderTest.php @@ -86,6 +86,33 @@ protected function getDrupalComposerStructure() return $fileStructure; } + protected function getDrupalComposerStructureWithDuplicateInstallerPaths() + { + $fileStructure = [ + 'web' => static::$fileStructure, + 'composer.json' => [ + 'require' => [ + 'drupal/core' => '*', + ], + 'extra' => [ + 'installer-paths' => [ + 'web/core' => [ + 'type:drupal-core', + ], + 'core' => [ + 'type:drupal-core', + ], + ], + ], + ], + 'vendor' => [], + ]; + unset($fileStructure['web']['composer.json']); + unset($fileStructure['web']['vendor']); + + return $fileStructure; + } + public function testDrupalDefaultStructure() { $finder = new DrupalFinder(); @@ -271,6 +298,27 @@ public function testDrupalComposerStructureWithRealFilesystem() $this->assertSame($root . '/vendor', $finder->getVendorDir()); } + public function testDrupalComposerStructureWithDuplicateInstallerPaths() + { + $finder = new DrupalFinder(); + $root = $this->tempdir(sys_get_temp_dir()); + $this->dumpToFileSystem($this->getDrupalComposerStructureWithDuplicateInstallerPaths(), $root); + + $this->assertTrue($finder->locateRoot($root)); + $this->assertSame($root . '/web', $finder->getDrupalRoot()); + $this->assertSame($root, $finder->getComposerRoot()); + $this->assertSame($root . '/vendor', $finder->getVendorDir()); + + // Test symlink implementation + $symlink = $this->tempdir(sys_get_temp_dir()); + $this->symlink($root, $symlink . '/foo'); + + $this->assertTrue($finder->locateRoot($symlink . '/foo')); + $this->assertSame($root . '/web', $finder->getDrupalRoot()); + $this->assertSame($root, $finder->getComposerRoot()); + $this->assertSame($root . '/vendor', $finder->getVendorDir()); + } + public function testDrupalWithLinkedModule() { $finder = new DrupalFinder(); From c67641c694d044e833d56dc2565bd966e82dab0d Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Fri, 11 Feb 2022 11:49:35 -0800 Subject: [PATCH 2/2] Use first instance of "drupal-core" found in installer-paths. --- src/DrupalFinder.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DrupalFinder.php b/src/DrupalFinder.php index ffbcecd..9b69b7c 100644 --- a/src/DrupalFinder.php +++ b/src/DrupalFinder.php @@ -218,6 +218,7 @@ protected function findAndValidateRoots($path) } $this->drupalRoot = rtrim($path . '/' . $install_path, '/'); $this->vendorDir = $this->composerRoot . '/vendor'; + break; } } }