1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/tests/ci

49 lines
1.7 KiB
Plaintext
Raw Normal View History

2023-01-18 07:43:30 +01:00
#!/usr/bin/env php
<?php
/*
* This script assumes you're in a Laravel project that has access
* to the Str, Collection and Symfony's Process class.
*/
require_once 'vendor/autoload.php';
/**
* Lists PHPunit tests in the following format:
* - Tests\Support\UuidTest::it_can_create_a_uuid_from_a_string
* - Tests\Support\UuidTest::it_can_not_create_a_uuid_from_null
* - ...
*/
2023-01-18 08:15:20 +01:00
$process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--list-tests']);
2023-01-18 07:43:30 +01:00
$process->mustRun();
$tests = \Illuminate\Support\Str::of($process->getOutput())
->explode("\n") // Break the output from new lines into an array
->filter(fn (string $test) => str_contains($test, ' - ')) // Only lines with " - "
->map(fn (string $test) => addslashes(
\Illuminate\Support\Str::of($test)
->replace('- ', '') // Strip the "- "
->trim()
->explode('::') // Only the class, not the method
->get(0)
))
->filter(fn (string $test) => !empty($test)) // Make sure there are no empty lines
->unique() // We only need unique classes
->split((int) getenv('CI_NODE_TOTAL')) // Split it into equally sized chunks
->get((int) getenv('CI_NODE_INDEX')); // Get the index we need for this instance
/**
* Run phpunit with a filter:
* phpunit --filter 'TestClass|AnotherTestClass|...'
*/
2023-01-18 09:02:14 +01:00
$process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--testdox', '--filter', $tests->join('|')], timeout: null);
2023-01-18 07:43:30 +01:00
$process->start();
// Make sure we have live data output
foreach ($process as $type => $data) {
echo $data;
}
$process->wait();
// Exit using PHPUnit's exit code to have the action pass/fail
exit($process->getExitCode());