Skip to content

Commit

Permalink
Merge branch '7.x' into develop
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Sep 22, 2023
2 parents c6564a4 + c505fde commit 12635e6
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 73 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"laravel/dusk": "^7.11",
"laravel/serializable-closure": "^1.0",
"orchestra/dusk-updater": "^2.3",
"orchestra/testbench": ">=8.11.0 <8.12.0",
"orchestra/testbench": "^8.12",
"php-webdriver/webdriver": "^1.9"
},
"require-dev": {
Expand Down Expand Up @@ -74,7 +74,11 @@
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse"
],
"test": "@php vendor/bin/phpunit -c ./ --color",
"test": [
"@php drop-sqlite-db",
"@php create-sqlite-db",
"@php vendor/bin/phpunit -c ./ --color"
],
"ci": [
"@prepare",
"@dusk:install-chromedriver",
Expand Down
43 changes: 0 additions & 43 deletions laravel/resources/views/errors/503.blade.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Concerns/CanServeSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class_exists(SerializableClosureFactory::class)
: new SerializableClosure($closure)
),
]);

$this->beforeApplicationDestroyed(function () {
$this->removeApplicationTweaks();
});
}

/**
Expand Down Expand Up @@ -183,6 +187,9 @@ public function getServer()
*/
protected function setUpDuskServer(): void
{
static::cachedUsesForTestCase();
static::cachedConfigurationForWorkbench();

if (! $this->app) {
$this->refreshApplication();
}
Expand Down
10 changes: 7 additions & 3 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ protected function setUpTheTestEnvironmentTraitToBeIgnored(string $use): bool
*/
protected function getApplicationProviders($app)
{
return array_merge(parent::getApplicationProviders($app), [
DuskServiceProvider::class,
]);
$providers = parent::getApplicationProviders($app);

if (! \in_array(DuskServiceProvider::class, $providers)) {
array_push($providers, DuskServiceProvider::class);
}

return $providers;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
providers:
- Workbench\App\Providers\RouteServiceProvider

migrations:
- workbench/database/migrations

workbench:
start: '/'
welcome: true
build:
- drop-sqlite-db
- create-sqlite-db
- migrate:refresh
12 changes: 3 additions & 9 deletions tests/Browser/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@

namespace Orchestra\Testbench\Dusk\Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Orchestra\Testbench\Concerns\WithLaravelMigrations;
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;

/** @test */
public function can_authenticate_user()
Expand Down
16 changes: 4 additions & 12 deletions tests/Browser/DatabaseMigrationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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 () {
Expand All @@ -18,16 +20,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()
{
Expand Down
14 changes: 10 additions & 4 deletions tests/Browser/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,19 @@ public function can_use_multiple_browsers()
{
$this->browse(function (Browser $browser, Browser $browserTwo) {
$browser->visit('hello')
->assertSee('hello world');
->assertSee('hello world')
->blank();

$browserTwo->visit('hello')
->assertSee('hello world');
->assertSee('hello world')
->blank();
});
}

/** @test */
public function can_tweak_the_application_within_a_test()
{
$this->tweakApplication(function ($app, $config) {
$this->beforeServingApplication(function ($app, $config) {
$config->set('new_config_item', 'Fantastic!');
});

Expand All @@ -78,8 +80,12 @@ public function can_tweak_the_application_within_a_test()
$browser->visit('config')
->assertSee('Fantastic!');
});
}

$this->removeApplicationTweaks();
/** @test */
public function application_tweak_doesnt_persist_between_test()
{
$this->assertNull($this->app['config']->get('new_config_item'));
}

/** @test */
Expand Down
35 changes: 35 additions & 0 deletions tests/Browser/WorkbenchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Orchestra\Testbench\Dusk\Tests\Browser;

use Illuminate\Contracts\Http\Kernel as HttpKernel;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\Dusk\TestCase;
use Orchestra\Workbench\Http\Middleware\CatchDefaultRoute;

class WorkbenchTest extends TestCase
{
use WithWorkbench;

/** @test */
public function it_can_browse_the_default_page()
{
$this->beforeServingApplication(function ($app) {
$app->make(HttpKernel::class)->pushMiddleware(CatchDefaultRoute::class);
});

$this->browse(function ($browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}

/** @test */
public function it_can_browse_the_welcome_page()
{
$this->browse(function ($browser) {
$browser->visit('/welcome')
->assertSee('Laravel');
});
}
}
29 changes: 29 additions & 0 deletions workbench/app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

class RouteServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}

/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
Route::view('welcome', 'welcome');
}
}

0 comments on commit 12635e6

Please sign in to comment.