diff --git a/src/Concerns/CanServeSite.php b/src/Concerns/CanServeSite.php index 1fe04d7f..93e4d720 100644 --- a/src/Concerns/CanServeSite.php +++ b/src/Concerns/CanServeSite.php @@ -36,10 +36,8 @@ public static function serve($host = '127.0.0.1', $port = 8001): void return; } - $basePath = static::applicationBasePath(); - $server = new DuskServer($host, $port); - $server->setPublicPath("{$basePath}/public"); + $server->setLaravelPath(static::applicationBasePath()); $server->stash(['class' => static::class]); $server->start(); diff --git a/src/DuskServer.php b/src/DuskServer.php index 14c7eb29..77a7ffea 100644 --- a/src/DuskServer.php +++ b/src/DuskServer.php @@ -45,11 +45,11 @@ class DuskServer protected $port; /** - * Laravel public working path. + * Laravel working path. * * @var string|null */ - protected $laravelPublicPath; + protected $laravelPath; /** * Construct a new server. @@ -66,12 +66,12 @@ public function __construct($host = '127.0.0.1', $port = 8001) /** * Set Laravel working path. * - * @param string|null $publicPath + * @param string|null $laravelPath * @return void */ - public function setPublicPath(?string $publicPath = null): void + public function setLaravelPath(?string $laravelPath = null): void { - $this->laravelPublicPath = $publicPath; + $this->laravelPath = $laravelPath; } /** @@ -159,7 +159,7 @@ protected function startServer(): void $this->prepareCommand(), null, defined_environment_variables() ); - $this->process->setWorkingDirectory($this->laravelPublicPath()); + $this->process->setWorkingDirectory("{$this->laravelPath()}/public"); $this->process->start(); } @@ -211,9 +211,9 @@ protected function prepareCommand(): string * * @return string */ - public function laravelPublicPath(): string + public function laravelPath(): string { - return $this->laravelPublicPath ?: (string) realpath(__DIR__.'/../laravel/public'); + return $this->laravelPath ?: (string) realpath(__DIR__.'/../laravel'); } /** diff --git a/tests/Unit/DuskServerTest.php b/tests/Unit/DuskServerTest.php index 11297f90..f2e7e0ac 100644 --- a/tests/Unit/DuskServerTest.php +++ b/tests/Unit/DuskServerTest.php @@ -11,8 +11,8 @@ class DuskServerTest extends TestCase public function it_provides_the_laravel_public_directory() { $this->assertEquals( - realpath(__DIR__.'/../../laravel/public'), - (new DuskServer())->laravelPublicPath() + realpath(__DIR__.'/../../laravel'), + (new DuskServer())->laravelPath() ); } @@ -20,11 +20,11 @@ public function it_provides_the_laravel_public_directory() public function it_provides_the_laravel_public_directory_from_custom_location() { $server = new DuskServer(); - $server->setPublicPath('/dir/project/laravel/public'); + $server->setLaravelPath('/dir/project/laravel'); $this->assertEquals( - '/dir/project/laravel/public', - $server->laravelPublicPath() + '/dir/project/laravel', + $server->laravelPath() ); }