diff --git a/composer.json b/composer.json index 7330e157..264c66df 100644 --- a/composer.json +++ b/composer.json @@ -74,7 +74,10 @@ "@php vendor/bin/pint", "@php vendor/bin/phpstan analyse" ], - "test": "@php vendor/bin/phpunit -c ./ --color", + "test": [ + "@build", + "@php vendor/bin/phpunit -c ./ --color" + ], "ci": [ "@prepare", "@dusk:install-chromedriver", diff --git a/src/Concerns/CanServeSite.php b/src/Concerns/CanServeSite.php index af157016..24adda23 100644 --- a/src/Concerns/CanServeSite.php +++ b/src/Concerns/CanServeSite.php @@ -159,6 +159,8 @@ public function getFreshApplicationToServe(DuskServer $server) after_resolving($app, 'config', static function ($config, $app) use ($closure) { $closure($app, $config); }); + + $app['config']; } return $app; @@ -183,6 +185,10 @@ public function getServer() */ protected function setUpDuskServer(): void { + if (! static::$cachedConfigurationForWorkbench) { + static::setupBeforeClassUsingWorkbench(); + } + if (! $this->app) { $this->refreshApplication(); } diff --git a/testbench.yaml b/testbench.yaml index 98cc6777..38dba707 100644 --- a/testbench.yaml +++ b/testbench.yaml @@ -1,5 +1,12 @@ +providers: + - Workbench\App\Providers\RouteServiceProvider + +migrations: + - workbench/database/migrations + workbench: start: '/' build: - drop-sqlite-db - create-sqlite-db + - migrate:refresh diff --git a/tests/Browser/AuthTest.php b/tests/Browser/AuthTest.php index 7695e516..f34ae603 100644 --- a/tests/Browser/AuthTest.php +++ b/tests/Browser/AuthTest.php @@ -2,21 +2,16 @@ namespace Orchestra\Testbench\Dusk\Tests\Browser; +use Illuminate\Foundation\Testing\DatabaseMigrations; use Laravel\Dusk\Browser; +use Orchestra\Testbench\Concerns\WithLaravelMigrations; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Dusk\TestCase; use Orchestra\Testbench\Factories\UserFactory; class AuthTest extends TestCase { - /** - * Define database migrations. - * - * @return void - */ - protected function defineDatabaseMigrations() - { - $this->loadLaravelMigrations(config('database.default')); - } + use DatabaseMigrations, WithLaravelMigrations, WithWorkbench; /** @test */ public function can_authenticate_user() diff --git a/tests/Browser/DatabaseMigrationsTest.php b/tests/Browser/DatabaseMigrationsTest.php index 586a761a..300cdec1 100644 --- a/tests/Browser/DatabaseMigrationsTest.php +++ b/tests/Browser/DatabaseMigrationsTest.php @@ -2,13 +2,16 @@ namespace Orchestra\Testbench\Dusk\Tests\Browser; +use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Support\Facades\Schema; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Dusk\TestCase; - use function Orchestra\Testbench\workbench_path; class DatabaseMigrationsTest extends TestCase { + use DatabaseMigrations, WithWorkbench; + protected function setUp(): void { $this->beforeApplicationDestroyed(function () { @@ -18,16 +21,6 @@ protected function setUp(): void parent::setUp(); } - /** - * Define database migrations. - * - * @return void - */ - protected function defineDatabaseMigrations() - { - $this->loadMigrationsFrom(workbench_path('database/migrations')); - } - /** @test */ public function it_can_migrate_and_reset_the_database() { diff --git a/tests/Browser/RouteTest.php b/tests/Browser/RouteTest.php index 7598d65a..899dc3e3 100644 --- a/tests/Browser/RouteTest.php +++ b/tests/Browser/RouteTest.php @@ -4,12 +4,14 @@ use Illuminate\Support\Env; use Laravel\Dusk\Browser; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Dusk\TestCase; - use function Orchestra\Testbench\package_path; class RouteTest extends TestCase { + use WithWorkbench; + /** * Define routes setup. * diff --git a/tests/Browser/WithFakerTest.php b/tests/Browser/WithFakerTest.php index d45bf61d..c58c7950 100644 --- a/tests/Browser/WithFakerTest.php +++ b/tests/Browser/WithFakerTest.php @@ -4,11 +4,12 @@ use Faker\Generator; use Illuminate\Foundation\Testing\WithFaker; +use Orchestra\Testbench\Concerns\WithWorkbench; use Orchestra\Testbench\Dusk\TestCase; class WithFakerTest extends TestCase { - use WithFaker; + use WithFaker, WithWorkbench; /** @test */ public function it_can_use_faker() diff --git a/tests/Browser/WorkbenchTest.php b/tests/Browser/WorkbenchTest.php new file mode 100644 index 00000000..4e668ae6 --- /dev/null +++ b/tests/Browser/WorkbenchTest.php @@ -0,0 +1,20 @@ +browse(function ($browser) { + $browser->visit('welcome') + ->assertSee('Documentation'); + }); + } +} diff --git a/workbench/app/.gitkeep b/workbench/app/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/workbench/app/Providers/RouteServiceProvider.php b/workbench/app/Providers/RouteServiceProvider.php new file mode 100644 index 00000000..56b71b48 --- /dev/null +++ b/workbench/app/Providers/RouteServiceProvider.php @@ -0,0 +1,29 @@ +