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; } } } 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();