diff --git a/src/DrupalFinder.php b/src/DrupalFinder.php index 642ea8f..fd6ef86 100644 --- a/src/DrupalFinder.php +++ b/src/DrupalFinder.php @@ -75,6 +75,12 @@ private function shiftPathUp($path) { $parent = dirname($path); + // If $path did not contain any parents, it may be a relative path: + // normalize it to the realpath first. + if ($parent === '.' && ($realpath = realpath($path))) { + $parent = dirname($realpath); + } + return in_array($parent, ['.', $path]) ? false : $parent; } diff --git a/tests/Drupal8FinderTest.php b/tests/Drupal8FinderTest.php index ad84954..c4292d2 100644 --- a/tests/Drupal8FinderTest.php +++ b/tests/Drupal8FinderTest.php @@ -247,6 +247,18 @@ public function testDrupalWithCustomVendor() $this->assertSame($root . '/vendor-foo', realpath($this->finder->getVendorDir())); } + public function testDrupalComposerWithRelativeRoot() + { + $root = $this->tempdir(sys_get_temp_dir()); + $fileStructure = ['drupal' => $this->getDrupalComposerStructure()]; + $this->dumpToFileSystem($fileStructure, $root); + + $cwd = getcwd(); + chdir($root . '/drupal'); + $this->assertTrue($this->finder->locateRoot('web')); + chdir($cwd); + } + /** * @param $fileStructure */