Skip to content

Commit ccfcf94

Browse files
feat(core): add root_path helper (#607)
Co-authored-by: Brent Roose <[email protected]>
1 parent c5fdcad commit ccfcf94

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Tempest/Core/src/functions.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Closure;
88
use Tempest\Core\DeferredTasks;
9+
use Tempest\Core\Kernel;
910

1011
function path(string ...$parts): string
1112
{
@@ -18,6 +19,11 @@ function path(string ...$parts): string
1819
);
1920
}
2021

22+
function root_path(string ...$parts): string
23+
{
24+
return path(realpath(get(Kernel::class)->root), ...$parts);
25+
}
26+
2127
function env(string $key, mixed $default = null): mixed
2228
{
2329
$value = getenv($key);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Tests\Tempest\Integration\Core;
6+
7+
use function Tempest\path;
8+
use function Tempest\root_path;
9+
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
10+
11+
/**
12+
* @internal
13+
*/
14+
final class RootPathHelperTest extends FrameworkIntegrationTestCase
15+
{
16+
public function test_can_get_base_path(): void
17+
{
18+
$this->assertSame(path(realpath($this->root)), root_path());
19+
$this->assertSame(path(realpath($this->root . '/tests/Fixtures')), root_path('/tests/Fixtures'));
20+
}
21+
}

0 commit comments

Comments
 (0)