Skip to content

Commit

Permalink
DuskServer Improvements (#89)
Browse files Browse the repository at this point in the history
* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Oct 27, 2023
1 parent 1aa3b4d commit 34afe54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 1 addition & 3 deletions src/Concerns/CanServeSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
16 changes: 8 additions & 8 deletions src/DuskServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class DuskServer
protected $port;

/**
* Laravel public working path.
* Laravel working path.
*
* @var string|null
*/
protected $laravelPublicPath;
protected $laravelPath;

/**
* Construct a new server.
Expand All @@ -65,12 +65,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;
}

/**
Expand Down Expand Up @@ -167,7 +167,7 @@ protected function startServer(): void
$this->prepareCommand(), null, $environmentVariables
);

$this->process->setWorkingDirectory($this->laravelPublicPath());
$this->process->setWorkingDirectory("{$this->laravelPath()}/public");
$this->process->start();
}

Expand Down Expand Up @@ -220,9 +220,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');
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/DuskServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ 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()
);
}

/** @test */
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()
);
}

Expand Down

0 comments on commit 34afe54

Please sign in to comment.