Skip to content
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

[3.x] Laravel Framework 11.x and Laravel Dusk 8.x support #35

Merged
merged 8 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
name: Check PHP code style

on: [push]
on:
push:
branches:
- master
- 1.x
- 2.x
paths-ignore:
- LICENSE.md
- readme.md
pull_request:
paths-ignore:
- LICENSE.md
- readme.md

jobs:
style:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: .php-cs-fixer.cache
uses: actions/cache@v4
with:
path: .php-cs-fixer.cache
key: ${{ runner.OS }}-${{ github.repository }}-php-cs-fixer-${{ github.sha }}
restore-keys: |
${{ runner.OS }}-${{ github.repository }}-php-cs-fixer-

- name: Check style
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.php --dry-run --diff
args: --dry-run --diff
43 changes: 28 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,34 @@ name: tests

on:
push:
branches:
- master
- 1.x
- 2.x
paths-ignore:
- LICENSE.md
- readme.md
pull_request:
paths-ignore:
- LICENSE.md
- readme.md

jobs:
linux_tests:
runs-on: ubuntu-latest

strategy:
matrix:
php: [7.3, 7.4, 8.0, 8.1, 8.2]
php: [8.1, 8.2, 8.3]

name: PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }} on Linux

env:
PHPUNIT_PACKAGE: ${{ matrix.php == '8.1' && 'phpunit/phpunit:^10.1' || 'phpunit/phpunit:^11.0' }}

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -28,26 +41,26 @@ jobs:

- name: Install dependencies
run: |
composer require "phpunit/phpunit:^9.5.10" --dev --no-update
composer require "$PHPUNIT_PACKAGE" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress --ansi

- name: Install Geckodriver
run: vendor/bin/phpunit tests/DownloadBinaries.php

- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
mac_tests:
runs-on: macos-latest

strategy:
matrix:
php: [8.1]
php: [8.3]

name: PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }} on MacOS

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -59,26 +72,26 @@ jobs:

- name: Install dependencies
run: |
composer require "phpunit/phpunit:^9.5.10" --dev --no-update
composer require "phpunit/phpunit:^11.0" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress --ansi

- name: Install Geckodriver
run: vendor/bin/phpunit tests/DownloadBinaries.php

- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
windows_tests:
runs-on: windows-latest

strategy:
matrix:
php: [8.1]
php: [8.3]

name: PHP ${{ matrix.php }}
name: PHP ${{ matrix.php }} on MS Windows

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -90,11 +103,11 @@ jobs:

- name: Install dependencies
run: |
composer require "phpunit/phpunit:^9.5.10" --dev --no-update
composer require "phpunit/phpunit:^10.1" --dev --no-update
composer update --prefer-dist --no-interaction --no-progress --ansi

- name: Install Geckodriver
run: vendor/bin/phpunit tests/DownloadBinaries.php

