Panther Documentation
End-to-End tests for pieceofcake2/cakephp applications with Symfony Panther, Chrome and PHPUnit 9.6, set up the way Symfony applications run them.
What it is
Panther is Symfony's library for End-to-End tests: its PantherTestCase starts the application with PHP's built-in web server and drives it with a real Chrome (or Firefox) through the WebDriver protocol. This package is the same thing for a CakePHP 2 application:
| Panther | This package |
|---|---|
Symfony\Component\Panther\PantherTestCase | PieceOfCake2\Panther\TestSuite\PantherTestCase, a CakeTestCase that uses Panther's PantherTestCaseTrait |
Symfony\Component\Panther\ServerExtension | PieceOfCake2\Panther\ServerExtension, the same extension for PantherTestCase |
The assertions of WebTestAssertionsTrait | PieceOfCake2\Panther\TestSuite\WebTestAssertionsTrait, the same assertions without the Symfony FrameworkBundle |
PANTHER_WEB_SERVER_DIR defaults to public/ | defaults to webroot/ (or app/webroot/) |
PANTHER_WEB_SERVER_ROUTER defaults to none | defaults to the CakePHP router script |
| The web server runs PHP in the document root | runs it in the working directory of the tests, so relative paths are the same |
APP_ENV=test of phpunit.xml.dist makes the tests and the web server load .env.test | the same, with config/.env.test of pieceofcake2/app; its tests run with APP_ENV=test by default |
Everything else is Panther's own: the Client (request(), clickLink(), submitForm(), waitFor(), takeScreenshot() ...), createPantherClient() and its options, and the PANTHER_* environment variables. The Symfony documentation applies as it is.
End-to-End tests are slower than the tests of controllers with ControllerTestCase or IntegrationTestTrait: use them for what needs a browser, such as JavaScript, the layout, and flows across several pages.
Requirements
- PHP 8.0+ (Panther 2.1 on PHP 8.0, Panther 2.4 on PHP 8.1+)
- pieceofcake2/cakephp 2.12+
- PHPUnit 9.6
- Google Chrome or Chromium, and a chromedriver of the same major version
Installation
composer require --dev pieceofcake2/panther dbrekelmans/bdi
vendor/bin/bdi detect driversvendor/bin/bdi detect drivers downloads the chromedriver that matches your Chrome to drivers/. Panther looks for chromedriver in the PATH, then in drivers/ and vendor/bin/, so a chromedriver of your package manager (brew install chromedriver, apt-get install chromium-chromedriver) works as well. Add /drivers/ to .gitignore.
Quick Start
Register the extension in
phpunit.xml.dist(Configuration):xml<extensions> <extension class="PieceOfCake2\Panther\ServerExtension"/> </extensions>Set
DATABASE_URLto the test database inconfig/.env.test, which the tests and the web server load withAPP_ENV=test, the default of the tests (Test Database).Write tests that extend
PieceOfCake2\Panther\TestSuite\PantherTestCaseintests/TestCase/EndToEnd/(Writing Tests).Run them:
bashvendor/bin/phpunit # the App suite only (defaultTestSuite) vendor/bin/phpunit --testsuite EndToEnd # the End-to-End tests vendor/bin/phpunit --testsuite App,EndToEnd # everythingDelete
defaultTestSuite="App"to makevendor/bin/phpunitrun everything, as in a Symfony application.
pieceofcake2/app already has this configuration.
Origin
This package was created by pieceofcake2, which also maintains it. It is not a fork of another project and is not based on one. It builds on Symfony Panther as a Composer dependency, and it replaces pieceofcake2/e2e-test.
License
The MIT License. See LICENSE.
