Skip to content

Commit 61fb43c

Browse files
committed
fix: root path resolution
1 parent 995caba commit 61fb43c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

packages/drift/src/FrameworkIntegrationTestCase.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ abstract class FrameworkIntegrationTestCase extends IntegrationTest
4040
protected function setUp(): void
4141
{
4242
// We force forward slashes for consistency even on Windows.
43-
$this->root = normalize(realpath(__DIR__ . '/../../../'));
43+
$this->root = normalize(realpath(
44+
dirname($this->findComposerJson(getcwd())) ?? getcwd(),
45+
));
46+
47+
// $this->root = normalize(realpath(__DIR__ . '/../../../'));
4448

4549
// TODO(aidan-casey): Clean this waaaaay up.
4650
if ($consoleFixtures = realpath(__DIR__ . '/../../../tests/Integration/Console/Fixtures')) {
@@ -181,4 +185,24 @@ protected function assertSnippetsMatch(string $expected, string $actual): void
181185

182186
$this->assertSame($expected, $actual);
183187
}
188+
189+
private function findComposerJson(?string $startDir = null): ?string
190+
{
191+
$dir = $startDir ?? getcwd();
192+
193+
while (true) {
194+
$composerPath = $dir . DIRECTORY_SEPARATOR . 'composer.json';
195+
if (file_exists($composerPath)) {
196+
return $composerPath;
197+
}
198+
199+
$parentDir = dirname($dir);
200+
if ($parentDir === $dir) {
201+
// Reached the root directory
202+
return null;
203+
}
204+
205+
$dir = $parentDir;
206+
}
207+
}
184208
}

0 commit comments

Comments
 (0)