From abb416c2ffc4f2f791600ed672f850c5017411cd Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 11 Jan 2024 15:32:44 +0000 Subject: [PATCH 1/3] chore: bumps dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f16feded..14bdaf6d 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "nunomaduro/collision": "^7.10.0|^8.0.1", "nunomaduro/termwind": "^1.15.1|^2.0.0", "pestphp/pest-plugin": "^2.1.1", - "pestphp/pest-plugin-arch": "^2.5.0", + "pestphp/pest-plugin-arch": "^2.6.1", "phpunit/phpunit": "^10.5.5" }, "conflict": { @@ -52,8 +52,8 @@ }, "require-dev": { "pestphp/pest-dev-tools": "^2.16.0", - "pestphp/pest-plugin-type-coverage": "^2.6.0", - "symfony/process": "^6.4.0|^7.0.0" + "pestphp/pest-plugin-type-coverage": "^2.8.0", + "symfony/process": "^6.4.0|^7.0.2" }, "minimum-stability": "dev", "prefer-stable": true, From 5258e569c19cb782b07a12027f189b78b216dbd1 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 11 Jan 2024 15:33:12 +0000 Subject: [PATCH 2/3] feat: adds `skipOnPHP` --- src/PendingCalls/TestCall.php | 33 +++++++++++++++++++++++++++++---- tests/Features/SkipOnPhp.php | 17 +++++++++++++++++ 2 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 tests/Features/SkipOnPhp.php diff --git a/src/PendingCalls/TestCall.php b/src/PendingCalls/TestCall.php index f16ce913..d9a76d55 100644 --- a/src/PendingCalls/TestCall.php +++ b/src/PendingCalls/TestCall.php @@ -208,12 +208,37 @@ final class TestCall return $this; } + /** + * Skips the current test on the given PHP version. + */ + public function skipOnPhp(string $version): self + { + if (mb_strlen($version) < 2) { + throw new InvalidArgumentException('The version must start with [<] or [>].'); + } + + if (str_starts_with($version, '>=') || str_starts_with($version, '<=')) { + $operator = substr($version, 0, 2); + $version = substr($version, 2); + } elseif (str_starts_with($version, '>') || str_starts_with($version, '<')) { + $operator = $version[0]; + $version = substr($version, 1); + // ensure starts with number: + } elseif (is_numeric($version[0])) { + $operator = '=='; + } else { + throw new InvalidArgumentException('The version must start with [<, >, <=, >=] or a number.'); + } + + return $this->skip(version_compare(PHP_VERSION, $version, $operator), sprintf('This test is skipped on PHP [%s%s].', $operator, $version)); + } + /** * Skips the current test if the given test is running on Windows. */ public function skipOnWindows(): self { - return $this->skipOn('Windows', 'This test is skipped on [Windows].'); + return $this->skipOnOs('Windows', 'This test is skipped on [Windows].'); } /** @@ -221,7 +246,7 @@ final class TestCall */ public function skipOnMac(): self { - return $this->skipOn('Darwin', 'This test is skipped on [Mac].'); + return $this->skipOnOs('Darwin', 'This test is skipped on [Mac].'); } /** @@ -229,13 +254,13 @@ final class TestCall */ public function skipOnLinux(): self { - return $this->skipOn('Linux', 'This test is skipped on [Linux].'); + return $this->skipOnOs('Linux', 'This test is skipped on [Linux].'); } /** * Skips the current test if the given test is running on the given operating systems. */ - private function skipOn(string $osFamily, string $message): self + private function skipOnOs(string $osFamily, string $message): self { return $osFamily === PHP_OS_FAMILY ? $this->skip($message) diff --git a/tests/Features/SkipOnPhp.php b/tests/Features/SkipOnPhp.php new file mode 100644 index 00000000..ad528954 --- /dev/null +++ b/tests/Features/SkipOnPhp.php @@ -0,0 +1,17 @@ +skipOnPhp('<=7.4.0') + ->assertTrue(true); + +it('can skip on specific php version') + ->skipOnPhp(PHP_VERSION) + ->assertTrue(false); + +it('can run on specific php version') + ->skipOnPhp('7.4.0') + ->assertTrue(true); + +it('can skip on php versions depending on constraint') + ->skipOnPhp('>=7.4.0') + ->assertTrue(false); From 3457841a9b124653edcfef1d5da24e6afe176f79 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 11 Jan 2024 15:33:20 +0000 Subject: [PATCH 3/3] release: v2.31.0 --- src/Pest.php | 2 +- .../Help/visual_snapshot_of_help_command_output.snap | 2 +- .../Version/visual_snapshot_of_help_command_output.snap | 2 +- tests/.snapshots/success.txt | 8 +++++++- tests/Visual/Parallel.php | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Pest.php b/src/Pest.php index a4b9483f..e59c88de 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '2.30.0'; + return '2.31.0'; } function testDirectory(string $file = ''): string diff --git a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap index d15625d3..87b0ec07 100644 --- a/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap +++ b/tests/.pest/snapshots/Visual/Help/visual_snapshot_of_help_command_output.snap @@ -1,5 +1,5 @@ - Pest Testing Framework 2.30.0. + Pest Testing Framework 2.31.0. USAGE: pest [options] diff --git a/tests/.pest/snapshots/Visual/Version/visual_snapshot_of_help_command_output.snap b/tests/.pest/snapshots/Visual/Version/visual_snapshot_of_help_command_output.snap index 2ec9da58..969fdf6e 100644 --- a/tests/.pest/snapshots/Visual/Version/visual_snapshot_of_help_command_output.snap +++ b/tests/.pest/snapshots/Visual/Version/visual_snapshot_of_help_command_output.snap @@ -1,3 +1,3 @@ - Pest Testing Framework 2.30.0. + Pest Testing Framework 2.31.0. diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index e3b529c9..41a30e46 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -1093,6 +1093,12 @@ - it can use something in the test case as a condition → This test was skipped - it can user higher order callables and skip + WARN Tests\Features\SkipOnPhp + ✓ it can run on php version + - it can skip on specific php version → This test is skipped on PHP [==8.3.1]. + ✓ it can run on specific php version + - it can skip on php versions depending on constraint → This test is skipped on PHP [>=7.4.0]. + PASS Tests\Features\Test ✓ a test ✓ higher order message test @@ -1372,4 +1378,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 976 passed (2302 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 21 skipped, 978 passed (2304 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 86bb8ad1..2b6b463c 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ $run = function () { test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 963 passed (2283 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 17 skipped, 965 passed (2285 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();