Docker pulls GitHub issues GitHub stars GitHub license
This is a complete test suite for running (Unit, Functional, Feature, Browser) tests on your Laravel based system.
It uses Laravel Dusk for browser tests via a Docker executor runner in GitLab.
With this package, you don't need to worry, about Chrome or chromedriver compatibility. This is done automatically, to make your Browser Testing with Laravel Dusk, as easy, as possible.
Laravel dusk? Find more in Laravel Dusk Docs 12.x | 11.x | 10.x | 9.x | 8.x | 7.x | 6.x | 5.8
Gitlab? Find more on gitlab
Gitlab Continous Integration CI ? Find more on gitlab-runner
You may be wondering why deprecated versions are still available. The main reason is to allow for browser testing of your older Laravel applications while you're transitioning to newer versions.
This plug-and-play package is designed for your CI testing environment in GitLab.
All you need to do is to select the appropriate version of your PHP interpreter (based on your Laravel version), and you should be ready to go.
Current state of supported versions of Laravel and PHP is presented below.
| LARAVEL VERSION | COMPATIBLE | PHP VERSIONS |
|---|---|---|
| 12.x | YES | |
| 11.x | YES | |
| 10.x | YES | |
| 9.x | YES | |
| 8.x | YES | |
| 7.x | YES | |
| 6.x | YES | |
| 5.8 | YES | |
| 5.7 | YES | |
| 5.6 | YES | |
| 5.5 | YES | |
| 5.4 | Reported working | |
| 5.3 and below | Not tested |
You should be up and running in seconds. However, please carefully read the following notes.
For now DuskTestCase.php needs to be modified in all cases. THIS package is not going to work without -no-sandbox directive in this file.. You should also disable starting of # static::startChromeDriver();, to have more control of which chromedriver will run. Please read more about it, under Usage...
In case of any issues, please read the current documentation thoroughly, check existing issues (including closed ones) and finally, report a new issue on GitHub.
If this package proves to be useful to you, please star it on Docker Hub or GitHub to increase its visibility to other users.
-
2025年03月15日 -
stabletag refersphp-8.3from now on -
2025年03月15日 -
latesttag refersphp-8.4from now on -
2025年03月15日 -
start-system-chromedriver,start-project-chromedriver,stop-chromedrivercommands introduced -
2025年03月14日 - new images built on ubuntu 24.04 noble. If you experience any problems you can use legacy images with tag
php-x.y-legacywhere x is the php x.y version you need. -
2025年02月25日 -
php-8.4tag introduced -
2023年12月30日 -
stabletag refersphp-8.2from now on -
2023年12月30日 -
latesttag refersphp-8.3from now on -
2023年12月20日 -
php-8.3tag released with latest versions of chrome and chromedriver -
2023年04月29日 -
latesttag refersphp-8.2from now on -
2022年12月16日 -
php-8.2tag added with thanks to @pepijnolivier -
2022年12月16日 - Latest chromedriver compatibility updated up to v.109
-
2022年09月01日 -
latesttag refersphp-8.1from now on -
2022年09月01日 - Latest chromedriver compatibility updated up to v.105 with thanks to @Velzeboer
-
2022年04月16日 - Laravel 9 compatibility confirmed
-
2022年04月16日 -
php-8.1tag added -
2022年04月16日 - Latest chromedriver compatibility updated up to v.101
-
2021年11月03日 - Latest chromedriver compatibility updated up to v.96
-
2021年11月03日 -
stabletag refersphp-7.4from now on -
2021年10月28日 -
latesttag refersphp-8.0from now on andstabletag refers tophp-7.2 -
2021年10月28日 - php imagick extension added to all images except deprecated
php-7.1 -
2021年10月12日 - Latest chromedriver compatibility updated up to v.95
-
2021年01月29日 - Latest chromedriver compatibility updated up to v.89
-
2020年12月03日 - PHP 8.0 version released in
php-8.0tag + latest chromedriver compatibility updated -
2020年10月23日 - PHP 8.0 RC in
php-8.rctag tested with Laravel 8 -
2020年10月20日 - Latest chromedriver compatibility updated up to v.87
-
2020年09月15日 - Laravel 8 compatibility confirmed in php-7.3, php-7.4 and latest tags
-
2020年08月17日 - Latest chromedriver compatibility updated v.85
-
2020年05月15日 - latest PHP versions, Laravel 7 compatibility confirmed
-
2020年02月17日 - Node updated to 12.x LTS
-
2019年12月12日 - Latest for now refers to PHP 7.4
-
2019年12月12日 - PHP 7.4 in
php-7.4tag -
2019年12月12日 - Latest chromedriver compatibility updated v.78 & v.79
-
2019年09月27日 - Latest chromedriver compatibility updated v.77
-
2019年09月24日 - chilio/laravel-dusk-ci:old-stable is deprecated for now. Use it only with old Laravel versions (before 5.5)
-
2019年05月06日 - Latest chromedriver compatibility updated v.75
-
2019年04月04日 - Latest chromedriver compatibility updated v.74
-
2018年12月20日 - PHP 7.3 in
php-7.3tag -
2018年10月24日 - Update to ubuntu:bionic (18.04), Install php-geos and link default
phpcommand tophp7.2in latest tag -
2018年10月09日 - Updated to nodejs v8
-
2018年10月06日 - Latest chromedriver compatibility updated
-
2018年07月24日 - mysql 8.0 and mysql:latest are now supported, but you need to make some modifications to your
.gitlab-ci.yml. Unfortunately for now you cannot simply run mysql in services, as it was before.Simple workaround, is to change in services: (everywhere you call mysql service) to:
services:
- name: mysql:latest
command: ["--default-authentication-plugin=mysql_native_password"]
You need to make sure your Laravel config/database.php has these modes array also:
'mysql' => [
...
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
- 2018年05月14日 - chilio/laravel-dusk-ci:stable ships now with php 7.2 and chrome versions check enabled
- 2018年05月14日 - chilio/laravel-dusk-ci:stable moved to chilio/laravel-dusk-ci:old-stable. If you encounter any problems use the old one, or post issues...
- 2018年05月08日 - Automatic Chrome and chromedriver versions check and fix - works only in chilio/laravel-dusk-ci:latest for now, if you experience errors with this please use chilio/laravel-dusk-ci:stable or chilio/laravel-dusk-ci:php-7.2
- 2018年02月16日 - New command introduced - versions - works only in chilio/laravel-dusk-ci:latest for now
- 2018年02月15日 - chilio/laravel-dusk-ci:latest - tested with Laravel 5.6 and dusk 3.0
- 2017年12月20日 - chilio/laravel-dusk-ci:latest uses php 7.2 from now on, as it is marked as working without issues
- 2017年12月01日 - php 7.2 support added, latest tag refers still to php 7.1 for now, so if you want to use 7.2, please choose exact docker tag : chilio/laravel-dusk-ci:php-7.2
- 2017年09月10日 - initial release, with php 7.1 for laravel 5.5
| Libs included |
|---|
| PHP |
| Xdebug |
| NGINX |
| Chromedriver |
| Chrome |
| NODEJS |
| NPM |
| YARN |
| BOWER |
| PHPUNIT |
| NODE-SASS |
| GULP |
To see exact versions of installed packages, please run versions command in your script declaration in .gitlab-ci.yml, as in examples.
configure-laravel - sets up file permissions, generates laravel key, migrates and seeds db, checks and enforces chromedriver compatibility
start-nginx-ci-project - configures and starts nginx with php-fpm
start-project-chromedriver - starts project embedded chromedriver on port 9515
start-system-chromedriver - starts system embedded chromedriver on port 9515
stop-chromedriver - stops running chromedriver
versions - shows versions of included packages and enabled php modules.
This build is tested with mysql, but also works with other docker db engines
To successfully run mysql add to your test routine:
services:
mysql:5.7 #or specify any downwards version of mysql. mysql:latest will not work out of the box, therefore please check changelog
And in your .env or your .env candidate file to use, mark mysql as the corresponding resource (DB_HOST=mysql)
If you receive errors like
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
probably you have other mysql instance running in your host system with that name. In this case you may need to provide db-alias for your test. More info here
Make sure your DuskTestCase class in /tests/DuskTestCase.php matches all attributes, like drive options, host url, and port, like in this example DuskTestCase.php # there are some modifications which you need to apply (especially --no-sandbox in $options for driver)!, these changes should not affect your local dev environment, otherwise there might be something else wrong with your project.
In your .gitlab-ci.yml use this image like:
image: chilio/laravel-dusk-ci:latest# you can experiment with other images, which might address your needs.
add script lines:
- cp .env.example .env # remember to have APP_URL=http://localhost and DB_HOST=mysql
- configure-laravel # preparations to run project
- start-nginx-ci-project # Here we start webserver, so this is important before running dusk
Finally you can run all your tests served by nginx | php-fpm via:
- php artisan dusk
Laravel Dusk ships with included chromedriver for linux, mac and windows. The examples here allow you to run dusk tests with these included chromedrivers (for linux in this case).
As of 2018年05月08日 this package automatically fixes eventual problems with chrome or chromedriver. Therefore following changes to your app should not be necessary.
However, if you encounter problems, especially errors, with incorrect chromedriver version on your local machine, or this docker image, you can use, this package inbuilt own chromedriver. This option brings, a little bit more compatibility to your project, since Chrome is updated much more often, then chromedriver. In order to do that, you need to make only 2 script modifications:
- In DuskTestCase.php comment out starting chromedriver like
// static::startChromeDriver();. In that case, to make your local development working, before issuingphp artisan duskcommand, you need to install proper chromedriver version manually, and make sure your chromedriver version matches Chrome, running on your local machine. You need to make sure chromedriver is started/running also. Due to different systems and configurations, that's beyond the scope of this documentation. Just to make clear here, in this case you are responsible for updating your own chromedriver with your current installation of Chrome. Since Chrome updates are pretty often, that's the suggested way to go, to keep your local dev running, while other packages are a little behind... - After running
configure-laravelChromedriver should be started already. If you want to use other version, in .gitlab-ci.yml add- stop-chromedriverand one of (- start-project-chromedriveror- start-system-chromedriver) before running- php artisan dusk. This will give you more control of which Chromedriver will be processing your Dusk tests.
- cp phpunit.xml.ci phpunit.xml # In case ,you don't want to interfere, with your local test environment, you can apply this approach for ci tests. Make sure, to create phpunit.xml.ci, in your project and phpunit.dusk.xml. You can specify, 2 separate files for your tests, one for phpunit and one for dusk, you can use examples, from this repo or modify them to suite your needs...
- composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts
- bower install --quiet
- npm run dev or if you are on yarn registry - yarn run dev
- ./vendor/phpunit/phpunit/phpunit -v --coverage-text --colors --stderr# to run phpunit with version specified in your project
DuskTestCase.php # with all modifications to successfully run php artisan dusk tests
DuskTestCase.php # (OLD for Laravel 6 and below) with all modifications to successfully run php artisan dusk tests
phpunit.dusk.xml # If exists in project root, this file will be automatically injected when dusk is run, in case, you want to define any custom variables for your tests like DBs, Caches etc.
phpunit.xml.ci # in case, you want to customize phpunit tests in CI , remember to copy this to phpunit.xml by adding - cp phpunit.xml.ci phpunit.xml to your gitlab-ci.yml.
gitlab-ci.yml # with stages, cache, and artifacts, assuming you are using scripts like "dev" in package.json.
- Please check contents of DuskTestCase.php , you should have it updated accordingly.
- If you get errors, about wrong chromedriver version, or errors about Laravel dusk not able to connect on port 9515, please consider stopping chromedriver via
stop-chromedriverand starting proper version of your choosing ('system' or 'project'). Check Note on using chromedriver versions - If your Laravel chromedriver version is not recognized properly you can issue
- php artisan dusk:install - Try different tag versions compatible with your project.
- You can always try older legacy version like for example chilio/laravel-dusk-ci:php-8.2-legacy instead of a current version chilio/laravel-dusk-ci:php-8.2
- In your dusk tests remember to use ->waitFor() extensively, to make sure, your pages are rendered properly, before test fails. Usually, CI test environments are much slower, than production or your local dev, cause they need to build caches from scratch.
- By default, all dusk browser tests are run with a resolution 1920x720 and color depth 24 (bits), if you need to change that, add/modify SCREEN_RESOLUTION in your .gitlab-ci.yml in
variables:section, like for exampleSCREEN_RESOLUTION: 1280x720x24 - If you experience /bootstrap/autoload.php errors, make sure your appropriate phpunit configs are updated, especially in line
bootstrap="vendor/autoload.php" - If you get warning about mysql
Service runner probably didn't start properlyor other strange behaviours make sure to remove all cache and artifacts routines. Depending on your workflow, they might introduce problems to your tests. You should also check, if your gitlab-runner is working in a privileged mode.
Images mentioned above are intended for testing purposes in CI environments only.
Production usage is not recommended.