dave-liddament / test-splitter
Splits up PHPUnit tests so they can be ran in parallel (e.g. on github actions)
Installs: 196 212
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- php-parallel-lint/php-parallel-lint: ^1.3
- phpunit/phpunit: ^9.5
- psalm/plugin-phpunit: ^0.16.1
- vimeo/psalm: ^4.10
README
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. This 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
To use. Install:
composer require --dev dave-liddament/test-splitter
Test splitter (tsplit
) takes two arguments: batch, and number of batches. The list of tests is piped into stdin
.
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 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.