From 0064f3fdffca83aea24ae37b21f85a2a72e150e3 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 13 Apr 2023 11:03:29 +0100 Subject: [PATCH 1/4] chore: phpunit ^10.1 support --- composer.json | 4 ++-- phpunit.xml | 4 ++-- src/Logging/TeamCity/TeamCityLogger.php | 14 +++++++++----- src/Plugins/Parallel/Support/CompactPrinter.php | 15 +++++++++++++++ 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 746c2c29..06684f07 100644 --- a/composer.json +++ b/composer.json @@ -23,11 +23,11 @@ "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.1", "pestphp/pest-plugin-arch": "^2.1.1", - "phpunit/phpunit": "^10.0.19" + "phpunit/phpunit": "^10.1.0" }, "conflict": { "webmozart/assert": "<1.11.0", - "phpunit/phpunit": ">10.0.19" + "phpunit/phpunit": ">10.1.0" }, "autoload": { "psr-4": { diff --git a/phpunit.xml b/phpunit.xml index c626b394..4aac1aa2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,9 +21,9 @@ ./tests/Fixtures/Inheritance - + ./src - + diff --git a/src/Logging/TeamCity/TeamCityLogger.php b/src/Logging/TeamCity/TeamCityLogger.php index eadfada8..3a11cd5e 100644 --- a/src/Logging/TeamCity/TeamCityLogger.php +++ b/src/Logging/TeamCity/TeamCityLogger.php @@ -34,6 +34,7 @@ use PHPUnit\Event\TestSuite\Finished as TestSuiteFinished; use PHPUnit\Event\TestSuite\Started as TestSuiteStarted; use PHPUnit\Event\UnknownSubscriberTypeException; use PHPUnit\TestRunner\TestResult\Facade as TestResultFacade; +use ReflectionClass; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Output\OutputInterface; @@ -207,13 +208,16 @@ final class TeamCityLogger $style = new Style($this->output); $telemetry = $event->telemetryInfo(); + if ($this->withoutDuration) { + $reflector = new ReflectionClass($telemetry); + $property = $reflector->getProperty('snapshot'); + $property->setAccessible(true); + $snapshot = $property->getValue($telemetry); + assert($snapshot instanceof Snapshot); + $telemetry = new Info( - new Snapshot( - $telemetry->time(), - $telemetry->memoryUsage(), - $telemetry->peakMemoryUsage(), - ), + $snapshot, Duration::fromSecondsAndNanoseconds(1, 0), $telemetry->memoryUsageSinceStart(), $telemetry->durationSincePrevious(), diff --git a/src/Plugins/Parallel/Support/CompactPrinter.php b/src/Plugins/Parallel/Support/CompactPrinter.php index 95aec81d..aff82fa4 100644 --- a/src/Plugins/Parallel/Support/CompactPrinter.php +++ b/src/Plugins/Parallel/Support/CompactPrinter.php @@ -7,6 +7,7 @@ namespace Pest\Plugins\Parallel\Support; use NunoMaduro\Collision\Adapters\Phpunit\State; use NunoMaduro\Collision\Adapters\Phpunit\Style; use ParaTest\Options; +use PHPUnit\Event\Telemetry\GarbageCollectorStatus; use PHPUnit\Event\Telemetry\HRTime; use PHPUnit\Event\Telemetry\Info; use PHPUnit\Event\Telemetry\MemoryUsage; @@ -122,11 +123,25 @@ final class CompactPrinter $snapshotDuration = HRTime::fromSecondsAndNanoseconds((int) $duration->asSeconds(), $nanoseconds); $telemetryDuration = \PHPUnit\Event\Telemetry\Duration::fromSecondsAndNanoseconds((int) $duration->asSeconds(), $nanoseconds); + $status = gc_status(); + + $garbageCollectorStatus = new GarbageCollectorStatus( + $status['runs'], + $status['collected'], + $status['threshold'], + $status['roots'], + null, + null, + null, + null, + ); + $telemetry = new Info( new Snapshot( $snapshotDuration, MemoryUsage::fromBytes(0), MemoryUsage::fromBytes(0), + $garbageCollectorStatus, ), $telemetryDuration, MemoryUsage::fromBytes(0), From 41cdb5f01b94b18ca523fbabe7d6c4ba1d68168e Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 13 Apr 2023 12:23:17 +0100 Subject: [PATCH 2/4] chore: skips parallel testing --- .github/workflows/tests.yml | 4 +++- TODO.md | 3 +++ composer.json | 1 - src/Logging/TeamCity/TeamCityLogger.php | 3 ++- tests/.snapshots/help-command.txt | 6 +++++- tests/.snapshots/success.txt | 9 ++++----- tests/Visual/Collision.php | 1 - tests/Visual/Parallel.php | 4 ++-- 8 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 TODO.md diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4bb4bec6..c4015ebc 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,4 +43,6 @@ jobs: - name: Unit Tests in Parallel run: composer test:parallel - if: startsWith(matrix.os, 'windows') != true + # Waiting for Paratest support... + if: false + diff --git a/TODO.md b/TODO.md new file mode 100644 index 00000000..73e90ddf --- /dev/null +++ b/TODO.md @@ -0,0 +1,3 @@ +1. Re-add Parallel Job on workflow. +2. Re-add Parallel Testing on composer. +3. Re-add Parallel skipped tests (Visual collision, and visual parallel). diff --git a/composer.json b/composer.json index 06684f07..2ff37eac 100644 --- a/composer.json +++ b/composer.json @@ -79,7 +79,6 @@ "@test:lint", "@test:types", "@test:unit", - "@test:parallel", "@test:integration" ] }, diff --git a/src/Logging/TeamCity/TeamCityLogger.php b/src/Logging/TeamCity/TeamCityLogger.php index 3a11cd5e..f8c4d1a4 100644 --- a/src/Logging/TeamCity/TeamCityLogger.php +++ b/src/Logging/TeamCity/TeamCityLogger.php @@ -211,7 +211,8 @@ final class TeamCityLogger if ($this->withoutDuration) { $reflector = new ReflectionClass($telemetry); - $property = $reflector->getProperty('snapshot'); + + $property = $reflector->getProperty('current'); $property->setAccessible(true); $snapshot = $property->getValue($telemetry); assert($snapshot instanceof Snapshot); diff --git a/tests/.snapshots/help-command.txt b/tests/.snapshots/help-command.txt index 9a284b40..3f31bc6d 100644 --- a/tests/.snapshots/help-command.txt +++ b/tests/.snapshots/help-command.txt @@ -43,15 +43,19 @@ --enforce-time-limit ................. Enforce time limit based on test size --default-time-limit [sec] Timeout in seconds for tests that have no declared size --dont-report-useless-tests .. Do not report tests that do not test anything - --stop-on-defect ... Stop after first error, failure, warning or, risky test + --stop-on-defect ... Stop after first error, failure, warning, or risky test --stop-on-error ..................................... Stop after first error --stop-on-failure ................................. Stop after first failure --stop-on-warning ................................. Stop after first warning --stop-on-risky ................................ Stop after first risky test + --stop-on-deprecation ... Stop after first test that triggered a deprecation + --stop-on-notice ............. Stop after first test that triggered a notice --stop-on-skipped ............................ Stop after first skipped test --stop-on-incomplete ...................... Stop after first incomplete test --fail-on-warning Signal failure using shell exit code when a warning was triggered --fail-on-risky Signal failure using shell exit code when a test was considered risky + --fail-on-deprecation Signal failure using shell exit code when a deprecation was triggered + --fail-on-notice Signal failure using shell exit code when a notice was triggered --fail-on-skipped Signal failure using shell exit code when a test was skipped --fail-on-incomplete Signal failure using shell exit code when a test was marked incomplete --cache-result ............................ Write test results to cache file diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 314ae733..ad780f14 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -988,14 +988,13 @@ PASS Tests\Visual\Collision ✓ collision with (['']) - ✓ collision with (['--parallel']) PASS Tests\Visual\Help ✓ visual snapshot of help command output - PASS Tests\Visual\Parallel - ✓ parallel - ✓ a parallel test can extend another test with same name + WARN Tests\Visual\Parallel + - parallel + - a parallel test can extend another test with same name PASS Tests\Visual\SingleTestOrDirectory ✓ allows to run a single test @@ -1016,4 +1015,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 709 passed (1717 assertions) + Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 16 skipped, 706 passed (1713 assertions) \ No newline at end of file diff --git a/tests/Visual/Collision.php b/tests/Visual/Collision.php index de6dad47..bf1c4fd7 100644 --- a/tests/Visual/Collision.php +++ b/tests/Visual/Collision.php @@ -38,5 +38,4 @@ test('collision', function (array $arguments) { expect($output())->toContain(file_get_contents($snapshot)); })->with([ [['']], - [['--parallel']], ])->skipOnWindows(); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 8a354fe2..4e2fc0fb 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -20,8 +20,8 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) ->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 697 passed (1702 assertions)') ->toContain('Parallel: 3 processes'); -})->skipOnWindows(); +})->skip(); test('a parallel test can extend another test with same name', function () use ($run) { expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)'); -}); +})->skip(); From d6c3f3522b08805df55c72a066e8f5bf7bebf753 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 13 Apr 2023 12:51:19 +0100 Subject: [PATCH 3/4] chore: fix caret --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2ff37eac..ea03796e 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ }, "conflict": { "webmozart/assert": "<1.11.0", - "phpunit/phpunit": ">10.1.0" + "phpunit/phpunit": "<10.1.0" }, "autoload": { "psr-4": { From 6d8b926df38c66e5e145aab93c0df1391c5cae32 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Fri, 14 Apr 2023 11:01:54 +0100 Subject: [PATCH 4/4] chore: adjusts for parallel testing --- .github/workflows/tests.yml | 2 -- TODO.md | 3 --- composer.json | 3 ++- tests/.snapshots/success.txt | 11 ++++++----- tests/Visual/Collision.php | 1 + tests/Visual/Parallel.php | 6 +++--- 6 files changed, 12 insertions(+), 14 deletions(-) delete mode 100644 TODO.md diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c4015ebc..5c80602f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,6 +43,4 @@ jobs: - name: Unit Tests in Parallel run: composer test:parallel - # Waiting for Paratest support... - if: false diff --git a/TODO.md b/TODO.md deleted file mode 100644 index 73e90ddf..00000000 --- a/TODO.md +++ /dev/null @@ -1,3 +0,0 @@ -1. Re-add Parallel Job on workflow. -2. Re-add Parallel Testing on composer. -3. Re-add Parallel skipped tests (Visual collision, and visual parallel). diff --git a/composer.json b/composer.json index ea03796e..2d3be6e1 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": "^8.1.0", - "brianium/paratest": "^7.1.2", + "brianium/paratest": "^7.1.3", "nunomaduro/collision": "^7.4.0", "nunomaduro/termwind": "^1.15.1", "pestphp/pest-plugin": "^2.0.1", @@ -79,6 +79,7 @@ "@test:lint", "@test:types", "@test:unit", + "@test:parallel", "@test:integration" ] }, diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index ad780f14..469567e1 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -153,7 +153,7 @@ DEPR Tests\Features\Deprecated ! deprecated → str_contains(): Passing null to parameter #2 ($needle) of type string is deprecated // tests/Features/Deprecated.php:6 - ! user deprecated → Since foo 1.0: This is a deprecation description // vendor/symfony/deprecation-contracts/function.php:25 + ✓ user deprecated PASS Tests\Features\Exceptions ✓ it gives access the the underlying expectException @@ -988,13 +988,14 @@ PASS Tests\Visual\Collision ✓ collision with (['']) + ✓ collision with (['--parallel']) PASS Tests\Visual\Help ✓ visual snapshot of help command output - WARN Tests\Visual\Parallel - - parallel - - a parallel test can extend another test with same name + PASS Tests\Visual\Parallel + ✓ parallel + ✓ a parallel test can extend another test with same name PASS Tests\Visual\SingleTestOrDirectory ✓ allows to run a single test @@ -1015,4 +1016,4 @@ PASS Tests\Visual\Version ✓ visual snapshot of help command output - Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 16 skipped, 706 passed (1713 assertions) \ No newline at end of file + Tests: 1 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 14 skipped, 710 passed (1717 assertions) \ No newline at end of file diff --git a/tests/Visual/Collision.php b/tests/Visual/Collision.php index bf1c4fd7..de6dad47 100644 --- a/tests/Visual/Collision.php +++ b/tests/Visual/Collision.php @@ -38,4 +38,5 @@ test('collision', function (array $arguments) { expect($output())->toContain(file_get_contents($snapshot)); })->with([ [['']], + [['--parallel']], ])->skipOnWindows(); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 4e2fc0fb..10f0d316 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -18,10 +18,10 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 697 passed (1702 assertions)') + ->toContain('Tests: 1 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 11 skipped, 698 passed (1702 assertions)') ->toContain('Parallel: 3 processes'); -})->skip(); +})->skipOnWindows(); test('a parallel test can extend another test with same name', function () use ($run) { expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 2 passed (2 assertions)'); -})->skip(); +});