From 86a6b3271518742dc39761228687a5107551d279 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 30 Jul 2023 23:49:11 +0100 Subject: [PATCH 01/12] fix: `-v` option --- composer.json | 3 ++- src/Plugins/Verbose.php | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/Plugins/Verbose.php diff --git a/composer.json b/composer.json index 2d6f6e85..aba12927 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "require-dev": { "pestphp/pest-dev-tools": "^2.12.0", "pestphp/pest-plugin-type-coverage": "^2.0.0", - "symfony/process": "^6.3.0" + "symfony/process": "^6.3.2" }, "minimum-stability": "dev", "prefer-stable": true, @@ -103,6 +103,7 @@ "Pest\\Plugins\\Profile", "Pest\\Plugins\\Retry", "Pest\\Plugins\\Snapshot", + "Pest\\Plugins\\Verbose", "Pest\\Plugins\\Version", "Pest\\Plugins\\Parallel" ] diff --git a/src/Plugins/Verbose.php b/src/Plugins/Verbose.php new file mode 100644 index 00000000..e37938a3 --- /dev/null +++ b/src/Plugins/Verbose.php @@ -0,0 +1,38 @@ +hasArgument('-'.$level, $arguments)) { + $arguments = $this->popArgument('-'.$level, $arguments); + } + } + + if ($this->hasArgument('--quiet', $arguments)) { + return $this->popArgument('--quiet', $arguments); + } + + return $arguments; + } +} From f3f35a2ed119f63eefd323a8c66d3387e908df3f Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 30 Jul 2023 23:49:20 +0100 Subject: [PATCH 02/12] feat: adds `repeat` --- src/Concerns/Testable.php | 25 +++++- src/Exceptions/InvalidArgumentException.php | 24 ++++++ src/Factories/TestCaseMethodFactory.php | 15 +++- src/PendingCalls/TestCall.php | 16 +++- tests/.snapshots/success.txt | 91 ++++++++++++++++++++- tests/Features/Repeat.php | 18 ++++ tests/Visual/Parallel.php | 2 +- 7 files changed, 185 insertions(+), 6 deletions(-) create mode 100644 src/Exceptions/InvalidArgumentException.php create mode 100644 tests/Features/Repeat.php diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index a962edf3..3268f2ae 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -187,7 +187,24 @@ trait Testable $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); - $this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description; + $description = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description; + + if ($method->repetitions > 1) { + $matches = []; + preg_match('/\((.*?)\)/', $description, $matches); + + if (count($matches) > 1) { + if (str_contains($description, 'with '.$matches[0].' /')) { + $description = str_replace('with '.$matches[0].' /', '', $description); + } else { + $description = str_replace('with '.$matches[0], '', $description); + } + } + + $description .= ' @ repetition '.($matches[1].' of '.$method->repetitions); + } + + $this->__description = self::$__latestDescription = $description; parent::setUp(); @@ -238,6 +255,12 @@ trait Testable */ private function __resolveTestArguments(array $arguments): array { + $method = TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name()); + + if ($method->repetitions > 1) { + array_shift($arguments); + } + $underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure'); $testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest)); diff --git a/src/Exceptions/InvalidArgumentException.php b/src/Exceptions/InvalidArgumentException.php new file mode 100644 index 00000000..6ba8ffa2 --- /dev/null +++ b/src/Exceptions/InvalidArgumentException.php @@ -0,0 +1,24 @@ +__invoke($this, $attributes); } - if ($this->datasets !== []) { + if ($this->datasets !== [] || $this->repetitions > 1) { $dataProviderName = $methodName.'_dataset'; $annotations[] = "@dataProvider $dataProviderName"; $datasetsCode = $this->buildDatasetForEvaluation($methodName, $dataProviderName); @@ -177,7 +182,13 @@ final class TestCaseMethodFactory */ private function buildDatasetForEvaluation(string $methodName, string $dataProviderName): string { - DatasetsRepository::with($this->filename, $methodName, $this->datasets); + $datasets = $this->datasets; + + if ($this->repetitions > 1) { + $datasets = [range(1, $this->repetitions), ...$datasets]; + } + + DatasetsRepository::with($this->filename, $methodName, $datasets); return <<testCaseMethod->repetitions = $times; + + return $this; + } + /** * Sets the test as "todo". */ diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 9dc4510d..909ae0e6 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -762,6 +762,95 @@ ! notice → This is a notice description // tests/Features/Notices.php:4 ! a "describe" group of tests → notice → This is a notice description // tests/Features/Notices.php:11 + PASS Tests\Features\Repeat + ✓ once + ✓ multiple times @ repetition 1 of 5 + ✓ multiple times @ repetition 2 of 5 + ✓ multiple times @ repetition 3 of 5 + ✓ multiple times @ repetition 4 of 5 + ✓ multiple times @ repetition 5 of 5 + ✓ multiple times with single dataset dataset "a" @ repetition 1 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 1 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 1 of 6 + ✓ multiple times with single dataset dataset "a" @ repetition 2 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 2 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 2 of 6 + ✓ multiple times with single dataset dataset "a" @ repetition 3 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 3 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 3 of 6 + ✓ multiple times with single dataset dataset "a" @ repetition 4 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 4 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 4 of 6 + ✓ multiple times with single dataset dataset "a" @ repetition 5 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 5 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 5 of 6 + ✓ multiple times with single dataset dataset "a" @ repetition 6 of 6 + ✓ multiple times with single dataset dataset "b" @ repetition 6 of 6 + ✓ multiple times with single dataset dataset "c" @ repetition 6 of 6 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 1 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 2 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 3 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 4 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 5 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 6 of 7 + ✓ multiple times with multiple dataset dataset "a" / (4) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "a" / (5) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "a" / (6) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "b" / (4) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "b" / (5) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "b" / (6) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "c" / (4) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "c" / (5) @ repetition 7 of 7 + ✓ multiple times with multiple dataset dataset "c" / (6) @ repetition 7 of 7 + PASS Tests\Features\ScopedDatasets\Directory\NestedDirectory1\TestFileInNestedDirectoryWithDatasetsFile ✓ uses dataset with (1) ✓ uses dataset with (2) @@ -1085,4 +1174,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 743 passed (1777 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 830 passed (1927 assertions) \ No newline at end of file diff --git a/tests/Features/Repeat.php b/tests/Features/Repeat.php new file mode 100644 index 00000000..e0651d33 --- /dev/null +++ b/tests/Features/Repeat.php @@ -0,0 +1,18 @@ +toBeTrue(); +})->repeat(times: 1); + +test('multiple times', function () { + expect(true)->toBeTrue(); +})->repeat(times: 5); + +test('multiple times with single dataset', function (int $number) { + expect([1, 2, 3])->toContain($number); +})->repeat(times: 6)->with(['a' => 1, 'b' => 2, 'c' => 3]); + +test('multiple times with multiple dataset', function (int $numberA, int $numberB) { + expect([1, 2, 3])->toContain($numberA) + ->and([4, 5, 6])->toContain($numberB); +})->repeat(times: 7)->with(['a' => 1, 'b' => 2, 'c' => 3], [4, 5, 6]); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index d87d551d..a8a69a34 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, 732 passed (1762 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 819 passed (1912 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); From 5f7a1663dd38ba3845ed952fa3272ab8cc917b47 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 30 Jul 2023 23:52:43 +0100 Subject: [PATCH 03/12] release: v2.10.0 --- src/Pest.php | 2 +- .../Visual/Help/visual_snapshot_of_help_command_output.snap | 2 +- .../Visual/Version/visual_snapshot_of_help_command_output.snap | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Pest.php b/src/Pest.php index b5b6953e..97f66c21 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '2.9.5'; + return '2.10.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 031e62cf..37c61192 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.9.5. + Pest Testing Framework 2.10.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 e8d95320..51f0e3be 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.9.5. + Pest Testing Framework 2.10.0. From 2e622f6fd47119a1bcf4c42cbbdd89b482395e8d Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 31 Jul 2023 00:06:36 +0100 Subject: [PATCH 04/12] chore: fixes type checkign --- src/Expectation.php | 2 +- src/Expectations/OppositeExpectation.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index dc6a2d81..79b7a742 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -430,7 +430,7 @@ final class Expectation { return Targeted::make( $this, - fn (ObjectDescription $object): bool => ! enum_exists($object->name) && $object->reflectionClass->isReadOnly(), + fn (ObjectDescription $object): bool => ! enum_exists($object->name) && $object->reflectionClass->isReadOnly() && assert(true), // @phpstan-ignore-line 'to be readonly', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index da4598f2..c234d8d1 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -109,7 +109,7 @@ final class OppositeExpectation { return Targeted::make( $this->original, - fn (ObjectDescription $object): bool => ! enum_exists($object->name) && ! $object->reflectionClass->isReadOnly(), + fn (ObjectDescription $object): bool => ! enum_exists($object->name) && ! $object->reflectionClass->isReadOnly() && assert(true), // @phpstan-ignore-line 'not to be readonly', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); From b795a9284046428187173b88466b35c1e887513a Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Mon, 31 Jul 2023 00:11:24 +0100 Subject: [PATCH 05/12] docs: updates changelog --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08e6486e..aafd406b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,22 @@ ## Unreleased +## [v2.10.0 (2023-07-31)](https://github.com/pestphp/pest/compare/v2.9.5...v2.10.0) + +### Added + +- `repeat` feature ([f3f35a2](https://github.com/pestphp/pest/commit/f3f35a2ed119f63eefd323a8c66d3387e908df3f)) + +### Fixed + +- `-v` option ([86a6b32](https://github.com/pestphp/pest/commit/86a6b3271518742dc39761228687a5107551d279)) + +## [v2.9.5 (2023-07-22)](https://github.com/pestphp/pest/compare/v2.9.4...v2.9.5) + +### Fixed + +- Assertions count on arch expectations ([632ffc2](https://github.com/pestphp/pest/commit/632ffc2f8e1fe45f739b12b818426ae14700079e)) + ## [v2.9.4 (2023-07-22)](https://github.com/pestphp/pest/compare/v2.9.3...v2.9.4) ### Fixed From 6886558ed1a8086c4e82fd2d2e283de203d98fa2 Mon Sep 17 00:00:00 2001 From: Luke Downing Date: Mon, 31 Jul 2023 11:28:53 +0100 Subject: [PATCH 06/12] feat(arch): Adds support for opposite expectations of `toHavePrefix` and `toHaveSuffix`. --- composer.json | 1 + src/Expectation.php | 6 +++--- src/Expectations/OppositeExpectation.php | 18 ++++++++++++---- tests/Features/Expect/toHavePrefix.php | 21 +++++++++++++++++++ tests/Features/Expect/toHaveSuffix.php | 21 +++++++++++++++++++ .../ToHavePrefix/HasNoPrefix/ClassWithout.php | 9 ++++++++ .../HasPrefix/PrefixClassWith.php | 9 ++++++++ .../ToHaveSuffix/HasNoSuffix/ClassWithout.php | 9 ++++++++ .../HasSuffix/ClassWithSuffix.php | 9 ++++++++ 9 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 tests/Features/Expect/toHavePrefix.php create mode 100644 tests/Features/Expect/toHaveSuffix.php create mode 100644 tests/Fixtures/Arch/ToHavePrefix/HasNoPrefix/ClassWithout.php create mode 100644 tests/Fixtures/Arch/ToHavePrefix/HasPrefix/PrefixClassWith.php create mode 100644 tests/Fixtures/Arch/ToHaveSuffix/HasNoSuffix/ClassWithout.php create mode 100644 tests/Fixtures/Arch/ToHaveSuffix/HasSuffix/ClassWithSuffix.php diff --git a/composer.json b/composer.json index aba12927..199d047f 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "psr-4": { "Tests\\Fixtures\\Covers\\": "tests/Fixtures/Covers", "Tests\\Fixtures\\Inheritance\\": "tests/Fixtures/Inheritance", + "Tests\\Fixtures\\Arch\\": "tests/Fixtures/Arch", "Tests\\": "tests/PHPUnit/" }, "files": [ diff --git a/src/Expectation.php b/src/Expectation.php index 79b7a742..32e22d3c 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -595,12 +595,12 @@ final class Expectation /** * Asserts that the given expectation target to have the given suffix. */ - public function toHavePrefix(string $suffix): ArchExpectation + public function toHavePrefix(string $prefix): ArchExpectation { return Targeted::make( $this, - fn (ObjectDescription $object): bool => str_starts_with($object->reflectionClass->getName(), $suffix), - "to have prefix '{$suffix}'", + fn (ObjectDescription $object): bool => str_starts_with($object->reflectionClass->getShortName(), $prefix), + "to have prefix '{$prefix}'", FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index c234d8d1..367dfb92 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -291,17 +291,27 @@ final class OppositeExpectation /** * Not supported. */ - public function toHavePrefix(string $suffix): never + public function toHavePrefix(string $prefix): ArchExpectation { - throw InvalidExpectation::fromMethods(['not', 'toHavePrefix']); + return Targeted::make( + $this->original, + fn (ObjectDescription $object): bool => ! str_starts_with($object->reflectionClass->getShortName(), $prefix), + "not to have prefix '{$prefix}'", + FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), + ); } /** * Not supported. */ - public function toHaveSuffix(string $suffix): never + public function toHaveSuffix(string $suffix): ArchExpectation { - throw InvalidExpectation::fromMethods(['not', 'toHaveSuffix']); + return Targeted::make( + $this->original, + fn (ObjectDescription $object): bool => ! str_ends_with($object->reflectionClass->getName(), $suffix), + "not to have suffix '{$suffix}'", + FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), + ); } /** diff --git a/tests/Features/Expect/toHavePrefix.php b/tests/Features/Expect/toHavePrefix.php new file mode 100644 index 00000000..eea734ae --- /dev/null +++ b/tests/Features/Expect/toHavePrefix.php @@ -0,0 +1,21 @@ +throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToHavePrefix\\HasNoPrefix') + ->toHavePrefix('Prefix'); + +test('has prefix') + ->expect('Tests\\Fixtures\\Arch\\ToHavePrefix\\HasPrefix') + ->toHavePrefix('Prefix'); + +test('opposite missing prefix') + ->throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToHavePrefix\\HasPrefix') + ->not->toHavePrefix('Prefix'); + +test('opposite has prefix') + ->expect('Tests\\Fixtures\\Arch\\ToHavePrefix\\HasNoPrefix') + ->not->toHavePrefix('Prefix'); diff --git a/tests/Features/Expect/toHaveSuffix.php b/tests/Features/Expect/toHaveSuffix.php new file mode 100644 index 00000000..766c9e54 --- /dev/null +++ b/tests/Features/Expect/toHaveSuffix.php @@ -0,0 +1,21 @@ +throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToHaveSuffix\\HasNoSuffix') + ->toHaveSuffix('Suffix'); + +test('has suffix') + ->expect('Tests\\Fixtures\\Arch\\ToHaveSuffix\\HasSuffix') + ->toHaveSuffix('Suffix'); + +test('opposite missing suffix') + ->throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToHaveSuffix\\HasSuffix') + ->not->toHaveSuffix('Suffix'); + +test('opposite has suffix') + ->expect('Tests\\Fixtures\\Arch\\ToHaveSuffix\\HasNoSuffix') + ->not->toHaveSuffix('Suffix'); diff --git a/tests/Fixtures/Arch/ToHavePrefix/HasNoPrefix/ClassWithout.php b/tests/Fixtures/Arch/ToHavePrefix/HasNoPrefix/ClassWithout.php new file mode 100644 index 00000000..19281e44 --- /dev/null +++ b/tests/Fixtures/Arch/ToHavePrefix/HasNoPrefix/ClassWithout.php @@ -0,0 +1,9 @@ + Date: Mon, 31 Jul 2023 11:58:13 +0100 Subject: [PATCH 07/12] release: v2.10.1 --- CHANGELOG.md | 6 ++++++ src/Pest.php | 2 +- .../visual_snapshot_of_help_command_output.snap | 2 +- .../visual_snapshot_of_help_command_output.snap | 2 +- tests/.snapshots/success.txt | 14 +++++++++++++- tests/Visual/Parallel.php | 2 +- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aafd406b..069625b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## [v2.10.1 (2023-07-31)](https://github.com/pestphp/pest/compare/v2.10.0...v2.10.1) + +### Fixed + +- `not->toHaveSuffix` and `toHavePrefix` expectations ([#888](https://github.com/pestphp/pest/pull/888)) + ## [v2.10.0 (2023-07-31)](https://github.com/pestphp/pest/compare/v2.9.5...v2.10.0) ### Added diff --git a/src/Pest.php b/src/Pest.php index 97f66c21..322884d6 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '2.10.0'; + return '2.10.1'; } 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 37c61192..b7c36edd 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.10.0. + Pest Testing Framework 2.10.1. 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 51f0e3be..0d599238 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.10.0. + Pest Testing Framework 2.10.1. diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 909ae0e6..9eeb752b 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -629,6 +629,12 @@ ✓ failures with custom message ✓ not failures + PASS Tests\Features\Expect\toHavePrefix + ✓ missing prefix + ✓ has prefix + ✓ opposite missing prefix + ✓ opposite has prefix + PASS Tests\Features\Expect\toHaveProperties ✓ pass ✓ failures @@ -642,6 +648,12 @@ ✓ failures with message and Any matcher ✓ not failures + PASS Tests\Features\Expect\toHaveSuffix + ✓ missing suffix + ✓ has suffix + ✓ opposite missing suffix + ✓ opposite has suffix + PASS Tests\Features\Expect\toMatch ✓ pass ✓ failures @@ -1174,4 +1186,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 830 passed (1927 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 838 passed (1939 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index a8a69a34..89c3a9a1 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, 819 passed (1912 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 827 passed (1924 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); From 011bd3ba827b33d3f7ab617c9a57ae3ab004a830 Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Tue, 1 Aug 2023 12:09:18 +0100 Subject: [PATCH 08/12] Added "toBeInvokable" arch expectation. --- src/Expectation.php | 13 +++++++++ src/Expectations/OppositeExpectation.php | 13 +++++++++ tests/Features/Expect/toBeInvokable.php | 29 +++++++++++++++++++ .../IsInvokable/InvokableClass.php | 13 +++++++++ .../IsInvokable/InvokableClassViaParent.php | 10 +++++++ .../IsInvokable/InvokableClassViaTrait.php | 10 +++++++ .../IsInvokable/InvokableTrait.php | 13 +++++++++ .../IsInvokable/ParentInvokableClass.php | 13 +++++++++ .../IsNotInvokable/IsNotInvokableClass.php | 13 +++++++++ 9 files changed, 127 insertions(+) create mode 100644 tests/Features/Expect/toBeInvokable.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClass.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClassViaParent.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClassViaTrait.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableTrait.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsInvokable/ParentInvokableClass.php create mode 100644 tests/Fixtures/Arch/ToBeInvokable/IsNotInvokable/IsNotInvokableClass.php diff --git a/src/Expectation.php b/src/Expectation.php index 32e22d3c..185acef6 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -693,4 +693,17 @@ final class Expectation { return ToBeUsedInNothing::make($this); } + + /** + * Asserts that the given expectation dependency is an invokable class. + */ + public function toBeInvokable(): ArchExpectation + { + return Targeted::make( + $this, + fn(ObjectDescription $object): bool => $object->reflectionClass->hasMethod('__invoke'), + 'to be invokable', + FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')) + ); + } } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 367dfb92..4f24cb76 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -365,6 +365,19 @@ final class OppositeExpectation throw InvalidExpectation::fromMethods(['not', 'toBeUsedInNothing']); } + /** + * Asserts that the given expectation dependency is not an invokable class. + */ + public function toBeInvokable(): ArchExpectation + { + return Targeted::make( + $this->original, + fn(ObjectDescription $object): bool => !$object->reflectionClass->hasMethod('__invoke'), + 'to not be invokable', + FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')) + ); + } + /** * Handle dynamic method calls into the original expectation. * diff --git a/tests/Features/Expect/toBeInvokable.php b/tests/Features/Expect/toBeInvokable.php new file mode 100644 index 00000000..c36567f7 --- /dev/null +++ b/tests/Features/Expect/toBeInvokable.php @@ -0,0 +1,29 @@ +expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass') + ->toBeInvokable(); + +test('opposite class is invokable') + ->throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass') + ->not->toBeInvokable(); + +test('class is invokable via a parent class') + ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaParent') + ->toBeInvokable(); + +test('class is invokable via a trait') + ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaTrait') + ->toBeInvokable(); + +test('failure when the class is not invokable') + ->throws(ArchExpectationFailedException::class) + ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass') + ->toBeInvokable(); + +test('class is not invokable') + ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass') + ->not->toBeInvokable(); diff --git a/tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClass.php b/tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClass.php new file mode 100644 index 00000000..24cbb979 --- /dev/null +++ b/tests/Fixtures/Arch/ToBeInvokable/IsInvokable/InvokableClass.php @@ -0,0 +1,13 @@ + Date: Tue, 1 Aug 2023 12:12:41 +0100 Subject: [PATCH 09/12] Style updates. --- src/Expectation.php | 2 +- src/Expectations/OppositeExpectation.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 185acef6..0df76ac2 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -701,7 +701,7 @@ final class Expectation { return Targeted::make( $this, - fn(ObjectDescription $object): bool => $object->reflectionClass->hasMethod('__invoke'), + fn (ObjectDescription $object): bool => $object->reflectionClass->hasMethod('__invoke'), 'to be invokable', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')) ); diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 4f24cb76..55261be8 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -372,7 +372,7 @@ final class OppositeExpectation { return Targeted::make( $this->original, - fn(ObjectDescription $object): bool => !$object->reflectionClass->hasMethod('__invoke'), + fn (ObjectDescription $object): bool => ! $object->reflectionClass->hasMethod('__invoke'), 'to not be invokable', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')) ); From 2e352c008441cee6b02000cc55502bbf5ad8078d Mon Sep 17 00:00:00 2001 From: Ash Allen Date: Tue, 1 Aug 2023 13:09:53 +0100 Subject: [PATCH 10/12] Updated comments. --- src/Expectation.php | 2 +- src/Expectations/OppositeExpectation.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 32e22d3c..9b85b24c 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -593,7 +593,7 @@ final class Expectation } /** - * Asserts that the given expectation target to have the given suffix. + * Asserts that the given expectation target to have the given prefix. */ public function toHavePrefix(string $prefix): ArchExpectation { diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 367dfb92..5f436c32 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -289,7 +289,7 @@ final class OppositeExpectation } /** - * Not supported. + * Asserts that the given expectation target to not have the given prefix. */ public function toHavePrefix(string $prefix): ArchExpectation { @@ -302,7 +302,7 @@ final class OppositeExpectation } /** - * Not supported. + * Asserts that the given expectation target to not have the given suffix. */ public function toHaveSuffix(string $suffix): ArchExpectation { From 049da041b244776765ffea5ae9f3e13bd96ec4c9 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 1 Aug 2023 14:43:50 +0100 Subject: [PATCH 11/12] release: v2.11.0 --- bin/worker.php | 1 + src/Pest.php | 2 +- .../Help/visual_snapshot_of_help_command_output.snap | 2 +- .../visual_snapshot_of_help_command_output.snap | 2 +- tests/.snapshots/success.txt | 10 +++++++++- tests/Visual/Parallel.php | 2 +- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bin/worker.php b/bin/worker.php index 6b2660d4..4c2f7be2 100644 --- a/bin/worker.php +++ b/bin/worker.php @@ -46,6 +46,7 @@ $bootPest = (static function (): void { ]; foreach ($composerAutoloadFiles as $file) { + if (file_exists($file)) { require_once $file; define('PHPUNIT_COMPOSER_INSTALL', $file); diff --git a/src/Pest.php b/src/Pest.php index 322884d6..37dc243d 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -6,7 +6,7 @@ namespace Pest; function version(): string { - return '2.10.1'; + return '2.11.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 b7c36edd..c630e2d5 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.10.1. + Pest Testing Framework 2.11.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 0d599238..30e2d8c5 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.10.1. + Pest Testing Framework 2.11.0. diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index 9eeb752b..f9d7233c 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -411,6 +411,14 @@ ✓ failures with custom message ✓ not failures + PASS Tests\Features\Expect\toBeInvokable + ✓ class is invokable + ✓ opposite class is invokable + ✓ class is invokable via a parent class + ✓ class is invokable via a trait + ✓ failure when the class is not invokable + ✓ class is not invokable + PASS Tests\Features\Expect\toBeIterable ✓ pass ✓ failures @@ -1186,4 +1194,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 838 passed (1939 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 19 skipped, 844 passed (1947 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 89c3a9a1..406c0f5b 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, 827 passed (1924 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 15 skipped, 833 passed (1932 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); From 72d482de282ee4805047f76762813a33276780f9 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Tue, 1 Aug 2023 14:49:00 +0100 Subject: [PATCH 12/12] docs: update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 069625b0..ce229105 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Unreleased +## [v2.11.0 (2023-08-01)](https://github.com/pestphp/pest/compare/v2.10.1...v2.11.0) + +### Added + +- `toBeInvokable`expectation ([#891](https://github.com/pestphp/pest/pull/891)) + ## [v2.10.1 (2023-07-31)](https://github.com/pestphp/pest/compare/v2.10.0...v2.10.1) ### Fixed