dave-liddament/test-splitter

Splits up PHPUnit tests so they can be ran in parallel (e.g. on GitHub actions)

Installs: 313 352

Dependents: 0

Suggesters: 0

Security: 0

Stars: 9

Watchers: 2

Forks: 1

Open Issues: 1

Type:project

pkg:composer/dave-liddament/test-splitter

0.2.0 2025-09-19 13:21 UTC

This package is auto-updated.

Last update: 2025-09-19 14:06:30 UTC


README

PHP versions: 8.1|8.2|8.3|8.4 Latest Stable Version License Total Downloads

Continuous Integration Psalm level 1

Have you got a slow running test suite? Are existing test parallelisation tools (e.g. paratest) not suitable as you need separate database instances?

If so, PHPUnit test case splitter might help. It splits tests into batches in a deterministic way. Each batch of tests can run in separate instances (e.g. by using a matrix in GitHub actions).

Usage

Install via Composer:

composer require --dev dave-liddament/test-splitter

This package provides an executable under vendor/bin/tsplit that takes two arguments: batch, and number of batches. It accepts a list of tests piped into stdin and outputs the tests for the specified batch to stdout.

To split the tests into 4 batches and run the first batch you can do:

vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 1 4`

To run the second batch out of 4 you'd use:

vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit 2 4`

GitHub actions

Add this to your GitHub actions:

jobs:
  tests:
  
    strategy:
      fail-fast: false
      matrix: 
        test-batch: [1, 2, 3, 4]

    steps: 
      # Steps to checkout code, setup environment, etc.

      - name: "Tests batch ${{ matrix.test--batch }}"
        run: vendor/bin/phpunit --filter `vendor/bin/phpunit --list-tests | vendor/bin/tsplit ${{ matrix.test-batch }} 4`

This will split the tests over 4 different jobs.

Additional documentation