-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dusk env file not working with artisan serve #162
Comments
Make sure that you do not cache the configuration, i.e. run |
I like the thought of having dusk serving the application automatically instead of having to do this manually. Perhaps something to be done at DuskTestCase? |
@deleugpn you mean that you do not wan't to run
The only situation where it might actually be useful to have a webserver booted up by Dusk itself is if that will make mocks usable in Dusk test cases. But that is not possible so far. See also the discussion in #152. |
Yes, that's exactly what I mean. I work on centos. Since Google Chromw doesn't support Red Hat, I installed a Ubuntu server headless just to run the tests. My activities in this machine is:
Since my centos runs on another VM, I thought to be over complicated to have Ubuntu connecting there for the sake of dusk. Serve would be enough. Given this idea, today I'm going to try and have DuskTestCase turn on the server for me. |
@deleugpn instead of having Create a class in <?php
namespace App\Console\Commands;
use Laravel\Dusk\Console\DuskCommand as BaseCommand;
use Symfony\Component\Process\ProcessBuilder;
class DuskCommand extends BaseCommand
{
public function handle()
{
$webserver = (new ProcessBuilder())
->setTimeout(null)
->add('exec')
->add(PHP_BINARY)
->add('artisan')
->add('serve')
->getProcess();
$webserver->start();
return tap(parent::handle(), function () use ($webserver) {
$webserver->stop();
});
}
} And then, in if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class);
$this->commands(\App\Console\Commands\DuskCommand::class);
} |
Here's another option. I've added a <?php
namespace Tests;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
trait RunsWebServer
{
/**
* @var Process
*/
protected static $webServerProcess;
/**
* Start the web server process
*/
public static function startWebServer()
{
static::$webServerProcess = static::buildServerProcess();
static::$webServerProcess->start();
static::afterClass(function() {
static::stopWebServer();
});
}
/**
* Stop the web server process
*/
public static function stopWebServer()
{
if (static::$webServerProcess) {
static::$webServerProcess->stop();
}
}
/**
* Build the process to run the web server
*
* @return \Symfony\Component\Process\Process
* @throws \Symfony\Component\Process\Exception\InvalidArgumentException
* @throws \Symfony\Component\Process\Exception\LogicException
*/
protected static function buildServerProcess()
{
$host = env('TEST_SERVER_HOST', '127.0.0.1');
$port = env('TEST_SERVER_PORT', 8080);
return (new ProcessBuilder())
->setTimeout(null)
->setWorkingDirectory(realpath(__DIR__.'/../'))
->add('exec')
->add(PHP_BINARY)
->add('-S')
->add("$host:$port")
->add('server.php')
->getProcess();
}
} That trait can be added to any test that needs a web server running, or to the base |
@inxilpro Did you check if the environments match with that approach? The reason I ask is because when I tried running I wrote about it here: https://medium.com/@deleugpn/running-serve-automatically-prior-to-laravel-dusk-9eedf295bbd6 |
I just have an |
Fantastic! That's helped hugely with me getting Jenkins to start the server before running Dusk tests :-) However, I did need to add the following to make the docroot serve from /public correctly:
|
Maybe related, I fixed an issue similar to #531 with these steps:
Sample snippets: // config/database.php
// ...
'dusk' => [
'driver' => 'sqlite',
'database' => database_path('dusk.sqlite'),
'prefix' => '',
],
// ...
|
Heya everyone. Try to see if @alchermd's solution can help you. |
Quick update as this was the top Google result when I was getting started with Dusk + local webserver... The comment by @alchermd is correct, but as a bit of streamlining, the Dusk automatically looks for a So, first starting the web server with |
@alchermd Thanks, it worked well for me @jasonmccreary I needed to use |
I am using Laravel 6 Dusk in ubuntu valet server, but dusk is using default laravel .env instead of .env.dusk.local. Fed up. |
When running php artisan serve and then in another terminal php artisan dusk, the env file isn't loaded properly.
I think Dusk should launch php artisan serve after copying the Dusk specific .env file, and then kill the process afterwards.
The text was updated successfully, but these errors were encountered: