Skip to content

Commit

Permalink
Merge branch 'develop' into 8.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Aug 23, 2023
2 parents 990abe4 + f2f581e commit c5d1b21
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 22 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG-7.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-dusk`.

## 7.30.1

Released: 2023-08-23

### Fixes

* Fixes usage with `Orchestra\Testbench\Concerns\WithWorkbench`.

## 7.30.0

Released: 2023-08-22

### Added

* Added `Orchestra\Testbench\Dusk\Concerns\InteractsWithWebDriverOptions`.

### Changes

* Update minimum support for Testbench v7.29.1+. ([v7.29.0...v7.29.1](https://github.com/orchestral/testbench/compare/v7.29.0...v7.29.1))
* Utilise `setUpTheTestEnvironmentTraitToBeIgnored()` method.

## 7.29.0

Released: 2023-08-15
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG-8.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-dusk`.

## 8.9.2

Released: 2023-08-23

### Fixes

* Fixes usage with `Orchestra\Testbench\Concerns\WithWorkbench`.

## 8.9.1

Released: 2023-08-22

### Added

* Added `Orchestra\Testbench\Dusk\Concerns\InteractsWithWebDriverOptions`.

### Changes

* Update minimum support for Testbench v8.9.1+. ([v8.9.0...v8.9.1](https://github.com/orchestral/testbench/compare/v8.9.0...v8.9.1))
* Utilise `setUpTheTestEnvironmentTraitToBeIgnored()` method.

## 8.9.0

Released: 2023-08-19
Expand Down
42 changes: 26 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"psr-4": {
"Orchestra\\Testbench\\Dusk\\Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\": "workbench/database/"
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
}
},
"bin": [
Expand All @@ -50,26 +51,35 @@
"phpstan/phpstan": "^1.10.7",
"phpunit/phpunit": "^10.1"
},
"extra": {
"branch-alias": {
"dev-master": "8.0-dev"
}
},
"scripts": {
"post-autoload-dump": "@composer run prepare",
"prepare": [
"@php testbench-dusk package:discover --ansi",
"@php vendor/bin/dusk-updater detect --auto-update",
"@php testbench-dusk package:drop-sqlite-db",
"@php testbench-dusk package:create-sqlite-db"
"post-autoload-dump": [
"@clear",
"@prepare",
"@dusk:install-chromedriver"
],
"clear": "@php testbench-dusk package:purge-skeleton --ansi",
"build": [
"@php vendor/bin/dusk-updater detect --auto-update",
"@php testbench-dusk workbench:build --ansi"
"clear": "@php vendor/bin/testbench package:purge-skeleton --ansi",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"dusk:install-chromedriver": "@php vendor/bin/dusk-updater detect --auto-update --ansi",
"serve": [
"@build",
"@php vendor/bin/testbench serve"
],
"lint": [
"@php vendor/bin/phpstan analyse",
"@php vendor/bin/pint"
"@php vendor/bin/pint",
"@php vendor/bin/phpstan analyse"
],
"test": [
"@composer run build",
"@php vendor/bin/phpunit -c ./ --color"
"test": "@php vendor/bin/phpunit -c ./ --color",
"ci": [
"@prepare",
"@dusk:install-chromedriver",
"@lint",
"@test"
]
},
"config": {
Expand Down
1 change: 1 addition & 0 deletions laravel/config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

'postmark' => [
'transport' => 'postmark',
// 'message_stream_id' => null,
// 'client' => [
// 'timeout' => 5,
// ],
Expand Down
15 changes: 13 additions & 2 deletions src/Concerns/CanServeSite.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Orchestra\Testbench\Dusk\DuskServer;
use Orchestra\Testbench\Dusk\Options;

use function Orchestra\Testbench\after_resolving;

trait CanServeSite
{
/**
Expand Down Expand Up @@ -89,7 +91,13 @@ public function beforeServingApplication(Closure $closure): void
/** @var \Illuminate\Foundation\Application $app */
$app = $this->app;

$closure($app, $app['config']);
after_resolving($app, 'config', static function ($config, $app) use ($closure) {
/**
* @var \Illuminate\Foundation\Application $app
* @var \Illuminate\Contracts\Config\Repository $config
*/
$closure($app, $config);
});

static::$server?->stash([
'class' => static::class,
Expand Down Expand Up @@ -147,7 +155,10 @@ public function getFreshApplicationToServe(DuskServer $server)

if ($serializedClosure) {
$closure = unserialize($serializedClosure)->getClosure();
$closure($app, $app['config']);

after_resolving($app, 'config', static function ($config, $app) use ($closure) {
$closure($app, $config);
});
}

return $app;
Expand Down
16 changes: 16 additions & 0 deletions src/Concerns/InteractsWithWebDriverOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Orchestra\Testbench\Dusk\Concerns;

trait InteractsWithWebDriverOptions
{
/**
* Prepare the testing environment web driver options.
*
* @return void
*/
public static function defineWebDriverOptions()
{
//
}
}
8 changes: 4 additions & 4 deletions src/DuskServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

use function Orchestra\Testbench\package_path;

class DuskServer
{
/**
Expand Down Expand Up @@ -150,10 +152,8 @@ protected function startServer(): void

/** @var array<string, mixed> $environmentVariables */
$environmentVariables = Collection::make($_ENV)
->when(\defined('TESTBENCH_WORKING_PATH'), function ($collect) {
/** @phpstan-ignore-next-line */
return $collect->put('TESTBENCH_WORKING_PATH', TESTBENCH_WORKING_PATH);
})->all();
->put('TESTBENCH_WORKING_PATH', package_path())
->all();

$this->process = Process::fromShellCommandline(
$this->prepareCommand(), null, $environmentVariables
Expand Down
4 changes: 4 additions & 0 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
abstract class TestCase extends Testbench
{
use Concerns\CanServeSite,
Concerns\InteractsWithWebDriverOptions,
Concerns\ProvidesBrowser;

/**
Expand Down Expand Up @@ -102,6 +103,7 @@ protected function setUpTheTestEnvironmentTraitToBeIgnored(string $use): bool
{
return Str::startsWith($use, [
Concerns\CanServeSite::class,
Concerns\InteractsWithWebDriverOptions::class,
Concerns\ProvidesBrowser::class,
\Laravel\Dusk\Concerns\ProvidesBrowser::class,
\Laravel\Dusk\Chrome\SupportsChrome::class,
Expand Down Expand Up @@ -189,6 +191,8 @@ protected function resolveApplication()
*/
protected function driver(): RemoteWebDriver
{
static::defineWebDriverOptions();

if (DuskOptions::shouldUsesWithoutUI()) {
DuskOptions::withoutUI();
} elseif ($this->hasHeadlessDisabled()) {
Expand Down
37 changes: 37 additions & 0 deletions tests/Browser/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

namespace Orchestra\Testbench\Dusk\Tests\Browser;

use Illuminate\Support\Env;
use Laravel\Dusk\Browser;
use Orchestra\Testbench\Dusk\TestCase;

use function Orchestra\Testbench\package_path;

class RouteTest extends TestCase
{
/**
Expand All @@ -26,6 +29,10 @@ protected function defineRoutes($router)
$router->get('environment', ['uses' => function () {
return config('app.env');
}]);

$router->get('testbench-environment-value', ['uses' => function () {
return Env::get('TESTBENCH_WORKING_PATH');
}]);
}

/** @test */
Expand Down Expand Up @@ -74,4 +81,34 @@ public function can_tweak_the_application_within_a_test()

$this->removeApplicationTweaks();
}

/** @test */
public function can_use_multiple_browsers_can_persist_testbench_working_path_environment_variables()
{
$this->browse(function (Browser $browser, Browser $browserTwo) {
$browser->visit('testbench-environment-value')
->assertSee(package_path())
->visit('testbench-environment-value')
->assertSee(package_path());

$browserTwo->visit('testbench-environment-value')
->assertSee(package_path())
->visit('testbench-environment-value')
->assertSee(package_path());
});

static::reloadServing();

$this->browse(function (Browser $browser, Browser $browserTwo) {
$browser->visit('testbench-environment-value')
->assertSee(package_path())
->visit('testbench-environment-value')
->assertSee(package_path());

$browserTwo->visit('testbench-environment-value')
->assertSee(package_path())
->visit('testbench-environment-value')
->assertSee(package_path());
});
}
}

0 comments on commit c5d1b21

Please sign in to comment.