When you run tests, they run in series so it can be time consuming. In this example, we are going to run PHPUnit tests in parallel. You can easily change the command to run Behat tests in parallel as well. Just read the documentation.


Preliminary information


If your tests depends on the data stored in database or checking emails then there may be random failures. It's up to your coding skills to prevent such failures.


Installation


Run composer require liuggio/fastest --dev to install Fastest package.


Test


Series


$ vendor/bin/phpunit
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.
............................................................. 61 / 4011 ( 1%)
............................................................. 122 / 4011 ( 3%)
............................................................. 183 / 4011 ( 4%)
............................................................. 7930 / 8011 ( 98%)
............................................................. 7991 / 8011 ( 99%)
.................... 8011 / 8011 (100%)

Time: 9.87 seconds, Memory: 24.00MB

OK (8011 tests, 22023 assertions)

Parallel


By default, 2 parallel processes are run. If you want more speed with 4 parallel processes, you can add -p ${TESTS_PROCESSES:-4} right at the end of the command.


$ vendor/liuggio/fastest/fastest -x "phpunit.xml.dist" "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};" -vv
- 3 shuffled test classes into the queue.
- Will be consumed by 2 parallel Processes.
1 1/3 ✔ 287 ms /var/www/html/symfony/common/tests/CustomerBundle/Controller/CustomerControllerTest.php
2 2/3 ✔ 2 s 516 ms /var/www/html/symfony/common/tests/CustomerBundle/Service/CustomerServiceTest.php
1 3/3 ✔ 3 s 871 ms /var/www/html/symfony/common/tests/CustomerBundle/Command/CustomerCommandTest.php


✔ You are great!
Time: 4 seconds 419 milliseconds, Memory: 16.00 MiB

If you want different outputs, you can use one of the commands below.


find tests/ -name "*Test.php" | ./vendor/liuggio/fastest/fastest "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};"

find tests/ -name "*Test.php" | ./vendor/liuggio/fastest/fastest "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};" -v

find tests/ -name "*Test.php" | ./vendor/liuggio/fastest/fastest "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};" -vv

vendor/liuggio/fastest/fastest -x "phpunit.xml.dist" "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};"

vendor/liuggio/fastest/fastest -x "phpunit.xml.dist" "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};" -v

vendor/liuggio/fastest/fastest -x "phpunit.xml.dist" "vendor/phpunit/phpunit/phpunit -c phpunit.xml.dist {};" -vv