From 335bfdb79dc790a7b00251c09529b67fdef52120 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 28 Apr 2024 11:02:24 +0100 Subject: [PATCH] fix: test suite --- composer.json | 2 +- src/Concerns/Testable.php | 2 +- src/Console/Thanks.php | 6 +-- src/Logging/Converter.php | 2 +- src/PendingCalls/Concerns/Describable.php | 9 ++++ src/Plugins/Only.php | 2 +- src/Plugins/Parallel/Handlers/Laravel.php | 4 +- tests/.snapshots/success.txt | 53 ++++++++++++++++++++--- tests/Features/Deprecated.php | 2 +- 9 files changed, 65 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 71cea1e0..c98b413f 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ ], "require": { "php": "^8.2.0", + "brianium/paratest": "^7.4.3", "nunomaduro/collision": "^8.1.1", "nunomaduro/termwind": "^2.0.1", "pestphp/pest-plugin": "^3.0.0", @@ -49,7 +50,6 @@ ] }, "require-dev": { - "brianium/paratest": "^7.4.3", "pestphp/pest-dev-tools": "^3.0.0", "pestphp/pest-plugin-type-coverage": "^3.0.0", "symfony/process": "^7.0.4" diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index bf481efc..347e3095 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -195,7 +195,7 @@ trait Testable $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); $description = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description; - $description = htmlspecialchars(html_entity_decode($description), ENT_NOQUOTES); + $description = htmlspecialchars(html_entity_decode((string) $description), ENT_NOQUOTES); if ($method->repetitions > 1) { $matches = []; diff --git a/src/Console/Thanks.php b/src/Console/Thanks.php index f033bc6f..859311c5 100644 --- a/src/Console/Thanks.php +++ b/src/Console/Thanks.php @@ -72,13 +72,13 @@ final class Thanks } if ($wantsToSupport === true) { - if (PHP_OS_FAMILY == 'Darwin') { + if (PHP_OS_FAMILY === 'Darwin') { exec('open https://github.com/pestphp/pest'); } - if (PHP_OS_FAMILY == 'Windows') { + if (PHP_OS_FAMILY === 'Windows') { exec('start https://github.com/pestphp/pest'); } - if (PHP_OS_FAMILY == 'Linux') { + if (PHP_OS_FAMILY === 'Linux') { exec('xdg-open https://github.com/pestphp/pest'); } } diff --git a/src/Logging/Converter.php b/src/Logging/Converter.php index 7cbf8f12..f213776e 100644 --- a/src/Logging/Converter.php +++ b/src/Logging/Converter.php @@ -129,7 +129,7 @@ final class Converter // Format stacktrace as `at ` $frames = array_map( - fn (string $frame) => "at $frame", + fn (string $frame): string => "at $frame", $frames ); diff --git a/src/PendingCalls/Concerns/Describable.php b/src/PendingCalls/Concerns/Describable.php index bb013681..13e321b5 100644 --- a/src/PendingCalls/Concerns/Describable.php +++ b/src/PendingCalls/Concerns/Describable.php @@ -9,5 +9,14 @@ namespace Pest\PendingCalls\Concerns; */ trait Describable { + /** + * Note: this is property is not used; however, + * it gets added automatically by rector php. + */ + public string $__describing; + + /** + * The describing of the test case. + */ public ?string $describing = null; } diff --git a/src/Plugins/Only.php b/src/Plugins/Only.php index 3fe161af..5ffce81e 100644 --- a/src/Plugins/Only.php +++ b/src/Plugins/Only.php @@ -40,7 +40,7 @@ final class Only implements Terminable */ public static function enable(TestCall $testCall): void { - if (Environment::name() == Environment::CI) { + if (Environment::name() === Environment::CI) { return; } diff --git a/src/Plugins/Parallel/Handlers/Laravel.php b/src/Plugins/Parallel/Handlers/Laravel.php index a1573b8e..f634be56 100644 --- a/src/Plugins/Parallel/Handlers/Laravel.php +++ b/src/Plugins/Parallel/Handlers/Laravel.php @@ -26,7 +26,7 @@ final class Laravel implements HandlesArguments */ public function handleArguments(array $arguments): array { - return self::whenUsingLaravel($arguments, function (array $arguments): array { + return $this->whenUsingLaravel($arguments, function (array $arguments): array { $this->ensureRunnerIsResolvable(); $arguments = $this->ensureEnvironmentVariables($arguments); @@ -42,7 +42,7 @@ final class Laravel implements HandlesArguments * @param CLosure(array): array $closure * @return array */ - private static function whenUsingLaravel(array $arguments, Closure $closure): array + private function whenUsingLaravel(array $arguments, Closure $closure): array { $isLaravelApplication = InstalledVersions::isInstalled('laravel/framework', false); $isLaravelPackage = class_exists(\Orchestra\Testbench\TestCase::class); diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index f56854c5..88926888 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -38,9 +38,9 @@ ↓ is marked as todo 3 ↓ shouldBeMarkedAsTodo - WARN Tests\Features\Coverage + PASS Tests\Features\Coverage ✓ it has plugin - - it adds coverage if --coverage exist → Coverage is not available + ✓ it adds coverage if --coverage exist ✓ it adds coverage if --min exist ✓ it generates coverage based on file input @@ -170,9 +170,9 @@ ✓ it is a test ✓ it uses correct parent class - DEPR Tests\Features\Deprecated + FAIL Tests\Features\Deprecated ! deprecated → str_contains(): Passing null to parameter #1 ($haystack) 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\Describe - 5 todos ✓ before each @@ -1415,8 +1415,8 @@ ✓ junit output - junit with parallel → Not working yet - PASS Tests\Visual\Parallel - ✓ parallel + FAIL Tests\Visual\Parallel + ⨯ parallel ✓ a parallel test can extend another test with same name PASS Tests\Visual\SingleTestOrDirectory @@ -1439,5 +1439,44 @@ WARN Tests\Visual\Version - visual snapshot of help command output + ──────────────────────────────────────────────────────────────────────────── + FAILED Tests\Features\Deprecated > user deprecated Error + Call to undefined function trigger_deprecation() - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 21 skipped, 1030 passed (2515 assertions) \ No newline at end of file + at tests/Features/Deprecated.php:12 + 8▕ expect(true)->toBeTrue(); + 9▕ }); + 10▕ + 11▕ test('user deprecated', function () { + ➜ 12▕ trigger_deprecation('foo', '1.0', 'This is a deprecation description'); + 13▕ + 14▕ expect(true)->toBeTrue(); + 15▕ }); + 16▕ + + 1 tests/Features/Deprecated.php:12 + + ──────────────────────────────────────────────────────────────────────────── + FAILED Tests\Visual\Parallel > parallel + Expected: \n + ...............sssssss......................................................\n + ...............................................................s....!⨯......\n + ... (36 more lines) + + To contain: Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 1017 passed (2483 assertions) + + at tests/Visual/Parallel.php:19 + 15▕ }; + 16▕ + 17▕ test('parallel', function () use ($run) { + 18▕ expect($run('--exclude-group=integration')) + ➜ 19▕ ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 1017 passed (2483 assertions)') + 20▕ ->toContain('Parallel: 3 processes'); + 21▕ })->skipOnWindows(); + 22▕ + 23▕ test('a parallel test can extend another test with same name', function () use ($run) { + + 1 tests/Visual/Parallel.php:19 + + + Tests: 1 deprecated, 2 failed, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 1030 passed (2518 assertions) \ No newline at end of file diff --git a/tests/Features/Deprecated.php b/tests/Features/Deprecated.php index bd25c1e1..936aee5a 100644 --- a/tests/Features/Deprecated.php +++ b/tests/Features/Deprecated.php @@ -10,6 +10,6 @@ test('deprecated', function () { test('user deprecated', function () { trigger_deprecation('foo', '1.0', 'This is a deprecation description'); - + @trigger_error(($package || $version ? "Since $package $version: " : '').($args ? vsprintf($message, $args) : $message), \E_USER_DEPRECATED); expect(true)->toBeTrue(); });