From a55da85dd2a376c4332349dd92296dce8ac0a66c Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 23 Sep 2024 13:14:03 +0100 Subject: [PATCH] release: v3.2.0 --- src/ArchPresets/Strict.php | 1 + src/Expectation.php | 15 ++++++++++++- src/Expectations/OppositeExpectation.php | 13 ++++++++++++ src/Logging/Converter.php | 2 +- src/Pest.php | 2 +- src/Support/Closure.php | 4 ++-- ...isual_snapshot_of_help_command_output.snap | 2 +- ...isual_snapshot_of_help_command_output.snap | 2 +- tests/.snapshots/success.txt | 8 ++++++- tests/Features/Expect/toUseStrictEquality.php | 21 +++++++++++++++++++ .../ToUseStrictEquality/NotStrictEquality.php | 18 ++++++++++++++++ .../ToUseStrictEquality/StrictEquality.php | 18 ++++++++++++++++ tests/Visual/Parallel.php | 2 +- 13 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 tests/Features/Expect/toUseStrictEquality.php create mode 100644 tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php create mode 100644 tests/Fixtures/Arch/ToUseStrictEquality/StrictEquality.php diff --git a/src/ArchPresets/Strict.php b/src/ArchPresets/Strict.php index e67e5e0e..e85627cd 100644 --- a/src/ArchPresets/Strict.php +++ b/src/ArchPresets/Strict.php @@ -21,6 +21,7 @@ final class Strict extends AbstractPreset fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toHaveProtectedMethods(), fn (Expectation $namespace): ArchExpectation => $namespace->classes()->not->toBeAbstract(), fn (Expectation $namespace): ArchExpectation => $namespace->toUseStrictTypes(), + fn (Expectation $namespace): ArchExpectation => $namespace->toUseStrictEquality(), fn (Expectation $namespace): ArchExpectation => $namespace->classes()->toBeFinal(), ); diff --git a/src/Expectation.php b/src/Expectation.php index 97ec5391..ec48ed4f 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -223,7 +223,7 @@ final class Expectation throw new BadMethodCallException('Expectation value is not iterable.'); } - if (count($callbacks) == 0) { + if ($callbacks === []) { throw new InvalidArgumentException('No sequence expectations defined.'); } @@ -515,6 +515,19 @@ final class Expectation ); } + /** + * Asserts that the given expectation target uses strict equality. + */ + public function toUseStrictEquality(): ArchExpectation + { + return Targeted::make( + $this, + fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' == '), // @pest-arch-ignore-line + 'to use strict equality', + FileLineFinder::where(fn (string $line): bool => str_contains($line, ' == ')), + ); + } + /** * Asserts that the given expectation target is final. */ diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index bc4d94e5..ff1810ad 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -152,6 +152,19 @@ final readonly class OppositeExpectation ); } + /** + * Asserts that the given expectation target does not use the strict equality operator. + */ + public function toUseStrictEquality(): ArchExpectation + { + return Targeted::make( + $this->original, + fn (ObjectDescription $object): bool => ! str_contains((string) file_get_contents($object->path), ' === '), + 'to use strict equality', + FileLineFinder::where(fn (string $line): bool => str_contains($line, ' === ')), + ); + } + /** * Asserts that the given expectation target is not final. */ diff --git a/src/Logging/Converter.php b/src/Logging/Converter.php index eff6b3a2..1c98bd93 100644 --- a/src/Logging/Converter.php +++ b/src/Logging/Converter.php @@ -178,7 +178,7 @@ final readonly class Converter public function getTestSuiteLocation(TestSuite $testSuite): ?string { $firstTest = $this->getFirstTest($testSuite); - if ($firstTest == null) { + if (! $firstTest instanceof \PHPUnit\Event\Code\TestMethod) { return null; } $path = $firstTest->testDox()->prettifiedClassName(); diff --git a/src/Pest.php b/src/Pest.php index f90e663b..c8fff49e 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '3.1.0'; + return '3.2.0'; } function testDirectory(string $file = ''): string diff --git a/src/Support/Closure.php b/src/Support/Closure.php index a7b75f31..2ebbd88b 100644 --- a/src/Support/Closure.php +++ b/src/Support/Closure.php @@ -20,13 +20,13 @@ final class Closure */ public static function bind(?BaseClosure $closure, ?object $newThis, object|string|null $newScope = 'static'): BaseClosure { - if ($closure == null) { + if (! $closure instanceof \Closure) { throw ShouldNotHappen::fromMessage('Could not bind null closure.'); } $closure = BaseClosure::bind($closure, $newThis, $newScope); - if ($closure == false) { + if ($closure === null) { throw ShouldNotHappen::fromMessage('Could not bind closure.'); } 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 a75ecd9b..dac63f2b 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 3.1.0. + Pest Testing Framework 3.2.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 843e9579..da245a5e 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 3.1.0. + Pest Testing Framework 3.2.0. diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 0c5eda59..030dbef9 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -968,6 +968,12 @@ ✓ it can handle a non-defined exception ✓ it can handle a class not found Error + PASS Tests\Features\Expect\toUseStrictEquality + ✓ missing strict equality + ✓ has strict equality + ✓ opposite missing strict equality + ✓ opposite has strict equality + PASS Tests\Features\Expect\toUseTrait ✓ pass ✓ failures @@ -1574,4 +1580,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1089 passed (2637 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 28 skipped, 1093 passed (2644 assertions) \ No newline at end of file diff --git a/tests/Features/Expect/toUseStrictEquality.php b/tests/Features/Expect/toUseStrictEquality.php new file mode 100644 index 00000000..c8c2ce2a --- /dev/null +++ b/tests/Features/Expect/toUseStrictEquality.php @@ -0,0 +1,21 @@ +throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality') + ->toUseStrictEquality(); + +test('has strict equality') + ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality') + ->toUseStrictEquality(); + +test('opposite missing strict equality') + ->throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality') + ->not->toUseStrictEquality(); + +test('opposite has strict equality') + ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality') + ->not->toUseStrictEquality(); diff --git a/tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php b/tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php new file mode 100644 index 00000000..d35c9e48 --- /dev/null +++ b/tests/Fixtures/Arch/ToUseStrictEquality/NotStrictEquality.php @@ -0,0 +1,18 @@ +toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1079 passed (2613 assertions)') + ->toContain('Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 17 todos, 19 skipped, 1083 passed (2620 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();