pieceofcake2 / e2e-test
Browser end-to-end tests for CakePHP 2 applications with Symfony Panther and PHPUnit
Requires
- php: >=8.0
- ext-dom: *
- phpunit/phpunit: ^9.6
- pieceofcake2/cakephp: ^2.12
- symfony/panther: ^2.1.1
Requires (Dev)
- cakephp/cakephp-codesniffer: ^5.0
- phpstan/phpstan: ^2.1
- pieceofcake2/phpstan-cakephp2: ^0.2.3
Suggests
- dbrekelmans/bdi: Downloads a chromedriver that matches the installed Chrome (vendor/bin/bdi detect drivers)
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-14 22:52:47 UTC
README
Browser end-to-end tests for pieceofcake2/cakephp applications, with Symfony Panther, headless Chrome and PHPUnit 9.6.
The tests start your application with PHP's built-in web server and drive it with a real browser,
so they cover JavaScript, cookies, sessions, SecurityComponent tokens, redirects and the layout on
desktop and mobile. $fixtures work as in any CakeTestCase.
<?php use Pieceofcake2\E2ETest\TestSuite\E2ETestCase; class ContactFormTest extends E2ETestCase { /** * @var array<string> */ public $fixtures = ['app.contact']; /** * @return void */ public function testSend(): void { $this->visit('/contacts/add'); $this->fillField('Your name', 'Jane Doe'); $this->fillField('Email address', 'jane@example.com'); $this->checkLabel('I agree to the terms'); $this->pressButton('Send'); $this->assertCurrentPath('/contacts/thanks'); $this->assertSeeText('Thank you for your message.'); $this->assertNoHorizontalOverflow($this->mobile()); } }
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 matching chromedriver
Installation
composer require --dev pieceofcake2/e2e-test
composer require --dev dbrekelmans/bdi && vendor/bin/bdi detect drivers
It is a library (PSR-4, Pieceofcake2\E2ETest\), not a CakePHP plugin: there is nothing to load with CakePlugin::load().
Quick start
- Copy docs/examples/phpunit.e2e.xml.dist to your project root and
docs/examples/bootstrap.php to
tests/E2E/bootstrap.php - Write tests in
tests/E2E/that extendPieceofcake2\E2ETest\TestSuite\E2ETestCase - Run them:
vendor/bin/phpunit -c phpunit.e2e.xml.dist
When a test fails, a screenshot, the HTML and the server logs are saved to tmp/e2e-artifacts/.
CI
A GitHub Actions job: PHP, Chrome for Testing with the matching chromedriver, the E2E tests with a JUnit report, the failure screenshots, HTML and logs uploaded as an artifact, and a job summary that links to it.
jobs: e2e: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: persist-credentials: false - uses: shivammathur/setup-php@v2 with: php-version: '8.4' coverage: none - name: Install Composer packages run: composer install --no-interaction --no-progress - name: Setup Chrome id: setup-chrome uses: browser-actions/setup-chrome@v2 with: chrome-version: stable install-chromedriver: true - name: Run E2E tests env: PANTHER_CHROME_BINARY: ${{ steps.setup-chrome.outputs.chrome-path }} PANTHER_CHROME_DRIVER_BINARY: ${{ steps.setup-chrome.outputs.chromedriver-path }} PANTHER_NO_SANDBOX: 1 run: vendor/bin/phpunit -c phpunit.e2e.xml.dist --log-junit e2e-junit.xml - name: Upload E2E artifacts if: ${{ failure() }} uses: actions/upload-artifact@v7 with: name: e2e-artifacts path: tmp/e2e-artifacts/ retention-days: 7 if-no-files-found: ignore - name: E2E summary if: ${{ !cancelled() }} uses: pieceofcake2/.github/actions/ci-summary@v1 with: type: junit title: E2E file: e2e-junit.xml artifact-name: e2e-artifacts artifact-note: Screenshots, page HTML and server logs of the failed tests are in the {artifact} artifact.
The documentation has a complete workflow with a MySQL test database.
Documentation
Documentation: https://pieceofcake2.github.io/e2e-test/
It covers the setup of modern and legacy application layouts, the test database, writing tests, the full API, CI with GitHub Actions and troubleshooting.
Reporting Issues
Please open an issue on GitHub. To report a security vulnerability, use private vulnerability reporting.
Contributing
See the contribution guidelines.
License
The MIT License. See LICENSE.