From ca455b00b44527981225a2ea481b4d9aeb9567a2 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 11:47:20 +0200 Subject: [PATCH 01/15] Chunk tests --- bin/paralell-testing | 49 +++++++++++++++++++++++++++++++++++++++++ composer.json | 7 ++++-- lib/stages/run_tests.sh | 8 +------ 3 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 bin/paralell-testing diff --git a/bin/paralell-testing b/bin/paralell-testing new file mode 100644 index 0000000..d9d3056 --- /dev/null +++ b/bin/paralell-testing @@ -0,0 +1,49 @@ +#!/usr/bin/env php +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|...' + */ +$process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); +$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()); diff --git a/composer.json b/composer.json index 708f2d7..e981f2d 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,15 @@ ], "bin": [ "bin/keep-travis-running", + "bin/paralell-testing", "bin/test-drupal-project" ], "require": { - "php": ">=7.2", + "php": ">=8.1", "drupal/coder": "^8.3", - "symfony/yaml": "^3.4" + "symfony/yaml": "^6.3", + "symfony/process": "^6.3", + "illuminate/support ": "^11.2" }, "config": { "allow-plugins": { diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index 95da93f..cce8cc1 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -12,13 +12,7 @@ _stage_run_tests() { local phpunit="composer exec -- phpunit --debug" if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then - phpunit="composer exec -- paratest -p "${DRUPAL_TESTING_PARALLEL_TESTING_PROCESSES} - if [ "${DRUPAL_TESTING_PARALLEL_TESTING_PER_FUNCTION}" = true ]; then - phpunit=${phpunit}" -f" - fi - if [ "${DRUPAL_TESTING_PARALLEL_TESTING_WRAPPER_RUNNER}" = true ]; then - phpunit=${phpunit}" --runner WrapperRunner" - fi + ./paralell-testing fi if [[ ${DRUPAL_TESTING_TEST_GROUP} ]]; then From 87fd2fd90ab443692b6f08c64e6abd510ff81393 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 11:59:07 +0200 Subject: [PATCH 02/15] Fix composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e981f2d..d96d843 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "drupal/coder": "^8.3", "symfony/yaml": "^6.3", "symfony/process": "^6.3", - "illuminate/support ": "^11.2" + "illuminate/support": "^11.2" }, "config": { "allow-plugins": { From bb934e3bccd91c99f7dc1e2ead40daa851419bc3 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 12:08:58 +0200 Subject: [PATCH 03/15] Make executable --- bin/paralell-testing | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/paralell-testing diff --git a/bin/paralell-testing b/bin/paralell-testing old mode 100644 new mode 100755 From 4d6546a1f4892e9a2b10c543ba9854c2d7b8fb2c Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 12:12:46 +0200 Subject: [PATCH 04/15] Fix --- lib/stages/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index cce8cc1..fc13181 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -12,7 +12,7 @@ _stage_run_tests() { local phpunit="composer exec -- phpunit --debug" if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then - ./paralell-testing + paralell-testing fi if [[ ${DRUPAL_TESTING_TEST_GROUP} ]]; then From d076da02b9629626564f835533d3c38a95fb6f41 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 12:18:16 +0200 Subject: [PATCH 05/15] Fix path --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index d9d3056..2ff0a3c 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -5,7 +5,7 @@ * 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'; +require_once '../vendor/autoload.php'; /** * Lists PHPunit tests in the following format: From 64cbd5d69906d3734cb2df8a71e011c7e0d74010 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 12:22:45 +0200 Subject: [PATCH 06/15] Try --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index 2ff0a3c..a8f3cff 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -5,7 +5,7 @@ * 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'; +require_once '../../../../vendor/autoload.php'; /** * Lists PHPunit tests in the following format: From 1272e12aba2666664abc767b8c5fa441167f6b5f Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 12:33:16 +0200 Subject: [PATCH 07/15] Hm --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index a8f3cff..bc9a388 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -5,7 +5,7 @@ * 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'; +require_once '/home/runner/.composer/vendor/autoload.php'; /** * Lists PHPunit tests in the following format: From 75a60f28732d34093725cc0c246053b41bcd50de Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 13:27:53 +0200 Subject: [PATCH 08/15] Try --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index bc9a388..2542b5b 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -35,7 +35,7 @@ $tests = \Illuminate\Support\Str::of($process->getOutput()) * Run phpunit with a filter: * phpunit --filter 'TestClass|AnotherTestClass|...' */ -$process = new \Symfony\Component\Process\Process(['./vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); +$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_PROJECT_BASEDIR') .'/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); $process->start(); // Make sure we have live data output From 6aa72d683a163f490754f78a4a22db5fa5d2ff31 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 13:35:15 +0200 Subject: [PATCH 09/15] Fix --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index 2542b5b..4928f15 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -35,7 +35,7 @@ $tests = \Illuminate\Support\Str::of($process->getOutput()) * Run phpunit with a filter: * phpunit --filter 'TestClass|AnotherTestClass|...' */ -$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_PROJECT_BASEDIR') .'/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); +$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY') .'/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); $process->start(); // Make sure we have live data output From 0920c9487eb5a8dacf0249826e9dbc63ffb65613 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 13:39:33 +0200 Subject: [PATCH 10/15] Fix --- bin/paralell-testing | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index 4928f15..1e5edcc 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -13,7 +13,7 @@ require_once '/home/runner/.composer/vendor/autoload.php'; * - Tests\Support\UuidTest::it_can_not_create_a_uuid_from_null * - ... */ -$process = new \Symfony\Component\Process\Process([__DIR__ . '/vendor/bin/phpunit', '--list-tests']); +$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY') . '/vendor/bin/phpunit', '--list-tests']); $process->mustRun(); $tests = \Illuminate\Support\Str::of($process->getOutput()) From e52d15cff38959c0083a6673e2c7bb1c3164e6a8 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 4 Sep 2024 13:48:02 +0200 Subject: [PATCH 11/15] Foo --- bin/paralell-testing | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index 1e5edcc..9704b66 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -13,7 +13,7 @@ require_once '/home/runner/.composer/vendor/autoload.php'; * - Tests\Support\UuidTest::it_can_not_create_a_uuid_from_null * - ... */ -$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY') . '/vendor/bin/phpunit', '--list-tests']); +$process = new \Symfony\Component\Process\Process(['/tmp/test/thunder/install/vendor/bin/phpunit', '--list-tests']); $process->mustRun(); $tests = \Illuminate\Support\Str::of($process->getOutput()) @@ -35,7 +35,7 @@ $tests = \Illuminate\Support\Str::of($process->getOutput()) * Run phpunit with a filter: * phpunit --filter 'TestClass|AnotherTestClass|...' */ -$process = new \Symfony\Component\Process\Process([getenv('DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY') .'/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); +$process = new \Symfony\Component\Process\Process(['tmp/test/thunder/install/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); $process->start(); // Make sure we have live data output From 0cae21158cfe0638bf2030c7cc3e1ce51a693f0e Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Wed, 8 Jan 2025 14:33:04 +0100 Subject: [PATCH 12/15] Move debog into verbose --- lib/stages/run_tests.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index fc13181..bb1d782 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -9,7 +9,11 @@ _stage_run_tests() { test_location=$(get_project_location) local test_selection="" - local phpunit="composer exec -- phpunit --debug" + local phpunit="composer exec -- phpunit" + + if [ "${DRUPAL_TESTING_VERBOSE}" = true ]; then + phpunit="${phpunit} --debug" + fi if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then paralell-testing From 5e4f1ac11913c71d11be0b80230490b6bd5e3d6d Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Thu, 9 Jan 2025 12:46:26 +0100 Subject: [PATCH 13/15] Make us able to specify a phpunit.xml --- bin/paralell-testing | 2 +- configuration.sh | 3 +++ lib/stages/run_tests.sh | 9 ++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bin/paralell-testing b/bin/paralell-testing index 9704b66..d374439 100755 --- a/bin/paralell-testing +++ b/bin/paralell-testing @@ -35,7 +35,7 @@ $tests = \Illuminate\Support\Str::of($process->getOutput()) * Run phpunit with a filter: * phpunit --filter 'TestClass|AnotherTestClass|...' */ -$process = new \Symfony\Component\Process\Process(['tmp/test/thunder/install/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); +$process = new \Symfony\Component\Process\Process(['/tmp/test/thunder/install/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); $process->start(); // Make sure we have live data output diff --git a/configuration.sh b/configuration.sh index d4e2820..fb1c52d 100644 --- a/configuration.sh +++ b/configuration.sh @@ -45,6 +45,9 @@ DRUPAL_TESTING_COMPOSER_NAME=${DRUPAL_TESTING_COMPOSER_NAME:-$(jq -r .name "${DR # vendor/myproject the project name will be myproject. DRUPAL_TESTING_PROJECT_NAME=${DRUPAL_TESTING_PROJECT_NAME-$(jq -r --arg FALLBACK "$(echo "${DRUPAL_TESTING_COMPOSER_NAME}" | cut -d '/' -f 2)" '.extra."installer-name" // $FALLBACK' "${DRUPAL_TESTING_PROJECT_BASEDIR}/composer.json")} +# The phpunit configuration file to use. Defaults to docroot/core/phpunit.xml.dist +DRUPAL_TESTING_TEST_CONFIGURATION=${DRUPAL_TESTING_TEST_CONFIGURATION:-""} + # Path for phpunit to search for test files. Default is the current project folder. DRUPAL_TESTING_TEST_PATH=${DRUPAL_TESTING_TEST_PATH:-""} diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index bb1d782..59d0502 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -48,7 +48,14 @@ _stage_run_tests() { test_selection="${test_selection} --filter ${DRUPAL_TESTING_TEST_FILTER}" fi - local runtest="${phpunit} --configuration ${docroot}/core ${test_selection} ${test_location}" + if [[ ${DRUPAL_TESTING_TEST_CONFIGURATION} ]]; then + test_selection="${test_selection} --configuration ${DRUPAL_TESTING_TEST_CONFIGURATION}" + else + test_selection="${test_selection} --configuration ${docroot}/core" + fi + + + local runtest="${phpunit} ${test_selection} ${test_location}" cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit eval "COMPOSER_PROCESS_TIMEOUT=0 ${runtest}" || exit 1 From 5b414b591194a022d6cb2133ad1ed5a3d95d06f4 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Fri, 10 Jan 2025 15:00:47 +0100 Subject: [PATCH 14/15] Cleanup --- bin/paralell-testing | 49 ----------------------------------------- composer.json | 9 +++----- lib/stages/run_tests.sh | 8 ++++++- 3 files changed, 10 insertions(+), 56 deletions(-) delete mode 100755 bin/paralell-testing diff --git a/bin/paralell-testing b/bin/paralell-testing deleted file mode 100755 index d374439..0000000 --- a/bin/paralell-testing +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env php -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|...' - */ -$process = new \Symfony\Component\Process\Process(['/tmp/test/thunder/install/vendor/bin/phpunit', '--filter', $tests->join('|')], timeout: null); -$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()); diff --git a/composer.json b/composer.json index d96d843..cb914e2 100644 --- a/composer.json +++ b/composer.json @@ -13,19 +13,16 @@ ], "bin": [ "bin/keep-travis-running", - "bin/paralell-testing", "bin/test-drupal-project" ], "require": { - "php": ">=8.1", + "php": ">=7.2", "drupal/coder": "^8.3", - "symfony/yaml": "^6.3", - "symfony/process": "^6.3", - "illuminate/support": "^11.2" + "symfony/yaml": "^3.4" }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true } } -} +} \ No newline at end of file diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index 59d0502..13e0cfa 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -16,7 +16,13 @@ _stage_run_tests() { fi if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then - paralell-testing + phpunit="composer exec -- paratest -p "${DRUPAL_TESTING_PARALLEL_TESTING_PROCESSES} + if [ "${DRUPAL_TESTING_PARALLEL_TESTING_PER_FUNCTION}" = true ]; then + phpunit=${phpunit}" -f" + fi + if [ "${DRUPAL_TESTING_PARALLEL_TESTING_WRAPPER_RUNNER}" = true ]; then + phpunit=${phpunit}" --runner WrapperRunner" + fi fi if [[ ${DRUPAL_TESTING_TEST_GROUP} ]]; then From aa4e6872e045c44cbe85c6fc979e350d19380bbb Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Fri, 10 Jan 2025 15:01:42 +0100 Subject: [PATCH 15/15] Cleanup --- composer.json | 2 +- lib/stages/run_tests.sh | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index cb914e2..708f2d7 100644 --- a/composer.json +++ b/composer.json @@ -25,4 +25,4 @@ "dealerdirect/phpcodesniffer-composer-installer": true } } -} \ No newline at end of file +} diff --git a/lib/stages/run_tests.sh b/lib/stages/run_tests.sh index 13e0cfa..7b9615b 100644 --- a/lib/stages/run_tests.sh +++ b/lib/stages/run_tests.sh @@ -60,7 +60,6 @@ _stage_run_tests() { test_selection="${test_selection} --configuration ${docroot}/core" fi - local runtest="${phpunit} ${test_selection} ${test_location}" cd "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" || exit