Search by

pieceofcake2 / e2e-test

ttsuru

Browser end-to-end tests for CakePHP 2 applications with Symfony Panther and PHPUnit

Package info

github.com/pieceofcake2/e2e-test

pkg:composer/pieceofcake2/e2e-test

Statistics

Installs: 219

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

v1.1.0 2026-10-14 17:16 UTC

README

GitHub License Packagist Version PHP PHPStan CakePHP CI Codecov

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

  1. Copy docs/examples/phpunit.e2e.xml.dist to your project root and docs/examples/bootstrap.php to tests/E2E/bootstrap.php
  2. Write tests in tests/E2E/ that extend Pieceofcake2\E2ETest\TestSuite\E2ETestCase
  3. 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.