- name: Execute tests
run: vendor/bin/phpunit --verbose
run: vendor/bin/phpunit
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
bin/geckodriver*
storage
vendor
.php_cs.cache
.php-cs-fixer.cache
composer.lock
coverage
.phpunit.cache
.phpunit.result.cache
phpunit.xml
.idea
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
}
],
"require": {
"php": "^7.2|^8.0",
"guzzlehttp/guzzle": "^6.0|^7.0",
"laravel/dusk": "^6.0|^7.0",
"php-webdriver/webdriver": "^1.11.0"
"php": "^8.1",
"guzzlehttp/guzzle": "^7.5",
"laravel/dusk": "^8.0",
"php-webdriver/webdriver": "^1.15.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"mockery/mockery": "^1.4.4",
"orchestra/testbench": "^6.25|^7.0",
"phpunit/phpunit": "^9.5.10"
"friendsofphp/php-cs-fixer": "^3.64",
"mockery/mockery": "^1.6.12",
"orchestra/testbench": "^8.19|^9.0",
"phpunit/phpunit": "^10.1|^11.0"
},
"autoload": {
"psr-4": {
Expand All @@ -43,6 +43,7 @@
},
"scripts": {
"download": "vendor/bin/phpunit tests/DownloadBinaries.php",
"lint": "./vendor/bin/php-cs-fixer fix -vvv --dry-run --show-progress=dots --diff",
"test": "vendor/bin/phpunit"
},
"extra": {
Expand Down
24 changes: 10 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
backupGlobals="false"
backupStaticProperties="false"
beStrictAboutTestsThatDoNotTestAnything="false"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
failOnRisky="true"
failOnWarning="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
verbose="true"
>
<testsuites>
<testsuite name="Laravel Dusk for Firefox Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
29 changes: 26 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ This package will make [Laravel Dusk](https://github.com/laravel/dusk/) browser
<a name="requirements"></a>
## Requirements

* PHP 7.2+
* Laravel Framework 6.0+
* Laravel Dusk 6.0+
* PHP 8.1+
* Laravel Framework 10.0+
* Laravel Dusk 8.0+
* PHPUnit 10+
* Latest version of Mozilla Firefox installed locally

<a name="installation"></a>
Expand Down Expand Up @@ -285,6 +286,28 @@ or call PHPUnit directly:
```

Xdebug may be awaiting a user interaction to continue from a code breakpoint. PHP extension Xdebug should be disabled in php.ini for running browser tests.
7. Why is every test case failing with this error message?

> Expected browser binary location, but unable to find binary in default locatio
n, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on
the command line

Mozilla Firefox v130.0.1 introduced a bug on MS Windows that configured the binary path using the incorrect registry keys. See https://github.com/mozilla/geckodriver/issues/2199 for more details. If a similar error happens again in the future, try one of the below options.

1. Reinstall the latest Mozilla Firefox.
2. Add the Mozilla Firefox executable directory to your operating system's environment variable `$PATH`.
3. Update tests/DuskTestCase.php method `driver()` to define the absolute binary path:

```php
$capabilities = DesiredCapabilities::firefox();

$capabilities->getCapability(FirefoxOptions::CAPABILITY)
// ...
->setOption('binary', 'c:\Program Files (x86)\Mozilla Firefox\firefox.exe');
```
8. Does this package support Pest as a Laravel Dusk test runner?

No, currently this only supports PHPUnit. Contributors can submit a pull request for Pest support that will need to update DuskTestCase.php stub installation and the `SupportsFirefox` trait.

<a name="contributing"></a>
## Contributing
Expand Down
22 changes: 0 additions & 22 deletions src/Concerns/TogglesHeadlessMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,4 @@ protected function filterHeadlessArguments(array $args = [])
]);
})->values()->all();
}

/**
* Determine whether the Dusk command has disabled headless mode.
*
* @return bool
*/
protected function hasHeadlessDisabled()
{
return isset($_SERVER['DUSK_HEADLESS_DISABLED']) ||
isset($_ENV['DUSK_HEADLESS_DISABLED']);
}

/**
* Determine if the browser window should start maximized.
*
* @return bool
*/
protected function shouldStartMaximized()
{
return isset($_SERVER['DUSK_START_MAXIMIZED']) ||
isset($_ENV['DUSK_START_MAXIMIZED']);
}
}
2 changes: 2 additions & 0 deletions src/Console/ChromeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
use Derekmd\Dusk\DuskFile;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'dusk:chrome')]
class ChromeCommand extends Command
{
/**
Expand Down
2 changes: 2 additions & 0 deletions src/Console/FirefoxDriverCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
use Derekmd\Dusk\OperatingSystem;
use Illuminate\Console\Command;
use RuntimeException;
use Symfony\Component\Console\Attribute\AsCommand;

/**
* @copyright Proxy downloads are based on https://github.com/staudenmeir/dusk-updater
* by Jonas Staudenmeir.
*/
#[AsCommand(name: 'dusk:firefox-driver')]
class FirefoxDriverCommand extends Command
{
use DownloadsBinaries;
Expand Down
11 changes: 11 additions & 0 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace Derekmd\Dusk\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'dusk:install-firefox')]
class InstallCommand extends Command
{
/**
Expand Down Expand Up @@ -55,6 +57,15 @@ public function handle()
return 1;
}

// Laravel 11+ apps may not define a CreatesApplication trait.
if (! trait_exists(\Tests\CreatesApplication::class)) {
file_put_contents($stubDestination, str_replace(
'use CreatesApplication, ',
'use ',
file_get_contents($stubDestination),
));
}

$this->info('Firefox scaffolding installed successfully.');

$this->comment('Downloading Geckodriver binaries...');
Expand Down
5 changes: 2 additions & 3 deletions src/Firefox/SupportsFirefox.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Derekmd\Dusk\Firefox;

use Laravel\Dusk\Browser;
use PHPUnit\Framework\Attributes\After;

trait SupportsFirefox
{
Expand All @@ -27,9 +28,7 @@ trait SupportsFirefox
*/
protected static $firefoxLog;

/**
* @after
*/
#[After]
public function tearDownFirefoxConsoleOutput()
{
if (static::$firefoxLog) {
Expand Down
3 changes: 2 additions & 1 deletion stubs/DuskTestCase.stub
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use Facebook\WebDriver\Firefox\FirefoxOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;
use PHPUnit\Framework\Attributes\BeforeClass;

abstract class DuskTestCase extends BaseTestCase
{
Expand All @@ -17,9 +18,9 @@ abstract class DuskTestCase extends BaseTestCase
/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
#[BeforeClass]
public static function prepare()
{
if (static::runningFirefoxInSail()) {
Expand Down
Loading