From 820fa0831313dd57a5c294b438933fa595516e05 Mon Sep 17 00:00:00 2001 From: nuno maduro Date: Sat, 18 Jul 2026 01:10:01 +0100 Subject: [PATCH] fix: package lock fingerprint --- composer.json | 3 +- phpstan.neon | 2 +- rector.php | 31 ++ .../HigherOrderExpectationTypeExtension.php | 2 +- src/Plugins/Tia/Contracts/Lockfile.php | 15 + src/Plugins/Tia/Fingerprint.php | 47 ++- src/Plugins/Tia/Lockfiles/PackageLock.php | 79 +++++ .../collision_with_data_set_________.snap | 20 +- tests/.snapshots/success.txt | 21 +- tests/Autoload.php | 2 +- tests/Datasets/Bound.php | 18 +- tests/Datasets/Numbers.php | 2 + tests/Environments/Windows.php | 4 +- tests/Features/After.php | 50 +-- tests/Features/AfterAll.php | 8 +- tests/Features/AfterEach.php | 68 ++-- tests/Features/Assignee.php | 8 +- tests/Features/BeforeAll.php | 6 +- tests/Features/BeforeEach.php | 76 ++--- ...eEachProxiesToTestCallWithExpectations.php | 6 +- .../BeforeEachProxiesToTestCallWithSkip.php | 6 +- .../BeforeEachProxiesToTestCallWithTodo.php | 4 +- tests/Features/Coverage.php | 8 +- tests/Features/Covers/ClassCoverage.php | 8 +- tests/Features/Covers/ExceptionHandling.php | 4 +- tests/Features/Covers/FunctionCoverage.php | 10 +- tests/Features/Covers/GuessCoverage.php | 15 +- tests/Features/Covers/TraitCoverage.php | 8 +- tests/Features/DatasetMethodChaining.php | 156 ++++----- tests/Features/DatasetProviderErrors.php | 23 +- tests/Features/DatasetsTests.php | 320 ++++++++---------- tests/Features/Depends.php | 34 +- tests/Features/DependsInheritance.php | 10 +- tests/Features/Deprecated.php | 8 +- tests/Features/Describe.php | 54 +-- tests/Features/DescriptionLess.php | 2 +- tests/Features/Done.php | 10 +- tests/Features/Exceptions.php | 52 ++- tests/Features/Expect/HigherOrder/methods.php | 47 ++- .../HigherOrder/methodsAndProperties.php | 27 +- .../Expect/HigherOrder/properties.php | 32 +- tests/Features/Expect/each.php | 54 ++- tests/Features/Expect/extend.php | 12 +- tests/Features/Expect/json.php | 4 +- tests/Features/Expect/matchExpectation.php | 71 ++-- tests/Features/Expect/not.php | 2 +- tests/Features/Expect/pipes.php | 30 +- tests/Features/Expect/ray.php | 6 +- tests/Features/Expect/sequence.php | 62 ++-- tests/Features/Expect/toBe.php | 8 +- tests/Features/Expect/toBeAlpha.php | 14 +- tests/Features/Expect/toBeAlphaNumeric.php | 14 +- tests/Features/Expect/toBeArray.php | 18 +- tests/Features/Expect/toBeBetween.php | 22 +- tests/Features/Expect/toBeBool.php | 18 +- tests/Features/Expect/toBeCallable.php | 18 +- tests/Features/Expect/toBeCamelCase.php | 19 +- tests/Features/Expect/toBeDigits.php | 14 +- tests/Features/Expect/toBeDirectory.php | 10 +- tests/Features/Expect/toBeEmail.php | 12 +- tests/Features/Expect/toBeEmpty.php | 26 +- tests/Features/Expect/toBeFalse.php | 12 +- tests/Features/Expect/toBeFalsy.php | 14 +- tests/Features/Expect/toBeFile.php | 12 +- tests/Features/Expect/toBeFloat.php | 14 +- tests/Features/Expect/toBeGreaterThan.php | 25 +- .../Expect/toBeGreaterThanOrEqual.php | 28 +- tests/Features/Expect/toBeIn.php | 14 +- tests/Features/Expect/toBeInfinite.php | 14 +- tests/Features/Expect/toBeInstanceOf.php | 13 +- tests/Features/Expect/toBeInt.php | 14 +- tests/Features/Expect/toBeInvokable.php | 16 +- tests/Features/Expect/toBeIterable.php | 14 +- tests/Features/Expect/toBeJson.php | 16 +- tests/Features/Expect/toBeKebabCase.php | 20 +- tests/Features/Expect/toBeLessThan.php | 24 +- tests/Features/Expect/toBeLessThanOrEqual.php | 28 +- tests/Features/Expect/toBeList.php | 20 +- tests/Features/Expect/toBeLowercase.php | 14 +- tests/Features/Expect/toBeNAN.php | 14 +- tests/Features/Expect/toBeNull.php | 16 +- tests/Features/Expect/toBeNumeric.php | 18 +- tests/Features/Expect/toBeObject.php | 18 +- .../Features/Expect/toBeReadableDirectory.php | 10 +- tests/Features/Expect/toBeReadableFile.php | 12 +- tests/Features/Expect/toBeResource.php | 20 +- tests/Features/Expect/toBeScalar.php | 14 +- tests/Features/Expect/toBeSlug.php | 12 +- tests/Features/Expect/toBeSnakeCase.php | 20 +- tests/Features/Expect/toBeString.php | 18 +- tests/Features/Expect/toBeStudlyCase.php | 19 +- tests/Features/Expect/toBeTrue.php | 12 +- tests/Features/Expect/toBeTruthy.php | 16 +- tests/Features/Expect/toBeUlid.php | 18 +- tests/Features/Expect/toBeUppercase.php | 14 +- tests/Features/Expect/toBeUrl.php | 12 +- tests/Features/Expect/toBeUuid.php | 12 +- .../Features/Expect/toBeWritableDirectory.php | 10 +- tests/Features/Expect/toBeWritableFile.php | 12 +- tests/Features/Expect/toContain.php | 24 +- tests/Features/Expect/toContainEqual.php | 18 +- .../Expect/toContainOnlyInstancesOf.php | 13 +- tests/Features/Expect/toEndWith.php | 10 +- tests/Features/Expect/toEqual.php | 10 +- .../Features/Expect/toEqualCanonicalizing.php | 14 +- tests/Features/Expect/toEqualWithDelta.php | 8 +- tests/Features/Expect/toHaveAttribute.php | 7 +- tests/Features/Expect/toHaveCamelCaseKeys.php | 10 +- tests/Features/Expect/toHaveConstructor.php | 7 +- tests/Features/Expect/toHaveCount.php | 12 +- tests/Features/Expect/toHaveDestructor.php | 7 +- .../Expect/toHaveFileSystemPermissions.php | 2 + tests/Features/Expect/toHaveKebabCaseKeys.php | 10 +- tests/Features/Expect/toHaveKey.php | 32 +- tests/Features/Expect/toHaveKeys.php | 16 +- tests/Features/Expect/toHaveLength.php | 14 +- .../Expect/toHaveLineCountLessThan.php | 4 +- tests/Features/Expect/toHaveMethod.php | 16 +- tests/Features/Expect/toHaveMethods.php | 16 +- .../Expect/toHaveMethodsDocumented.php | 6 +- .../Expect/toHavePrivateMethodsBesides.php | 4 +- tests/Features/Expect/toHaveProperties.php | 8 +- .../Expect/toHavePropertiesDocumented.php | 6 +- tests/Features/Expect/toHaveProperty.php | 18 +- .../Expect/toHaveProtectedMethodsBesides.php | 4 +- .../Expect/toHavePublicMethodsBesides.php | 4 +- tests/Features/Expect/toHaveSameSize.php | 12 +- tests/Features/Expect/toHaveSnakeCaseKeys.php | 10 +- .../Features/Expect/toHaveStudlyCaseKeys.php | 10 +- tests/Features/Expect/toMatch.php | 10 +- tests/Features/Expect/toMatchArray.php | 10 +- tests/Features/Expect/toMatchConstraint.php | 8 +- tests/Features/Expect/toMatchObject.php | 12 +- tests/Features/Expect/toMatchSnapshot.php | 62 ++-- tests/Features/Expect/toStartWith.php | 10 +- tests/Features/Expect/toThrow.php | 121 +++---- tests/Features/Expect/toUseStrictEquality.php | 10 +- tests/Features/Expect/toUseStrictTypes.php | 4 +- tests/Features/Expect/toUseTrait.php | 37 +- tests/Features/Expect/unless.php | 71 ++-- tests/Features/Expect/when.php | 71 ++-- tests/Features/Fail.php | 4 +- tests/Features/Fails.php | 4 +- tests/Features/Fixture.php | 6 +- tests/Features/Flaky.php | 73 ++-- tests/Features/Helpers.php | 14 +- tests/Features/HigherOrderTests.php | 26 +- tests/Features/Incompleted.php | 4 +- tests/Features/Issue.php | 8 +- tests/Features/It.php | 6 +- tests/Features/Note.php | 38 +-- tests/Features/Notices.php | 8 +- tests/Features/Pr.php | 8 +- tests/Features/References.php | 4 +- tests/Features/Repeat.php | 46 +-- .../Directory/Datasets/Scoped.php | 2 + .../Directory/NestedDirectory1/Datasets.php | 2 + ...tFileInNestedDirectoryWithDatasetsFile.php | 6 +- .../TestFileInNestedDirectory.php | 6 +- .../TestFileWithLocallyDefinedDataset.php | 6 +- .../Directory/TestFileWithScopedDataset.php | 6 +- .../ScopedDatasets/TestFileOutOfScope.php | 12 +- tests/Features/See.php | 4 +- tests/Features/Skip.php | 122 +++---- tests/Features/Test.php | 2 +- tests/Features/TestCycle.php | 10 +- tests/Features/ThrowsNoExceptions.php | 8 +- tests/Features/Ticket.php | 8 +- tests/Features/Todo.php | 152 ++++----- tests/Features/Warnings.php | 10 +- tests/Features/Wip.php | 10 +- tests/Fixtures/CollisionTest.php | 6 +- tests/Fixtures/Covers/CoversClass1.php | 2 + tests/Fixtures/Covers/CoversClass2.php | 2 + tests/Fixtures/Covers/CoversClass3.php | 2 + tests/Fixtures/Covers/CoversTrait.php | 2 + .../Fixtures/Inheritance/Base/ExampleTest.php | 4 +- tests/Fixtures/Inheritance/ExampleTest.php | 5 +- .../Datasets/Nested/Users.php | 2 + .../TestFileWithNestedDataset.php | 4 +- tests/Fixtures/UnexpectedOutput.php | 4 +- tests/Helpers.php | 4 +- tests/Helpers/Helper.php | 2 +- tests/Helpers/TestInHelpers.php | 4 +- tests/Hooks/AfterEachTest.php | 20 +- tests/Hooks/BeforeAllTest.php | 8 +- tests/Hooks/BeforeEachTest.php | 6 +- .../FolderWithAn@/ExampleTest.php | 4 +- tests/PHPUnit/CustomTestCase/ChildTest.php | 8 +- .../PHPUnit/CustomTestCase/CustomTestCase.php | 2 +- .../CustomTestCase/UsesPerDirectory.php | 2 +- .../SubFolder/CustomTestCaseInSubFolder.php | 2 +- .../SubFolder/UsesPerSubDirectory.php | 2 +- .../SubFolder2/UsesPerFile.php | 6 +- .../InnerFolder/UsesPerDirectoryAsPattern.php | 2 +- .../SubFolder2/UsesPerFileAsPattern.php | 2 +- tests/PHPUnit/IgnorableTest.php | 2 + tests/Pest.php | 18 +- tests/Playground.php | 4 +- tests/Plugins/Coverage.php | 2 +- tests/Unit/Configuration/In.php | 4 +- tests/Unit/Configuration/Theme.php | 4 +- tests/Unit/Console/Help.php | 2 +- tests/Unit/DatasetsTests.php | 44 +-- .../Unit/Expectations/OppositeExpectation.php | 2 + tests/Unit/Overrides/ThrowableBuilder.php | 2 +- .../Unit/Plugins/Concerns/HandleArguments.php | 6 +- tests/Unit/Plugins/Environment.php | 4 +- tests/Unit/Plugins/Retry.php | 2 +- tests/Unit/Plugins/Shard.php | 80 ++--- tests/Unit/Plugins/Tia/ContentHash.php | 82 ++--- tests/Unit/Plugins/Tia/IsEnabledForRun.php | 4 +- .../Plugins/Tia/Lockfiles/PackageLock.php | 121 +++++++ tests/Unit/Plugins/Tia/ViteDepsHelper.php | 14 +- tests/Unit/Preset.php | 10 +- tests/Unit/Support/Arr.php | 44 +-- tests/Unit/Support/Backtrace.php | 6 +- tests/Unit/Support/Container.php | 14 +- tests/Unit/Support/DatasetInfo.php | 8 +- tests/Unit/Support/ExceptionTrace.php | 6 +- tests/Unit/Support/HigherOrderMessage.php | 4 +- tests/Unit/Support/Reflection.php | 16 +- tests/Unit/Support/Str.php | 4 +- tests/Unit/TestName.php | 2 +- tests/Unit/TestSuite.php | 12 +- tests/Visual/BeforeEachTestName.php | 6 +- tests/Visual/Collision.php | 8 +- tests/Visual/Help.php | 6 +- tests/Visual/JUnit.php | 36 +- tests/Visual/Parallel.php | 26 +- tests/Visual/ParallelNestedDatasets.php | 4 +- tests/Visual/SingleTestOrDirectory.php | 14 +- tests/Visual/Success.php | 12 +- tests/Visual/TeamCity.php | 5 +- tests/Visual/Todo.php | 14 +- tests/Visual/UnicodeFilename.php | 20 +- tests/Visual/Version.php | 6 +- 237 files changed, 2409 insertions(+), 2100 deletions(-) create mode 100644 src/Plugins/Tia/Contracts/Lockfile.php create mode 100644 src/Plugins/Tia/Lockfiles/PackageLock.php create mode 100644 tests/Unit/Plugins/Tia/Lockfiles/PackageLock.php diff --git a/composer.json b/composer.json index bdcdbcf7..a2379b3d 100644 --- a/composer.json +++ b/composer.json @@ -58,10 +58,11 @@ ] }, "require-dev": { - "mrpunyapal/peststan": "^0.2.11", "laravel/pao": "^1.1.2", "pestphp/pest-dev-tools": "^5.0.0", "pestphp/pest-plugin-browser": "^5.0.0", + "pestphp/pest-plugin-phpstan": "^5.0.0", + "pestphp/pest-plugin-rector": "^5.0.0", "pestphp/pest-plugin-type-coverage": "^5.0.0", "psy/psysh": "^0.12.24" }, diff --git a/phpstan.neon b/phpstan.neon index 19f6ae4e..f58ade30 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,7 +1,7 @@ includes: - phpstan-baseline.neon - phpstan-pest-extension.neon - - vendor/mrpunyapal/peststan/extension.neon + - vendor/pestphp/pest-plugin-phpstan/extension.neon parameters: level: 7 diff --git a/rector.php b/rector.php index 1531a89d..99fafbd9 100644 --- a/rector.php +++ b/rector.php @@ -2,21 +2,33 @@ declare(strict_types=1); +use Pest\Rector\Rules\UseToMatchArrayRector; +use Pest\Rector\Set\PestSetList; use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector; use Rector\Config\RectorConfig; use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; use Rector\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector; use Rector\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector; +use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector; +use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; return RectorConfig::configure() ->withPaths([ __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withSets([ + PestSetList::PEST_CODE_QUALITY, + PestSetList::PEST_CHAIN, ]) ->withSkip([ __DIR__.'/src/Plugins/Parallel/Paratest/WrapperRunner.php', + __DIR__.'/tests/Fixtures/Arch', ReturnNeverTypeRector::class, ArrowFunctionDelegatingCallToFirstClassCallableRector::class, NarrowObjectReturnTypeRector::class, @@ -26,6 +38,25 @@ return RectorConfig::configure() RemoveReturnTagIncompatibleWithNativeTypeRector::class => [ __DIR__.'/src/Expectations/HigherOrderExpectation.php', ], + // Merges unrelated expectations into a single `toMatchArray()`, turning + // `toContain()` into exact matches, dropping `->not`, and mistaking a + // `toBeTrue()` failure message for an expected value. Unsafe here. + UseToMatchArrayRector::class, + // Test fixtures rely on "unused" constructors, params and properties + // (resolved via the container or read through reflection), so the + // dead-code and return-type rules below must not touch the test suite. + RemoveEmptyClassMethodRector::class => [ + __DIR__.'/tests', + ], + RemoveUnusedConstructorParamRector::class => [ + __DIR__.'/tests', + ], + RemoveUnusedPrivatePropertyRector::class => [ + __DIR__.'/tests', + ], + AddArrowFunctionReturnTypeRector::class => [ + __DIR__.'/tests', + ], ]) ->withPreparedSets( deadCode: true, diff --git a/src/PHPStan/HigherOrderExpectationTypeExtension.php b/src/PHPStan/HigherOrderExpectationTypeExtension.php index fdf51198..5f8268c8 100644 --- a/src/PHPStan/HigherOrderExpectationTypeExtension.php +++ b/src/PHPStan/HigherOrderExpectationTypeExtension.php @@ -19,7 +19,7 @@ use PHPStan\Type\Type; * $expectation, $opposite, $shouldReset) from being incorrectly resolved as * higher-order value property accesses by downstream ExpressionTypeResolverExtensions. * - * This extension must be registered BEFORE the peststan HigherOrderExpectationTypeExtension. + * This extension must be registered BEFORE the pest-plugin-phpstan HigherOrderExpectationTypeExtension. * * @internal */ diff --git a/src/Plugins/Tia/Contracts/Lockfile.php b/src/Plugins/Tia/Contracts/Lockfile.php new file mode 100644 index 00000000..4f622a23 --- /dev/null +++ b/src/Plugins/Tia/Contracts/Lockfile.php @@ -0,0 +1,15 @@ +> + */ + private const array LOCKFILES = [ + Lockfiles\PackageLock::class, + ]; /** * @return array{ @@ -205,7 +213,11 @@ final readonly class Fingerprint $parts = []; foreach (['package-lock.json', 'pnpm-lock.yaml', 'yarn.lock', 'bun.lock', 'bun.lockb'] as $name) { - $hash = self::trackedHash($projectRoot, $name); + if (! self::isTrackedByGit($projectRoot, $name)) { + continue; + } + + $hash = self::lockfileHash($projectRoot.'/'.$name, $name); if ($hash !== null) { $parts[] = $name.':'.$hash; @@ -215,6 +227,37 @@ final readonly class Fingerprint return $parts === [] ? null : hash('xxh128', implode("\n", $parts)); } + private static function lockfileHash(string $path, string $name): ?string + { + if (! is_file($path)) { + return null; + } + + $contents = @file_get_contents($path); + + if ($contents === false) { + return null; + } + + foreach (self::LOCKFILES as $class) { + $handler = new $class; + + if (! $handler->applies($name)) { + continue; + } + + $fingerprint = $handler->fingerprint($contents); + + if ($fingerprint !== null) { + return $fingerprint; + } + + break; + } + + return hash('xxh128', $contents); + } + private static function trackedHash(string $projectRoot, string $relativePath): ?string { if (! self::isTrackedByGit($projectRoot, $relativePath)) { diff --git a/src/Plugins/Tia/Lockfiles/PackageLock.php b/src/Plugins/Tia/Lockfiles/PackageLock.php new file mode 100644 index 00000000..9595137e --- /dev/null +++ b/src/Plugins/Tia/Lockfiles/PackageLock.php @@ -0,0 +1,79 @@ + $meta) { + if (is_string($path) && is_array($meta) && $this->isPlatformSpecific($meta)) { + $platformPaths[] = $path; + } + } + + $entries = []; + + foreach ($packages as $path => $meta) { + if (! is_string($path)) { + continue; + } + if (! is_array($meta)) { + continue; + } + if ($this->isPlatformSpecific($meta)) { + continue; + } + if ($this->isBundledUnderPlatform($path, $platformPaths)) { + continue; + } + $version = $meta['version'] ?? null; + + $entries[$path] = is_string($version) ? $version : ''; + } + + ksort($entries); + + $encoded = json_encode($entries, JSON_UNESCAPED_SLASHES); + + return $encoded === false ? null : hash('xxh128', $encoded); + } + + /** + * @param array $meta + */ + private function isPlatformSpecific(array $meta): bool + { + return isset($meta['os']) || isset($meta['cpu']) || isset($meta['libc']); + } + + /** + * @param list $platformPaths + */ + private function isBundledUnderPlatform(string $path, array $platformPaths): bool + { + return array_any($platformPaths, fn (string $platformPath): bool => str_starts_with($path, $platformPath.'/node_modules/')); + } +} diff --git a/tests/.pest/snapshots/Visual/Collision/collision_with_data_set_________.snap b/tests/.pest/snapshots/Visual/Collision/collision_with_data_set_________.snap index 1bc29248..8477d670 100644 --- a/tests/.pest/snapshots/Visual/Collision/collision_with_data_set_________.snap +++ b/tests/.pest/snapshots/Visual/Collision/collision_with_data_set_________.snap @@ -6,18 +6,18 @@ FAILED Tests\Fixtures\CollisionTest > error Exception error - at tests/Fixtures/CollisionTest.php:4 - 1▕ skip(! isset($_SERVER['COLLISION_TEST'])); - 6▕ - 7▕ test('success', function () { - 8▕ expect(true)->toBeTrue(); - 9▕ })->skip(! isset($_SERVER['COLLISION_TEST'])); + 3▕ declare(strict_types=1); + 4▕ + 5▕ test('error', function (): void { + ➜ 6▕ throw new Exception('error'); + 7▕ })->skip(! isset($_SERVER['COLLISION_TEST'])); + 8▕ + 9▕ test('success', function (): void { + 10▕ expect(true)->toBeTrue(); - 1 tests/Fixtures/CollisionTest.php:4 + 1 tests/Fixtures/CollisionTest.php:6 Tests: 1 failed, 1 passed (1 assertions) \ No newline at end of file diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index bff081e3..b5d6918d 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -298,8 +298,8 @@ ✓ it uses correct parent class DEPR Tests\Features\Deprecated - ! deprecated → str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated // tests/Features/Deprecated.php:4 - ! user deprecated → Since foo 1.0: This is a deprecation description // tests/Features/Deprecated.php:10 + ✓ deprecated + ! user deprecated → Since foo 1.0: This is a deprecation description // tests/Features/Deprecated.php:12 PASS Tests\Features\Describe - 5 todos ✓ before each @@ -1279,8 +1279,8 @@ // This is another runtime note NOTI Tests\Features\Notices - ! 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 + ! notice → This is a notice description // tests/Features/Notices.php:6 + ! a "describe" group of tests → notice → This is a notice description // tests/Features/Notices.php:13 PASS Tests\Features\Pr ✓ it may be associated with an pr #1, #2 @@ -1825,6 +1825,17 @@ ✓ does not throw when an integer --random-order-seed is passed as a separate argv element ✓ still detects --tia when an integer argument is present + PASS Tests\Unit\Plugins\Tia\Lockfiles\PackageLock + ✓ it applies only to package-lock.json + ✓ it returns null for contents that are not an npm lockfile + ✓ it is stable when the directory-derived top-level name changes + ✓ it ignores platform-specific native binaries added or dropped per OS + ✓ it ignores libc-constrained variants + ✓ it ignores runtime deps bundled beneath a platform-specific package + ✓ it detects a real dependency version change + ✓ it detects an added or removed non-platform dependency + ✓ it is independent of package ordering + PASS Tests\Unit\Plugins\Tia\ViteDepsHelper ✓ it strips JSONC down to something JSON.parse accepts with ('plain-object') ✓ it strips JSONC down to something JSON.parse accepts with ('plain-array') @@ -2073,4 +2084,4 @@ ✓ pass with dataset with ('my-datas-set-value') ✓ within describe → pass with dataset with ('my-datas-set-value') - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1452 passed (3209 assertions) \ No newline at end of file + Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 35 skipped, 1462 passed (3220 assertions) \ No newline at end of file diff --git a/tests/Autoload.php b/tests/Autoload.php index 5bd3c23b..c9eb2848 100644 --- a/tests/Autoload.php +++ b/tests/Autoload.php @@ -21,7 +21,7 @@ trait SecondPluginTrait Plugin::uses(PluginTrait::class); Plugin::uses(SecondPluginTrait::class); -function _assertThat() +function _assertThat(): void { expect(true)->toBeTrue(); } diff --git a/tests/Datasets/Bound.php b/tests/Datasets/Bound.php index f8932962..cb98d5e6 100644 --- a/tests/Datasets/Bound.php +++ b/tests/Datasets/Bound.php @@ -1,19 +1,13 @@ 1; + yield fn (): int => 2; }); dataset('bound.array', [ - function () { - return 1; - }, - function () { - return 2; - }, + fn (): int => 1, + fn (): int => 2, ]); diff --git a/tests/Datasets/Numbers.php b/tests/Datasets/Numbers.php index fc2d81b7..640ca1b3 100644 --- a/tests/Datasets/Numbers.php +++ b/tests/Datasets/Numbers.php @@ -1,5 +1,7 @@ toBeString(); }); diff --git a/tests/Features/After.php b/tests/Features/After.php index f65a54d2..c57f3c5a 100644 --- a/tests/Features/After.php +++ b/tests/Features/After.php @@ -1,10 +1,10 @@ count = 0; }); -afterEach(function () { +afterEach(function (): void { match ($this->name()) { '__pest_evaluable_it_can_run_after_test' => expect($this->count)->toBe(1), '__pest_evaluable_it_can_run_after_test_twice' => expect($this->count)->toBe(1), @@ -21,37 +21,37 @@ afterEach(function () { $this->count++; }); -it('can run after test', function () { +it('can run after test', function (): void { expect($this->count)->toBe(0); $this->count++; -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(2); $this->count++; }); -it('can run after test twice', function () { +it('can run after test twice', function (): void { expect($this->count)->toBe(0); $this->count++; -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(2); $this->count++; -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(3); $this->count++; }); -it('does not run when skipped', function () { +it('does not run when skipped', function (): void { dd('This should not run 1'); -})->skip()->after(function () { +})->skip()->after(function (): void { dd('This should not run 2'); }); -afterEach(function () { +afterEach(function (): void { match ($this->name()) { '__pest_evaluable_it_can_run_after_test' => expect($this->count)->toBe(3), '__pest_evaluable_it_can_run_after_test_twice' => expect($this->count)->toBe(4), @@ -70,7 +70,7 @@ afterEach(function () { $this->count++; }); -afterEach(function () { +afterEach(function (): void { match ($this->name()) { '__pest_evaluable_it_can_run_after_test' => expect($this->count)->toBe(4), '__pest_evaluable_it_can_run_after_test_twice' => expect($this->count)->toBe(5), @@ -87,47 +87,47 @@ afterEach(function () { $this->count++; }); -describe('something', function () { - it('does not run when skipped', function () { +describe('something', function (): void { + it('does not run when skipped', function (): void { dd('This should not run 3'); - })->skip()->after(function () { + })->skip()->after(function (): void { dd('This should not run 4'); }); - it('can run after test', function () { + it('can run after test', function (): void { expect($this->count)->toBe(0); $this->count++; - })->after(function () { + })->after(function (): void { expect($this->count)->toBe(5); $this->count++; - })->after(function () { + })->after(function (): void { expect($this->count)->toBe(6); $this->count++; }); -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(4); $this->count++; }); -describe('something 2', function () { - it('can run after test', function () { +describe('something 2', function (): void { + it('can run after test', function (): void { expect($this->count)->toBe(0); $this->count++; - })->after(function () { + })->after(function (): void { expect($this->count)->toBe(6); $this->count++; }); -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(4); $this->count++; -})->after(function () { +})->after(function (): void { expect($this->count)->toBe(5); $this->count++; @@ -136,7 +136,7 @@ describe('something 2', function () { test('high order test') ->defer(fn () => $this->count++) ->expect(fn () => $this->count)->toBe(1) - ->after(function () { + ->after(function (): void { expect($this->count)->toBe(4); $this->count++; @@ -146,7 +146,7 @@ test('high order test with skip') ->skip() ->defer(fn () => $this->count++) ->expect(fn () => $this->count)->toBe(1) - ->after(function () { + ->after(function (): void { dd('This should not run 5'); }); diff --git a/tests/Features/AfterAll.php b/tests/Features/AfterAll.php index 1be6eaf1..78401f08 100644 --- a/tests/Features/AfterAll.php +++ b/tests/Features/AfterAll.php @@ -2,18 +2,18 @@ $file = __DIR__.DIRECTORY_SEPARATOR.'after-all-test'; -beforeAll(function () use ($file) { +beforeAll(function () use ($file): void { @unlink($file); }); -afterAll(function () use ($file) { +afterAll(function () use ($file): void { @unlink($file); }); -test('deletes file after all', function () use ($file) { +test('deletes file after all', function () use ($file): void { file_put_contents($file, 'foo'); $this->assertFileExists($file); - register_shutdown_function(function () { + register_shutdown_function(function (): void { // $this->assertFileDoesNotExist($file); }); }); diff --git a/tests/Features/AfterEach.php b/tests/Features/AfterEach.php index aff68283..21b975eb 100644 --- a/tests/Features/AfterEach.php +++ b/tests/Features/AfterEach.php @@ -2,99 +2,99 @@ $state = new stdClass; -beforeEach(function () use ($state) { +beforeEach(function () use ($state): void { $this->state = $state; }); -afterEach(function () { +afterEach(function (): void { $this->state->bar = 1; }); -afterEach(function () { +afterEach(function (): void { unset($this->state->bar); }); -it('does not get executed before the test', function () { +it('does not get executed before the test', function (): void { expect($this->state)->not->toHaveProperty('bar'); }); -it('gets executed after the test', function () { - expect($this->state)->toHaveProperty('bar'); - expect($this->state->bar)->toBe(2); +it('gets executed after the test', function (): void { + expect($this->state)->toHaveProperty('bar') + ->and($this->state->bar)->toBe(2); }); -afterEach(function () { +afterEach(function (): void { $this->state->bar = 2; }); -describe('outer', function () { - afterEach(function () { +describe('outer', function (): void { + afterEach(function (): void { $this->state->bar++; }); - describe('inner', function () { - afterEach(function () { + describe('inner', function (): void { + afterEach(function (): void { $this->state->bar++; }); - it('does not get executed before the test', function () { - expect($this->state)->toHaveProperty('bar'); - expect($this->state->bar)->toBe(2); + it('does not get executed before the test', function (): void { + expect($this->state)->toHaveProperty('bar') + ->and($this->state->bar)->toBe(2); }); - it('should call all parent afterEach functions', function () { - expect($this->state)->toHaveProperty('bar'); - expect($this->state->bar)->toBe(4); + it('should call all parent afterEach functions', function (): void { + expect($this->state)->toHaveProperty('bar') + ->and($this->state->bar)->toBe(4); }); }); }); -describe('matching describe block names', function () { - afterEach(function () { +describe('matching describe block names', function (): void { + afterEach(function (): void { $this->state->foo = 1; }); - describe('outer', function () { - afterEach(function () { + describe('outer', function (): void { + afterEach(function (): void { $this->state->foo++; }); - describe('middle', function () { - afterEach(function () { + describe('middle', function (): void { + afterEach(function (): void { $this->state->foo++; }); - describe('inner', function () { - afterEach(function () { + describe('inner', function (): void { + afterEach(function (): void { $this->state->foo++; }); - it('does not get executed before the test', function () { + it('does not get executed before the test', function (): void { expect($this)->not->toHaveProperty('foo'); }); - it('should call all parent afterEach functions', function () { + it('should call all parent afterEach functions', function (): void { expect($this->state->foo)->toBe(4); }); }); }); - describe('middle', function () { - it('does not get executed before the test', function () { + describe('middle', function (): void { + it('does not get executed before the test', function (): void { expect($this)->not->toHaveProperty('foo'); }); - it('should not call afterEach functions for sibling describe blocks with the same name', function () { + it('should not call afterEach functions for sibling describe blocks with the same name', function (): void { expect($this)->not->toHaveProperty('foo'); }); }); - describe('inner', function () { - it('does not get executed before the test', function () { + describe('inner', function (): void { + it('does not get executed before the test', function (): void { expect($this)->not->toHaveProperty('foo'); }); - it('should not call afterEach functions for descendent of sibling describe blocks with the same name', function () { + it('should not call afterEach functions for descendent of sibling describe blocks with the same name', function (): void { expect($this)->not->toHaveProperty('foo'); }); }); diff --git a/tests/Features/Assignee.php b/tests/Features/Assignee.php index 7995cb5a..e1ca639d 100644 --- a/tests/Features/Assignee.php +++ b/tests/Features/Assignee.php @@ -1,15 +1,15 @@ toBeTrue(); })->assignee('nunomaduro'); -it('may be associated with an assignee', function () { +it('may be associated with an assignee', function (): void { expect(true)->toBeTrue(); })->assignee('taylorotwell'); -describe('nested', function () { - it('may be associated with an assignee', function () { +describe('nested', function (): void { + it('may be associated with an assignee', function (): void { expect(true)->toBeTrue(); })->assignee('taylorotwell'); })->assignee('nunomaduro')->note('an note between an the assignee')->assignee(['jamesbrooks', 'joedixon']); diff --git a/tests/Features/BeforeAll.php b/tests/Features/BeforeAll.php index 2285ae86..1545011c 100644 --- a/tests/Features/BeforeAll.php +++ b/tests/Features/BeforeAll.php @@ -3,16 +3,16 @@ $foo = new stdClass; $foo->bar = 0; -beforeAll(function () use ($foo) { +beforeAll(function () use ($foo): void { $foo->bar++; }); -it('gets executed before tests', function () use ($foo) { +it('gets executed before tests', function () use ($foo): void { expect($foo)->bar->toBe(1); $foo->bar = 'changed'; }); -it('do not get executed before each test', function () use ($foo) { +it('do not get executed before each test', function () use ($foo): void { expect($foo)->bar->toBe('changed'); }); diff --git a/tests/Features/BeforeEach.php b/tests/Features/BeforeEach.php index a7c7befe..ef78194e 100644 --- a/tests/Features/BeforeEach.php +++ b/tests/Features/BeforeEach.php @@ -1,91 +1,91 @@ bar = 2; }); -beforeEach(function () { +beforeEach(function (): void { $this->bar++; }); -beforeEach(function () { +beforeEach(function (): void { $this->bar = 0; }); -it('gets executed before each test', function () { +it('gets executed before each test', function (): void { expect($this->bar)->toBe(1); $this->bar = 'changed'; }); -it('gets executed before each test once again', function () { +it('gets executed before each test once again', function (): void { expect($this->bar)->toBe(1); }); -beforeEach(function () { +beforeEach(function (): void { $this->bar++; }); -describe('outer', function () { - beforeEach(function () { +describe('outer', function (): void { + beforeEach(function (): void { $this->bar++; }); - describe('inner', function () { - beforeEach(function () { + describe('inner', function (): void { + beforeEach(function (): void { $this->bar++; }); - it('should call all parent beforeEach functions', function () { + it('should call all parent beforeEach functions', function (): void { expect($this->bar)->toBe(3); }); }); }); -describe('with expectations', function () { +describe('with expectations', function (): void { beforeEach()->expect(true)->toBeTrue(); - describe('nested block', function () { - test('test', function () {}); + describe('nested block', function (): void { + test('test', function (): void {}); }); - test('test', function () {}); + test('test', function (): void {}); }); -describe('matching describe block names', function () { - beforeEach(function () { +describe('matching describe block names', function (): void { + beforeEach(function (): void { $this->foo = 1; }); - describe('outer', function () { - beforeEach(function () { + describe('outer', function (): void { + beforeEach(function (): void { $this->foo++; }); - describe('middle', function () { - beforeEach(function () { + describe('middle', function (): void { + beforeEach(function (): void { $this->foo++; }); - describe('inner', function () { - beforeEach(function () { + describe('inner', function (): void { + beforeEach(function (): void { $this->foo++; }); - it('should call all parent beforeEach functions', function () { + it('should call all parent beforeEach functions', function (): void { expect($this->foo)->toBe(4); }); }); }); - describe('middle', function () { - it('should not call beforeEach functions for sibling describe blocks with the same name', function () { + describe('middle', function (): void { + it('should not call beforeEach functions for sibling describe blocks with the same name', function (): void { expect($this->foo)->toBe(2); }); }); - describe('inner', function () { - it('should not call beforeEach functions for descendent of sibling describe blocks with the same name', function () { + describe('inner', function (): void { + it('should not call beforeEach functions for descendent of sibling describe blocks with the same name', function (): void { expect($this->foo)->toBe(2); }); }); @@ -93,36 +93,36 @@ describe('matching describe block names', function () { }); $matchingNameCalls = 0; -describe('matching name', function () use (&$matchingNameCalls) { - beforeEach(function () use (&$matchingNameCalls) { +describe('matching name', function () use (&$matchingNameCalls): void { + beforeEach(function () use (&$matchingNameCalls): void { $matchingNameCalls++; }); - it('should call the before each', function () use (&$matchingNameCalls) { + it('should call the before each', function () use (&$matchingNameCalls): void { expect($matchingNameCalls)->toBe(1); }); }); -describe('matching name', function () use (&$matchingNameCalls) { - it('should not call the before each on the describe block with the same name', function () use (&$matchingNameCalls) { +describe('matching name', function () use (&$matchingNameCalls): void { + it('should not call the before each on the describe block with the same name', function () use (&$matchingNameCalls): void { expect($matchingNameCalls)->toBe(1); }); }); -beforeEach(function () { +beforeEach(function (): void { $this->baz = 1; }); -describe('called on all tests', function () { - beforeEach(function () { +describe('called on all tests', function (): void { + beforeEach(function (): void { $this->baz++; }); - test('beforeEach should be called', function () { + test('beforeEach should be called', function (): void { expect($this->baz)->toBe(2); }); - test('beforeEach should be called for all tests', function () { + test('beforeEach should be called for all tests', function (): void { expect($this->baz)->toBe(2); }); }); diff --git a/tests/Features/BeforeEachProxiesToTestCallWithExpectations.php b/tests/Features/BeforeEachProxiesToTestCallWithExpectations.php index cc15d3ec..98037eea 100644 --- a/tests/Features/BeforeEachProxiesToTestCallWithExpectations.php +++ b/tests/Features/BeforeEachProxiesToTestCallWithExpectations.php @@ -2,14 +2,14 @@ beforeEach()->expect(true)->toBeTrue(); -test('runs 1', function () { +test('runs 1', function (): void { // This test did performs assertions... }); -test('runs 2', function () { +test('runs 2', function (): void { // This test did performs assertions... }); -test('runs 3', function () { +test('runs 3', function (): void { // This test did performs assertions... }); diff --git a/tests/Features/BeforeEachProxiesToTestCallWithSkip.php b/tests/Features/BeforeEachProxiesToTestCallWithSkip.php index b315c9d8..34cc61fb 100644 --- a/tests/Features/BeforeEachProxiesToTestCallWithSkip.php +++ b/tests/Features/BeforeEachProxiesToTestCallWithSkip.php @@ -2,14 +2,14 @@ beforeEach()->skip(); -test('does not run 1', function () { +test('does not run 1', function (): void { $this->fail('This test should not run'); }); -test('does not run 2', function () { +test('does not run 2', function (): void { $this->fail('This test should not run'); }); -test('does not run 3', function () { +test('does not run 3', function (): void { $this->fail('This test should not run'); }); diff --git a/tests/Features/BeforeEachProxiesToTestCallWithTodo.php b/tests/Features/BeforeEachProxiesToTestCallWithTodo.php index 8f113976..7c9de872 100644 --- a/tests/Features/BeforeEachProxiesToTestCallWithTodo.php +++ b/tests/Features/BeforeEachProxiesToTestCallWithTodo.php @@ -2,11 +2,11 @@ beforeEach()->todo(); -test('is marked as todo 1', function () { +test('is marked as todo 1', function (): void { $this->fail('This test should not run'); }); -test('is marked as todo 2', function () { +test('is marked as todo 2', function (): void { $this->fail('This test should not run'); }); diff --git a/tests/Features/Coverage.php b/tests/Features/Coverage.php index 55ce4164..16e731bb 100644 --- a/tests/Features/Coverage.php +++ b/tests/Features/Coverage.php @@ -6,12 +6,12 @@ use Symfony\Component\Console\Output\ConsoleOutput; it('has plugin')->assertTrue(class_exists(CoveragePlugin::class)); -it('adds coverage if --coverage exist', function () { +it('adds coverage if --coverage exist', function (): void { $plugin = new CoveragePlugin(new ConsoleOutput); expect($plugin->coverage)->toBeFalse(); $arguments = $plugin->handleArguments([]); - expect($arguments)->toEqual([]) + expect($arguments)->toBeEmpty() ->and($plugin->coverage)->toBeFalse(); $arguments = $plugin->handleArguments(['--coverage']); @@ -19,7 +19,7 @@ it('adds coverage if --coverage exist', function () { ->and($plugin->coverage)->toBeTrue(); })->skip(! Coverage::isAvailable() || ! function_exists('xdebug_info') || ! in_array('coverage', xdebug_info('mode'), true), 'Coverage is not available'); -it('adds coverage if --min exist', function () { +it('adds coverage if --min exist', function (): void { $plugin = new CoveragePlugin(new ConsoleOutput); expect($plugin->coverageMin)->toEqual(0.0) ->and($plugin->coverage)->toBeFalse(); @@ -34,7 +34,7 @@ it('adds coverage if --min exist', function () { expect($plugin->coverageMin)->toEqual(2.4); }); -it('generates coverage based on file input', function () { +it('generates coverage based on file input', function (): void { expect(Coverage::getMissingCoverage(new class { public function lineCoverageData(): array diff --git a/tests/Features/Covers/ClassCoverage.php b/tests/Features/Covers/ClassCoverage.php index ab805e17..ec5369ca 100644 --- a/tests/Features/Covers/ClassCoverage.php +++ b/tests/Features/Covers/ClassCoverage.php @@ -5,9 +5,9 @@ use Tests\Fixtures\Covers\CoversClass1; covers([CoversClass1::class]); -it('uses the correct PHPUnit attribute for class', function () { - $attributes = (new ReflectionClass($this))->getAttributes(); +it('uses the correct PHPUnit attribute for class', function (): void { + $attributes = new ReflectionClass($this)->getAttributes(); - expect($attributes[1]->getName())->toBe(CoversClass::class); - expect($attributes[1]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversClass1'); + expect($attributes[1]->getName())->toBe(CoversClass::class) + ->and($attributes[1]->getArguments()[0])->toBe(CoversClass1::class); }); diff --git a/tests/Features/Covers/ExceptionHandling.php b/tests/Features/Covers/ExceptionHandling.php index de86bb02..99e6a24a 100644 --- a/tests/Features/Covers/ExceptionHandling.php +++ b/tests/Features/Covers/ExceptionHandling.php @@ -1,9 +1,11 @@ 'closure'); $testCall->covers('fakeName'); diff --git a/tests/Features/Covers/FunctionCoverage.php b/tests/Features/Covers/FunctionCoverage.php index fba97080..50c1d50a 100644 --- a/tests/Features/Covers/FunctionCoverage.php +++ b/tests/Features/Covers/FunctionCoverage.php @@ -2,11 +2,11 @@ use PHPUnit\Framework\Attributes\CoversFunction; -function testCoversFunction() {} +function testCoversFunction(): void {} -it('uses the correct PHPUnit attribute for function', function () { - $attributes = (new ReflectionClass($this))->getAttributes(); +it('uses the correct PHPUnit attribute for function', function (): void { + $attributes = new ReflectionClass($this)->getAttributes(); - expect($attributes[1]->getName())->toBe(CoversFunction::class); - expect($attributes[1]->getArguments()[0])->toBe('testCoversFunction'); + expect($attributes[1]->getName())->toBe(CoversFunction::class) + ->and($attributes[1]->getArguments()[0])->toBe('testCoversFunction'); })->coversFunction('testCoversFunction'); diff --git a/tests/Features/Covers/GuessCoverage.php b/tests/Features/Covers/GuessCoverage.php index e8a84035..4f97f8fc 100644 --- a/tests/Features/Covers/GuessCoverage.php +++ b/tests/Features/Covers/GuessCoverage.php @@ -4,14 +4,13 @@ use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\CoversFunction; use Tests\Fixtures\Covers\CoversClass3; -function testCoversFunction2() {} +function testCoversFunction2(): void {} -it('guesses if the given argument is a class or function', function () { - $attributes = (new ReflectionClass($this))->getAttributes(); +it('guesses if the given argument is a class or function', function (): void { + $attributes = new ReflectionClass($this)->getAttributes(); - expect($attributes[1]->getName())->toBe(CoversClass::class); - expect($attributes[1]->getArguments()[0])->toBe(CoversClass3::class); - - expect($attributes[2]->getName())->toBe(CoversFunction::class); - expect($attributes[2]->getArguments()[0])->toBe('testCoversFunction2'); + expect($attributes[1]->getName())->toBe(CoversClass::class) + ->and($attributes[1]->getArguments()[0])->toBe(CoversClass3::class) + ->and($attributes[2]->getName())->toBe(CoversFunction::class) + ->and($attributes[2]->getArguments()[0])->toBe('testCoversFunction2'); })->covers(CoversClass3::class, 'testCoversFunction2'); diff --git a/tests/Features/Covers/TraitCoverage.php b/tests/Features/Covers/TraitCoverage.php index 57bc3680..f05cc725 100644 --- a/tests/Features/Covers/TraitCoverage.php +++ b/tests/Features/Covers/TraitCoverage.php @@ -3,9 +3,9 @@ use PHPUnit\Framework\Attributes\CoversTrait as PHPUnitCoversTrait; use Tests\Fixtures\Covers\CoversTrait; -it('uses the correct PHPUnit attribute for trait', function () { - $attributes = (new ReflectionClass($this))->getAttributes(); +it('uses the correct PHPUnit attribute for trait', function (): void { + $attributes = new ReflectionClass($this)->getAttributes(); - expect($attributes[1]->getName())->toBe(PHPUnitCoversTrait::class); - expect($attributes[1]->getArguments()[0])->toBe('Tests\Fixtures\Covers\CoversTrait'); + expect($attributes[1]->getName())->toBe(PHPUnitCoversTrait::class) + ->and($attributes[1]->getArguments()[0])->toBe(CoversTrait::class); })->coversTrait(CoversTrait::class); diff --git a/tests/Features/DatasetMethodChaining.php b/tests/Features/DatasetMethodChaining.php index d1474f46..af1fa261 100644 --- a/tests/Features/DatasetMethodChaining.php +++ b/tests/Features/DatasetMethodChaining.php @@ -11,41 +11,41 @@ // beforeEach()->with() inside describe blocks // --------------------------------------------------------------- -describe('beforeEach()->with() applies dataset to tests', function () { +describe('beforeEach()->with() applies dataset to tests', function (): void { beforeEach()->with([10]); - test('receives the dataset value', function ($value) { + test('receives the dataset value', function ($value): void { expect($value)->toBe(10); }); - it('also receives the dataset value in it()', function ($value) { + it('also receives the dataset value in it()', function ($value): void { expect($value)->toBe(10); }); }); -describe('beforeEach()->with() with multiple dataset values', function () { +describe('beforeEach()->with() with multiple dataset values', function (): void { beforeEach()->with([1, 2, 3]); - test('receives each value from the dataset', function ($value) { + test('receives each value from the dataset', function ($value): void { expect($value)->toBeIn([1, 2, 3]); }); }); -describe('beforeEach()->with() with keyed dataset', function () { +describe('beforeEach()->with() with keyed dataset', function (): void { beforeEach()->with(['first' => [10], 'second' => [20]]); - test('receives keyed dataset values', function ($value) { + test('receives keyed dataset values', function ($value): void { expect($value)->toBeIn([10, 20]); }); }); -describe('beforeEach()->with() with closure dataset', function () { +describe('beforeEach()->with() with closure dataset', function (): void { beforeEach()->with(function () { yield [100]; yield [200]; }); - test('receives values from closure dataset', function ($value) { + test('receives values from closure dataset', function ($value): void { expect($value)->toBeIn([100, 200]); }); }); @@ -54,30 +54,30 @@ describe('beforeEach()->with() with closure dataset', function () { // describe()->with() method chaining // --------------------------------------------------------------- -describe('describe()->with() passes dataset to tests', function () { - test('receives the dataset value', function ($value) { +describe('describe()->with() passes dataset to tests', function (): void { + test('receives the dataset value', function ($value): void { expect($value)->toBe(42); }); - it('also receives it in it()', function ($value) { + it('also receives it in it()', function ($value): void { expect($value)->toBe(42); }); })->with([42]); -describe('describe()->with() with multiple values', function () { - test('receives each value', function ($value) { +describe('describe()->with() with multiple values', function (): void { + test('receives each value', function ($value): void { expect($value)->toBeIn([5, 10, 15]); }); })->with([5, 10, 15]); -describe('describe()->with() with keyed dataset', function () { - test('receives keyed values', function ($value) { +describe('describe()->with() with keyed dataset', function (): void { + test('receives keyed values', function ($value): void { expect($value)->toBeIn([100, 200]); }); })->with(['alpha' => [100], 'beta' => [200]]); -describe('describe()->with() with closure dataset', function () { - test('receives closure dataset values', function ($value) { +describe('describe()->with() with closure dataset', function (): void { + test('receives closure dataset values', function ($value): void { expect($value)->toBeIn([7, 14]); }); })->with(function () { @@ -89,33 +89,33 @@ describe('describe()->with() with closure dataset', function () { // Nested describe blocks with datasets // --------------------------------------------------------------- -describe('outer with dataset', function () { - describe('inner without dataset', function () { - test('inherits outer dataset', function (...$args) { +describe('outer with dataset', function (): void { + describe('inner without dataset', function (): void { + test('inherits outer dataset', function (...$args): void { expect($args)->toBe([1]); }); }); })->with([1]); -describe('nested describe blocks with datasets at multiple levels', function () { - describe('level 1', function () { - test('receives level 1 dataset', function (...$args) { +describe('nested describe blocks with datasets at multiple levels', function (): void { + describe('level 1', function (): void { + test('receives level 1 dataset', function (...$args): void { expect($args)->toBe([10]); }); - describe('level 2', function () { - test('receives datasets from all ancestor levels', function (...$args) { + describe('level 2', function (): void { + test('receives datasets from all ancestor levels', function (...$args): void { expect($args)->toBe([10, 20]); }); })->with([20]); })->with([10]); }); -describe('deeply nested describe with datasets', function () { - describe('a', function () { - describe('b', function () { - describe('c', function () { - test('receives all ancestor datasets', function (...$args) { +describe('deeply nested describe with datasets', function (): void { + describe('a', function (): void { + describe('b', function (): void { + describe('c', function (): void { + test('receives all ancestor datasets', function (...$args): void { expect($args)->toBe([1, 2, 3]); }); })->with([3]); @@ -127,19 +127,19 @@ describe('deeply nested describe with datasets', function () { // Combining hook datasets with test-level datasets // --------------------------------------------------------------- -describe('beforeEach()->with() combined with test->with()', function () { +describe('beforeEach()->with() combined with test->with()', function (): void { beforeEach()->with([10]); - test('receives both datasets as cross product', function ($hookValue, $testValue) { - expect($hookValue)->toBe(10); - expect($testValue)->toBeIn([1, 2]); + test('receives both datasets as cross product', function ($hookValue, $testValue): void { + expect($hookValue)->toBe(10) + ->and($testValue)->toBeIn([1, 2]); })->with([1, 2]); }); -describe('describe()->with() combined with test->with()', function () { - test('receives both datasets', function ($describeValue, $testValue) { - expect($describeValue)->toBe(5); - expect($testValue)->toBeIn([50, 60]); +describe('describe()->with() combined with test->with()', function (): void { + test('receives both datasets', function ($describeValue, $testValue): void { + expect($describeValue)->toBe(5) + ->and($testValue)->toBeIn([50, 60]); })->with([50, 60]); })->with([5]); @@ -147,33 +147,33 @@ describe('describe()->with() combined with test->with()', function () { // beforeEach()->with() combined with beforeEach closure // --------------------------------------------------------------- -describe('beforeEach closure and beforeEach()->with() coexist', function () { - beforeEach(function () { +describe('beforeEach closure and beforeEach()->with() coexist', function (): void { + beforeEach(function (): void { $this->setupValue = 'initialized'; }); beforeEach()->with([99]); - test('has both the closure state and dataset', function ($value) { - expect($this->setupValue)->toBe('initialized'); - expect($value)->toBe(99); + test('has both the closure state and dataset', function ($value): void { + expect($this->setupValue)->toBe('initialized') + ->and($value)->toBe(99); }); }); -describe('beforeEach()->with() does not interfere with closure hooks', function () { - beforeEach(function () { +describe('beforeEach()->with() does not interfere with closure hooks', function (): void { + beforeEach(function (): void { $this->counter = 1; }); - beforeEach(function () { + beforeEach(function (): void { $this->counter++; }); beforeEach()->with([42]); - test('closures run in order and dataset is applied', function ($value) { - expect($this->counter)->toBe(2); - expect($value)->toBe(42); + test('closures run in order and dataset is applied', function ($value): void { + expect($this->counter)->toBe(2) + ->and($value)->toBe(42); }); }); @@ -181,24 +181,24 @@ describe('beforeEach()->with() does not interfere with closure hooks', function // Dataset isolation between describe blocks // --------------------------------------------------------------- -describe('first describe with dataset', function () { +describe('first describe with dataset', function (): void { beforeEach()->with([111]); - test('gets its own dataset', function ($value) { + test('gets its own dataset', function ($value): void { expect($value)->toBe(111); }); }); -describe('second describe with different dataset', function () { +describe('second describe with different dataset', function (): void { beforeEach()->with([222]); - test('gets its own dataset, not the sibling', function ($value) { + test('gets its own dataset, not the sibling', function ($value): void { expect($value)->toBe(222); }); }); -describe('third describe without dataset', function () { - test('has no dataset leaking from siblings', function () { +describe('third describe without dataset', function (): void { + test('has no dataset leaking from siblings', function (): void { expect(true)->toBeTrue(); }); }); @@ -207,23 +207,23 @@ describe('third describe without dataset', function () { // describe()->with() combined with beforeEach hooks // --------------------------------------------------------------- -describe('describe()->with() with beforeEach closure', function () { - beforeEach(function () { +describe('describe()->with() with beforeEach closure', function (): void { + beforeEach(function (): void { $this->hookRan = true; }); - test('both hook and dataset work', function ($value) { - expect($this->hookRan)->toBeTrue(); - expect($value)->toBe(77); + test('both hook and dataset work', function ($value): void { + expect($this->hookRan)->toBeTrue() + ->and($value)->toBe(77); }); })->with([77]); -describe('describe()->with() with afterEach closure', function () { - afterEach(function () { +describe('describe()->with() with afterEach closure', function (): void { + afterEach(function (): void { expect($this->value)->toBe(88); }); - test('dataset is available and afterEach runs', function ($value) { + test('dataset is available and afterEach runs', function ($value): void { $this->value = $value; expect($value)->toBe(88); }); @@ -233,18 +233,18 @@ describe('describe()->with() with afterEach closure', function () { // Multiple tests in a describe with beforeEach()->with() // --------------------------------------------------------------- -describe('multiple tests share the same beforeEach dataset', function () { +describe('multiple tests share the same beforeEach dataset', function (): void { beforeEach()->with([33]); - test('first test gets the dataset', function ($value) { + test('first test gets the dataset', function ($value): void { expect($value)->toBe(33); }); - test('second test also gets the dataset', function ($value) { + test('second test also gets the dataset', function ($value): void { expect($value)->toBe(33); }); - it('third test with it() also gets the dataset', function ($value) { + it('third test with it() also gets the dataset', function ($value): void { expect($value)->toBe(33); }); }); @@ -253,21 +253,21 @@ describe('multiple tests share the same beforeEach dataset', function () { // Nested describe with beforeEach()->with() at inner level // --------------------------------------------------------------- -describe('outer describe', function () { - beforeEach(function () { +describe('outer describe', function (): void { + beforeEach(function (): void { $this->outer = true; }); - describe('inner describe with dataset on hook', function () { + describe('inner describe with dataset on hook', function (): void { beforeEach()->with([55]); - test('inherits outer beforeEach and has inner dataset', function ($value) { - expect($this->outer)->toBeTrue(); - expect($value)->toBe(55); + test('inherits outer beforeEach and has inner dataset', function ($value): void { + expect($this->outer)->toBeTrue() + ->and($value)->toBe(55); }); }); - test('outer test is unaffected by inner dataset', function () { + test('outer test is unaffected by inner dataset', function (): void { expect($this->outer)->toBeTrue(); }); }); @@ -276,12 +276,12 @@ describe('outer describe', function () { // describe()->with() with depends // --------------------------------------------------------------- -describe('describe()->with() preserves depends', function () { - test('first', function ($value) { +describe('describe()->with() preserves depends', function (): void { + test('first', function ($value): void { expect($value)->toBe(9); }); - test('second', function ($value) { + test('second', function ($value): void { expect($value)->toBe(9); })->depends('first'); })->with([9]); diff --git a/tests/Features/DatasetProviderErrors.php b/tests/Features/DatasetProviderErrors.php index 95fabb7d..ea58ad33 100644 --- a/tests/Features/DatasetProviderErrors.php +++ b/tests/Features/DatasetProviderErrors.php @@ -6,7 +6,7 @@ $run = function (string $target): array { $process = new Process( ['php', 'bin/pest', $target], dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -17,33 +17,30 @@ $run = function (string $target): array { ]; }; -test('reports missing datasets as errors for a single file run', function () use ($run) { +test('reports missing datasets as errors for a single file run', function () use ($run): void { $result = $run('tests/.tests/IssueOnly.php'); expect($result['output']) ->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.") ->toContain('FAILED') - ->toContain('Tests: 1 failed'); - - expect($result['code'])->not->toBe(0); + ->toContain('Tests: 1 failed') + ->and($result['code'])->not->toBe(0); })->skipOnWindows(); -test('reports missing datasets as errors alongside passing tests', function () use ($run) { +test('reports missing datasets as errors alongside passing tests', function () use ($run): void { $result = $run('tests/.tests/IssueWithPassing.php'); expect($result['output']) ->toContain("A dataset with the name `missing` does not exist. You can create it using `dataset('missing', ['a', 'b']);`.") ->toContain('1 passed') - ->toContain('1 failed'); - - expect($result['code'])->not->toBe(0); + ->toContain('1 failed') + ->and($result['code'])->not->toBe(0); })->skipOnWindows(); -test('reports dataset closure exceptions as errors', function () use ($run) { +test('reports dataset closure exceptions as errors', function () use ($run): void { $result = $run('tests/.tests/DatasetClosureThrows.php'); expect($result['output']) - ->toContain('boom from dataset'); - - expect($result['code'])->not->toBe(0); + ->toContain('boom from dataset') + ->and($result['code'])->not->toBe(0); })->skipOnWindows(); diff --git a/tests/Features/DatasetsTests.php b/tests/Features/DatasetsTests.php index 99682015..dd3934b7 100644 --- a/tests/Features/DatasetsTests.php +++ b/tests/Features/DatasetsTests.php @@ -5,25 +5,25 @@ use Pest\Exceptions\DatasetDoesNotExist; use Pest\Plugin; use Pest\Repositories\DatasetsRepository; -beforeEach(function () { +beforeEach(function (): void { $this->foo = 'bar'; }); -it('throws exception if dataset does not exist', function () { +it('throws exception if dataset does not exist', function (): void { $this->expectException(DatasetDoesNotExist::class); $this->expectExceptionMessage("A dataset with the name `first` does not exist. You can create it using `dataset('first', ['a', 'b']);`."); DatasetsRepository::resolve(['first'], __FILE__); }); -it('throws exception if dataset already exist', function () { +it('throws exception if dataset already exist', function (): void { DatasetsRepository::set('second', [[]], __DIR__); $this->expectException(DatasetAlreadyExists::class); $this->expectExceptionMessage('A dataset with the name `second` already exists in scope ['.__DIR__.'].'); DatasetsRepository::set('second', [[]], __DIR__); }); -it('sets closures', function () { +it('sets closures', function (): void { DatasetsRepository::set('foo', function () { yield [1]; }, __DIR__); @@ -31,18 +31,18 @@ it('sets closures', function () { expect(DatasetsRepository::resolve(['foo'], __FILE__))->toBe(['(1)' => [1]]); }); -it('sets arrays', function () { +it('sets arrays', function (): void { DatasetsRepository::set('bar', [[2]], __DIR__); expect(DatasetsRepository::resolve(['bar'], __FILE__))->toBe(['(2)' => [2]]); }); -it('gets bound to test case object', function ($value) { +it('gets bound to test case object', function ($value): void { $this->assertTrue(true); })->with([['a'], ['b']]); -test('it truncates the description', function () { - expect(true)->toBe(true); +test('it truncates the description', function (): void { + expect(true)->toBeTrue(); // it gets tested by the integration test })->with([str_repeat('Fooo', 10)]); @@ -51,61 +51,59 @@ $state->text = ''; $datasets = [[1], [2]]; -test('lazy datasets', function ($text) use ($state, $datasets) { +test('lazy datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; - expect(in_array([$text], $datasets))->toBe(true); + expect([$text])->toBeIn($datasets); })->with($datasets); -test('lazy datasets did the job right', function () use ($state) { +test('lazy datasets did the job right', function () use ($state): void { expect($state->text)->toBe('12'); }); -test('interpolated :dataset lazy datasets', function ($text) { +test('interpolated :dataset lazy datasets', function ($text): void { expect(true)->toBeTrue(); })->with($datasets); $state->text = ''; -test('eager datasets', function ($text) use ($state, $datasets) { +test('eager datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; expect($datasets)->toContain([$text]); -})->with(function () use ($datasets) { - return $datasets; -}); +})->with(fn (): array => $datasets); -test('eager datasets did the job right', function () use ($state) { +test('eager datasets did the job right', function () use ($state): void { expect($state->text)->toBe('1212'); }); -test('lazy registered datasets', function ($text) use ($state, $datasets) { +test('lazy registered datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; expect($datasets)->toContain([$text]); })->with('numbers.array'); -test('lazy registered datasets did the job right', function () use ($state) { +test('lazy registered datasets did the job right', function () use ($state): void { expect($state->text)->toBe('121212'); }); -test('eager registered datasets', function ($text) use ($state, $datasets) { +test('eager registered datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; expect($datasets)->toContain([$text]); })->with('numbers.closure'); -test('eager registered datasets did the job right', function () use ($state) { +test('eager registered datasets did the job right', function () use ($state): void { expect($state->text)->toBe('12121212'); }); -test('eager wrapped registered datasets', function ($text) use ($state, $datasets) { +test('eager wrapped registered datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; expect($datasets)->toContain([$text]); })->with('numbers.closure.wrapped'); -test('eager registered wrapped datasets did the job right', function () use ($state) { +test('eager registered wrapped datasets did the job right', function () use ($state): void { expect($state->text)->toBe('1212121212'); }); -test('named datasets', function ($text) use ($state, $datasets) { +test('named datasets', function ($text) use ($state, $datasets): void { $state->text .= $text; expect($datasets)->toContain([$text]); })->with([ @@ -113,14 +111,14 @@ test('named datasets', function ($text) use ($state, $datasets) { 'two' => [2], ]); -test('interpolated :dataset named datasets', function ($text) { +test('interpolated :dataset named datasets', function ($text): void { expect(true)->toBeTrue(); })->with([ 'one' => [1], 'two' => [2], ]); -test('named datasets did the job right', function () use ($state) { +test('named datasets did the job right', function () use ($state): void { expect($state->text)->toBe('121212121212'); }); @@ -133,13 +131,13 @@ $namedDatasets = [ new Bar, ]; -test('lazy named datasets', function ($text) { +test('lazy named datasets', function ($text): void { expect(true)->toBeTrue(); })->with($namedDatasets); $counter = 0; -it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter) { +it('creates unique test case names', function (string $name, Plugin $plugin, bool $bool) use (&$counter): void { expect(true)->toBeTrue(); $counter++; })->with([ @@ -151,73 +149,69 @@ it('creates unique test case names', function (string $name, Plugin $plugin, boo ['Name 1', new Plugin, true], ]); -it('creates unique test case names - count', function () use (&$counter) { +it('creates unique test case names - count', function () use (&$counter): void { expect($counter)->toBe(6); }); $datasets_a = [[1], [2]]; $datasets_b = [[3], [4]]; -test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) { +test('lazy multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b): void { $state->text .= $text_a.$text_b; - expect($datasets_a)->toContain([$text_a]); - expect($datasets_b)->toContain([$text_b]); + expect($datasets_a)->toContain([$text_a]) + ->and($datasets_b)->toContain([$text_b]); })->with($datasets_a, $datasets_b); -test('lazy multiple datasets did the job right', function () use ($state) { +test('lazy multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('12121212121213142324'); }); $state->text = ''; -test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) { +test('eager multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b): void { $state->text .= $text_a.$text_b; - expect($datasets_a)->toContain([$text_a]); - expect($datasets_b)->toContain([$text_b]); -})->with(function () use ($datasets_a) { - return $datasets_a; -})->with(function () use ($datasets_b) { - return $datasets_b; -}); + expect($datasets_a)->toContain([$text_a]) + ->and($datasets_b)->toContain([$text_b]); +})->with(fn (): array => $datasets_a)->with(fn (): array => $datasets_b); -test('eager multiple datasets did the job right', function () use ($state) { +test('eager multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('1212121212121314232413142324'); }); -test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) { +test('lazy registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets): void { $state->text .= $text_a.$text_b; - expect($datasets)->toContain([$text_a]); - expect($datasets)->toContain([$text_b]); + expect($datasets)->toContain([$text_a]) + ->toContain([$text_b]); })->with('numbers.array')->with('numbers.array'); -test('lazy registered multiple datasets did the job right', function () use ($state) { +test('lazy registered multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('121212121212131423241314232411122122'); }); -test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) { +test('eager registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets): void { $state->text .= $text_a.$text_b; - expect($datasets)->toContain([$text_a]); - expect($datasets)->toContain([$text_b]); + expect($datasets)->toContain([$text_a]) + ->toContain([$text_b]); })->with('numbers.array')->with('numbers.closure'); -test('eager registered multiple datasets did the job right', function () use ($state) { +test('eager registered multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('12121212121213142324131423241112212211122122'); }); -test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets) { +test('eager wrapped registered multiple datasets', function ($text_a, $text_b) use ($state, $datasets): void { $state->text .= $text_a.$text_b; - expect($datasets)->toContain([$text_a]); - expect($datasets)->toContain([$text_b]); + expect($datasets)->toContain([$text_a]) + ->toContain([$text_b]); })->with('numbers.closure.wrapped')->with('numbers.closure'); -test('eager wrapped registered multiple datasets did the job right', function () use ($state) { +test('eager wrapped registered multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('1212121212121314232413142324111221221112212211122122'); }); -test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b) { +test('named multiple datasets', function ($text_a, $text_b) use ($state, $datasets_a, $datasets_b): void { $state->text .= $text_a.$text_b; - expect($datasets_a)->toContain([$text_a]); - expect($datasets_b)->toContain([$text_b]); + expect($datasets_a)->toContain([$text_a]) + ->and($datasets_b)->toContain([$text_b]); })->with([ 'one' => [1], 'two' => [2], @@ -226,18 +220,18 @@ test('named multiple datasets', function ($text_a, $text_b) use ($state, $datase 'four' => [4], ]); -test('named multiple datasets did the job right', function () use ($state) { +test('named multiple datasets did the job right', function () use ($state): void { expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324'); }); -test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state, $datasets_a, $datasets_b) { +test('more than two datasets', function ($text_a, $text_b, $text_c) use ($state, $datasets_a, $datasets_b): void { $state->text .= $text_a.$text_b.$text_c; - expect($datasets_a)->toContain([$text_a]); - expect($datasets_b)->toContain([$text_b]); - expect([5, 6])->toContain($text_c); + expect($datasets_a)->toContain([$text_a]) + ->and($datasets_b)->toContain([$text_b]) + ->and([5, 6])->toContain($text_c); })->with($datasets_a, $datasets_b)->with([5, 6]); -test('more than two datasets did the job right', function () use ($state) { +test('more than two datasets did the job right', function () use ($state): void { expect($state->text)->toBe('121212121212131423241314232411122122111221221112212213142324135136145146235236245246'); }); @@ -250,125 +244,97 @@ test( function (int $text) use ( $wrapped_generator_state, $wrapped_generator_function_datasets - ) { + ): void { $wrapped_generator_state->text .= $text; - expect(in_array($text, $wrapped_generator_function_datasets))->toBe(true); + expect($text)->toBeIn($wrapped_generator_function_datasets); } )->with('numbers.generators.wrapped'); -test('eager registered wrapped datasets with Generator functions did the job right', function () use ($wrapped_generator_state) { +test('eager registered wrapped datasets with Generator functions did the job right', function () use ($wrapped_generator_state): void { expect($wrapped_generator_state->text)->toBe('1234'); }); -test('eager registered wrapped datasets with Generator functions display description', function ($wrapped_generator_state_with_description) { +test('eager registered wrapped datasets with Generator functions display description', function ($wrapped_generator_state_with_description): void { expect($wrapped_generator_state_with_description)->not->toBeEmpty(); })->with(function () { yield 'taylor' => 'taylor@laravel.com'; yield 'james' => 'james@laravel.com'; }); -it('can resolve a dataset after the test case is available', function ($result) { +it('can resolve a dataset after the test case is available', function ($result): void { expect($result)->toBe('bar'); })->with([ - function () { - return $this->foo; - }, + fn () => $this->foo, [ - function () { - return $this->foo; - }, + fn () => $this->foo, ], ]); -it('can resolve a dataset after the test case is available with multiple datasets', function (string $result, string $result2) { +it('can resolve a dataset after the test case is available with multiple datasets', function (string $result, string $result2): void { expect($result)->toBe('bar'); })->with([ - function () { - return $this->foo; - }, + fn () => $this->foo, [ - function () { - return $this->foo; - }, + fn () => $this->foo, ], ], [ - function () { - return $this->foo; - }, + fn () => $this->foo, [ - function () { - return $this->foo; - }, + fn () => $this->foo, ], ]); -it('can resolve a dataset after the test case is available with shared yield sets', function ($result) { +it('can resolve a dataset after the test case is available with shared yield sets', function ($result): void { expect($result)->toBeInt()->toBeLessThan(3); })->with('bound.closure'); -it('can resolve a dataset after the test case is available with shared array sets', function ($result) { +it('can resolve a dataset after the test case is available with shared array sets', function ($result): void { expect($result)->toBeInt()->toBeLessThan(3); })->with('bound.array'); -it('resolves a potential bound dataset logically', function ($foo, $bar) { - expect($foo)->toBe('foo'); - expect($bar())->toBe('bar'); +it('resolves a potential bound dataset logically', function ($foo, $bar): void { + expect($foo)->toBe('foo') + ->and($bar())->toBe('bar'); })->with([ [ 'foo', - function () { - return 'bar'; - }, + fn (): string => 'bar', ], // This should be passed as a closure because we've passed multiple arguments ]); -it('resolves a potential bound dataset logically even when the closure comes first', function ($foo, $bar) { - expect($foo())->toBe('foo'); - expect($bar)->toBe('bar'); +it('resolves a potential bound dataset logically even when the closure comes first', function ($foo, $bar): void { + expect($foo())->toBe('foo') + ->and($bar)->toBe('bar'); })->with([ [ - function () { - return 'foo'; - }, 'bar', + fn (): string => 'foo', 'bar', ], // This should be passed as a closure because we've passed multiple arguments ]); -it('will not resolve a closure if it is type hinted as a closure', function (Closure $data) { +it('will not resolve a closure if it is type hinted as a closure', function (Closure $data): void { expect($data())->toBeString(); })->with([ - function () { - return 'foo'; - }, - function () { - return 'bar'; - }, + fn (): string => 'foo', + fn (): string => 'bar', ]); -it('will not resolve a closure if it is type hinted as a callable', function (callable $data) { +it('will not resolve a closure if it is type hinted as a callable', function (callable $data): void { expect($data())->toBeString(); })->with([ - function () { - return 'foo'; - }, - function () { - return 'bar'; - }, + fn (): string => 'foo', + fn (): string => 'bar', ]); -it('can correctly resolve a bound dataset that returns an array', function (array $data) { +it('can correctly resolve a bound dataset that returns an array', function (array $data): void { expect($data)->toBe(['foo', 'bar', 'baz']); })->with([ - function () { - return ['foo', 'bar', 'baz']; - }, + fn (): array => ['foo', 'bar', 'baz'], ]); -it('can correctly resolve a bound dataset that returns an array but wants to be spread', function (string $foo, string $bar, string $baz) { +it('can correctly resolve a bound dataset that returns an array but wants to be spread', function (string $foo, string $bar, string $baz): void { expect([$foo, $bar, $baz])->toBe(['foo', 'bar', 'baz']); })->with([ - function () { - return ['foo', 'bar', 'baz']; - }, + fn (): array => ['foo', 'bar', 'baz'], ]); todo('forbids to define tests in Datasets dirs and Datasets.php files'); @@ -393,57 +359,57 @@ it('may be used with high order even when bound') ->expect(fn (string $greeting) => $greeting) ->throws(InvalidArgumentException::class); -describe('with on nested describe', function () { - describe('nested', function () { - test('before inner describe block', function (...$args) { +describe('with on nested describe', function (): void { + describe('nested', function (): void { + test('before inner describe block', function (...$args): void { expect($args)->toBe([1]); }); - describe('describe', function () { - it('should include the with value from all parent describe blocks', function (...$args) { + describe('describe', function (): void { + it('should include the with value from all parent describe blocks', function (...$args): void { expect($args)->toBe([1, 2]); }); - test('should include the with value from all parent describe blocks and the test', function (...$args) { + test('should include the with value from all parent describe blocks and the test', function (...$args): void { expect($args)->toBe([1, 2, 3]); })->with([3]); })->with([2]); - test('after inner describe block', function (...$args) { + test('after inner describe block', function (...$args): void { expect($args)->toBe([1]); }); })->with([1]); }); -describe('matching describe block names', function () { - describe('outer', function () { - test('before inner describe block', function (...$args) { +describe('matching describe block names', function (): void { + describe('outer', function (): void { + test('before inner describe block', function (...$args): void { expect($args)->toBe([1]); }); - describe('inner', function () { - it('should include the with value from all parent describe blocks', function (...$args) { + describe('inner', function (): void { + it('should include the with value from all parent describe blocks', function (...$args): void { expect($args)->toBe([1, 2]); }); - test('should include the with value from all parent describe blocks and the test', function (...$args) { + test('should include the with value from all parent describe blocks and the test', function (...$args): void { expect($args)->toBe([1, 2, 3]); })->with([3]); })->with([2]); - describe('inner', function () { - it('should not include the value from the other describe block with the same name', function (...$args) { + describe('inner', function (): void { + it('should not include the value from the other describe block with the same name', function (...$args): void { expect($args)->toBe([1]); }); }); - test('after inner describe block', function (...$args) { + test('after inner describe block', function (...$args): void { expect($args)->toBe([1]); }); })->with([1]); }); -test('after describe block', function (...$args) { +test('after describe block', function (...$args): void { expect($args)->toBe([5]); })->with([5]); @@ -454,64 +420,58 @@ it('may be used with high order after describe block') dataset('after-describe', ['after']); -test('after describe block with named dataset', function (...$args) { +test('after describe block with named dataset', function (...$args): void { expect($args)->toBe(['after']); })->with('after-describe'); -test('named parameters match by parameter name', function (string $email, string $name) { - expect($name)->toBe('Taylor'); - expect($email)->toBe('taylor@laravel.com'); +test('named parameters match by parameter name', function (string $email, string $name): void { + expect($name)->toBe('Taylor') + ->and($email)->toBe('taylor@laravel.com'); })->with([ ['name' => 'Taylor', 'email' => 'taylor@laravel.com'], ]); -test('named parameters work with multiple dataset items', function (string $email, string $name) { - expect($name)->toBeString(); - expect($email)->toContain('@'); +test('named parameters work with multiple dataset items', function (string $email, string $name): void { + expect($name)->toBeString() + ->and($email)->toContain('@'); })->with([ ['name' => 'Taylor', 'email' => 'taylor@laravel.com'], ['name' => 'James', 'email' => 'james@laravel.com'], ]); -test('named parameters work in different order than closure params', function (string $third, string $first, string $second) { - expect($first)->toBe('a'); - expect($second)->toBe('b'); - expect($third)->toBe('c'); +test('named parameters work in different order than closure params', function (string $third, string $first, string $second): void { + expect($first)->toBe('a') + ->and($second)->toBe('b') + ->and($third)->toBe('c'); })->with([ ['first' => 'a', 'second' => 'b', 'third' => 'c'], ]); -test('named parameters work with named dataset keys', function (string $email, string $name) { - expect($name)->toBeString(); - expect($email)->toContain('@'); +test('named parameters work with named dataset keys', function (string $email, string $name): void { + expect($name)->toBeString() + ->and($email)->toContain('@'); })->with([ 'taylor' => ['name' => 'Taylor', 'email' => 'taylor@laravel.com'], 'james' => ['name' => 'James', 'email' => 'james@laravel.com'], ]); -test('named parameters work with closures that should be resolved', function (string $email, string $name) { - expect($name)->toBe('bar'); - expect($email)->toBe('bar@example.com'); +test('named parameters work with closures that should be resolved', function (string $email, string $name): void { + expect($name)->toBe('bar') + ->and($email)->toBe('bar@example.com'); })->with([ [ - 'name' => function () { - return $this->foo; - }, - 'email' => function () { - return $this->foo.'@example.com'; - }, + 'name' => fn () => $this->foo, + 'email' => fn (): string => $this->foo.'@example.com', ], ]); -test('named parameters work with closure type hints', function (Closure $callback, string $name) { - expect($name)->toBe('Taylor'); - expect($callback())->toBe('resolved'); +test('named parameters work with closure type hints', function (Closure $callback, string $name): void { + expect($name)->toBe('Taylor') + ->and($callback())->toBe('resolved'); })->with([ [ 'name' => 'Taylor', - 'callback' => function () { - return 'resolved'; - }, + 'callback' => fn (): string => 'resolved', ], ]); @@ -520,23 +480,21 @@ dataset('named-params-dataset', [ ['name' => 'James', 'email' => 'james@laravel.com'], ]); -test('named parameters work with registered datasets', function (string $email, string $name) { - expect($name)->toBeString(); - expect($email)->toContain('@'); +test('named parameters work with registered datasets', function (string $email, string $name): void { + expect($name)->toBeString() + ->and($email)->toContain('@'); })->with('named-params-dataset'); -test('named parameters work with bound closure returning associative array', function (string $email, string $name) { - expect($name)->toBe('bar'); - expect($email)->toBe('test@example.com'); +test('named parameters work with bound closure returning associative array', function (string $email, string $name): void { + expect($name)->toBe('bar') + ->and($email)->toBe('test@example.com'); })->with([ - function () { - return ['name' => $this->foo, 'email' => 'test@example.com']; - }, + fn (): array => ['name' => $this->foo, 'email' => 'test@example.com'], ]); -test('dataset items can mix named and sequential styles', function (string $name, string $email) { - expect($name)->toBeString(); - expect($email)->toContain('@'); +test('dataset items can mix named and sequential styles', function (string $name, string $email): void { + expect($name)->toBeString() + ->and($email)->toContain('@'); })->with([ ['name' => 'Taylor', 'email' => 'taylor@laravel.com'], ['James', 'james@laravel.com'], diff --git a/tests/Features/Depends.php b/tests/Features/Depends.php index 82f45c05..0fbe91f5 100644 --- a/tests/Features/Depends.php +++ b/tests/Features/Depends.php @@ -2,34 +2,34 @@ $runCounter = 0; -test('first', function () use (&$runCounter) { +test('first', function () use (&$runCounter): string { expect(true)->toBeTrue(); $runCounter++; return 'first'; }); -test('second', function () use (&$runCounter) { +test('second', function () use (&$runCounter): string { expect(true)->toBeTrue(); $runCounter++; return 'second'; }); -test('depends', function () { +test('depends', function (): void { expect(func_get_args())->toBe(['first', 'second']); })->depends('first', 'second'); -test('depends with ...params', function (string ...$params) { +test('depends with ...params', function (string ...$params): void { expect(func_get_args())->toBe($params); })->depends('first', 'second'); -test('depends with defined arguments', function (string $first, string $second) { - expect($first)->toBe('first'); - expect($second)->toBe('second'); +test('depends with defined arguments', function (string $first, string $second): void { + expect($first)->toBe('first') + ->and($second)->toBe('second'); })->depends('first', 'second'); -test('depends run test only once', function () use (&$runCounter) { +test('depends run test only once', function () use (&$runCounter): void { expect($runCounter)->toBe(2); })->depends('first', 'second'); @@ -37,42 +37,42 @@ test('depends run test only once', function () use (&$runCounter) { it('asserts true is true')->assertTrue(true); test('depends works with the correct test name')->assertTrue(true)->depends('it asserts true is true'); -describe('describe block', function () { +describe('describe block', function (): void { $runCounter = 0; - test('first in describe', function () use (&$runCounter) { + test('first in describe', function () use (&$runCounter): void { $runCounter++; expect(true)->toBeTrue(); }); - test('second in describe', function () use (&$runCounter) { + test('second in describe', function () use (&$runCounter): void { expect($runCounter)->toBe(1); $runCounter++; })->depends('first in describe'); - test('third in describe', function () use (&$runCounter) { + test('third in describe', function () use (&$runCounter): void { expect($runCounter)->toBe(2); })->depends('second in describe'); - describe('nested describe', function () { + describe('nested describe', function (): void { $runCounter = 0; - test('first in nested describe', function () use (&$runCounter) { + test('first in nested describe', function () use (&$runCounter): void { $runCounter++; expect(true)->toBeTrue(); }); - test('second in nested describe', function () use (&$runCounter) { + test('second in nested describe', function () use (&$runCounter): void { expect($runCounter)->toBe(1); $runCounter++; })->depends('first in nested describe'); - test('third in nested describe', function () use (&$runCounter) { + test('third in nested describe', function () use (&$runCounter): void { expect($runCounter)->toBe(2); })->depends('second in nested describe'); }); }); -test('depends on test after describe block', function () use (&$runCounter) { +test('depends on test after describe block', function () use (&$runCounter): void { expect($runCounter)->toBe(2); })->depends('first', 'second'); diff --git a/tests/Features/DependsInheritance.php b/tests/Features/DependsInheritance.php index fd55b7f7..040a62f3 100644 --- a/tests/Features/DependsInheritance.php +++ b/tests/Features/DependsInheritance.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; class InheritanceTest extends TestCase { - public function foo() + public function foo(): string { return 'bar'; } @@ -12,11 +12,11 @@ class InheritanceTest extends TestCase pest()->extend(InheritanceTest::class); -it('is a test', function () { +it('is a test', function (): void { expect(true)->toBeTrue(); }); -it('uses correct parent class', function () { - expect(get_parent_class($this))->toEqual(InheritanceTest::class); - expect($this->foo())->toEqual('bar'); +it('uses correct parent class', function (): void { + expect(get_parent_class($this))->toEqual(InheritanceTest::class) + ->and($this->foo())->toEqual('bar'); })->depends('it is a test'); diff --git a/tests/Features/Deprecated.php b/tests/Features/Deprecated.php index 02ae11f8..f2f197ed 100644 --- a/tests/Features/Deprecated.php +++ b/tests/Features/Deprecated.php @@ -1,12 +1,14 @@ toBeTrue(); }); -test('user deprecated', function () { +test('user deprecated', function (): void { trigger_error('Since foo 1.0: This is a deprecation description', \E_USER_DEPRECATED); expect(true)->toBeTrue(); diff --git a/tests/Features/Describe.php b/tests/Features/Describe.php index 836b0fc8..f3fc130d 100644 --- a/tests/Features/Describe.php +++ b/tests/Features/Describe.php @@ -2,58 +2,58 @@ beforeEach(fn () => $this->count = 1); -test('before each', function () { +test('before each', function (): void { expect($this->count)->toBe(1); }); -describe('hooks', function () { - beforeEach(function () { +describe('hooks', function (): void { + beforeEach(function (): void { $this->count++; }); - test('value', function () { + test('value', function (): void { expect($this->count)->toBe(2); $this->count++; }); - afterEach(function () { + afterEach(function (): void { expect($this->count)->toBe(3); }); }); -describe('hooks in different orders', function () { - beforeEach(function () { +describe('hooks in different orders', function (): void { + beforeEach(function (): void { $this->count++; }); - test('value', function () { + test('value', function (): void { expect($this->count)->toBe(3); $this->count++; }); - afterEach(function () { + afterEach(function (): void { expect($this->count)->toBe(4); }); - beforeEach(function () { + beforeEach(function (): void { $this->count++; }); }); test('todo')->todo()->shouldNotRun(); -test('previous describable before each does not get applied here', function () { +test('previous describable before each does not get applied here', function (): void { expect($this->count)->toBe(1); }); -describe('todo on hook', function () { +describe('todo on hook', function (): void { beforeEach()->todo(); test('should not fail')->shouldNotRun(); test('should run')->expect(true)->toBeTrue(); }); -describe('todo on describe', function () { +describe('todo on describe', function (): void { test('should not fail')->shouldNotRun(); test('should run')->expect(true)->toBeTrue(); @@ -63,48 +63,48 @@ test('should run')->expect(true)->toBeTrue(); test('with', fn ($foo) => expect($foo)->toBe(1))->with([1]); -describe('with on hook', function () { +describe('with on hook', function (): void { beforeEach()->with([2]); - test('value', function ($foo) { + test('value', function ($foo): void { expect($foo)->toBe(2); }); }); -describe('with on describe', function () { - test('value', function ($foo) { +describe('with on describe', function (): void { + test('value', function ($foo): void { expect($foo)->toBe(3); }); })->with([3]); -describe('depends on describe', function () { - test('foo', function () { +describe('depends on describe', function (): void { + test('foo', function (): void { expect('foo')->toBe('foo'); }); - test('bar', function () { + test('bar', function (): void { expect('bar')->toBe('bar'); })->depends('foo'); }); -describe('depends on describe using with', function () { - test('foo', function ($foo) { +describe('depends on describe using with', function (): void { + test('foo', function ($foo): void { expect($foo)->toBe(3); }); - test('bar', function ($foo) { + test('bar', function ($foo): void { expect($foo + $foo)->toBe(6); })->depends('foo'); })->with([3]); -describe('with test after describe', function () { - beforeEach(function () { +describe('with test after describe', function (): void { + beforeEach(function (): void { $this->count++; }); - describe('foo', function () {}); + describe('foo', function (): void {}); - it('should run the before each', function () { + it('should run the before each', function (): void { expect($this->count)->toBe(2); }); }); diff --git a/tests/Features/DescriptionLess.php b/tests/Features/DescriptionLess.php index 0bc28720..99afb446 100644 --- a/tests/Features/DescriptionLess.php +++ b/tests/Features/DescriptionLess.php @@ -30,7 +30,7 @@ get('foo'); // not incomplete because closure is created... get('foo')->get('bar')->expect(true)->toBeTrue(); get('foo')->expect(true)->toBeTrue(); -describe('a "describe" group of tests', function () { +describe('a "describe" group of tests', function (): void { get('foo'); // not incomplete because closure is created... get('foo')->get('bar')->expect(true)->toBeTrue(); get('foo')->expect(true)->toBeTrue(); diff --git a/tests/Features/Done.php b/tests/Features/Done.php index bee3450d..1c148cd6 100644 --- a/tests/Features/Done.php +++ b/tests/Features/Done.php @@ -1,17 +1,19 @@ toBeTrue(); })->done(assignee: 'nunomaduro'); -it('may have an associated issue', function () { +it('may have an associated issue', function (): void { expect(true)->toBeTrue(); })->done(issue: 1); -it('may have an associated PR', function () { +it('may have an associated PR', function (): void { expect(true)->toBeTrue(); })->done(pr: 1); -it('may have an associated note', function () { +it('may have an associated note', function (): void { expect(true)->toBeTrue(); })->done(note: 'a note'); diff --git a/tests/Features/Exceptions.php b/tests/Features/Exceptions.php index 97a2d664..ec5ca430 100644 --- a/tests/Features/Exceptions.php +++ b/tests/Features/Exceptions.php @@ -1,95 +1,91 @@ expectException(InvalidArgumentException::class); throw new InvalidArgumentException; }); -it('catch exceptions', function () { +it('catch exceptions', function (): void { throw new Exception('Something bad happened'); })->throws(Exception::class); -it('catch exceptions and messages', function () { +it('catch exceptions and messages', function (): void { throw new Exception('Something bad happened'); })->throws(Exception::class, 'Something bad happened'); -it('catch exceptions, messages and code', function () { +it('catch exceptions, messages and code', function (): void { throw new Exception('Something bad happened', 1); })->throws(Exception::class, 'Something bad happened', 1); -it('can just define the message', function () { +it('can just define the message', function (): void { throw new Exception('Something bad happened'); })->throws('Something bad happened'); -it('can just define the code', function () { +it('can just define the code', function (): void { throw new Exception('Something bad happened', 1); })->throws(1); -it('not catch exceptions if given condition is false', function () { +it('not catch exceptions if given condition is false', function (): void { $this->assertTrue(true); })->throwsIf(false, Exception::class); -it('catch exceptions if given condition is true', function () { +it('catch exceptions if given condition is true', function (): void { throw new Exception('Something bad happened'); -})->throwsIf(function () { - return true; -}, Exception::class); +})->throwsIf(fn (): true => true, Exception::class); -it('catch exceptions and messages if given condition is true', function () { +it('catch exceptions and messages if given condition is true', function (): void { throw new Exception('Something bad happened'); })->throwsIf(true, Exception::class, 'Something bad happened'); -it('catch exceptions, messages and code if given condition is true', function () { +it('catch exceptions, messages and code if given condition is true', function (): void { throw new Exception('Something bad happened', 1); })->throwsIf(true, Exception::class, 'Something bad happened', 1); -it('can just define the message if given condition is true', function () { +it('can just define the message if given condition is true', function (): void { throw new Exception('Something bad happened'); })->throwsIf(true, 'Something bad happened'); -it('can just define the code if given condition is true', function () { +it('can just define the code if given condition is true', function (): void { throw new Exception('Something bad happened', 1); })->throwsIf(true, 1); -it('can just define the message if given condition is 1', function () { +it('can just define the message if given condition is 1', function (): void { throw new Exception('Something bad happened'); })->throwsIf(1, 'Something bad happened'); -it('can just define the code if given condition is 1', function () { +it('can just define the code if given condition is 1', function (): void { throw new Exception('Something bad happened', 1); })->throwsIf(1, 1); -it('not catch exceptions if given condition is true', function () { +it('not catch exceptions if given condition is true', function (): void { $this->assertTrue(true); })->throwsUnless(true, Exception::class); -it('catch exceptions if given condition is false', function () { +it('catch exceptions if given condition is false', function (): void { throw new Exception('Something bad happened'); -})->throwsUnless(function () { - return false; -}, Exception::class); +})->throwsUnless(fn (): false => false, Exception::class); -it('catch exceptions and messages if given condition is false', function () { +it('catch exceptions and messages if given condition is false', function (): void { throw new Exception('Something bad happened'); })->throwsUnless(false, Exception::class, 'Something bad happened'); -it('catch exceptions, messages and code if given condition is false', function () { +it('catch exceptions, messages and code if given condition is false', function (): void { throw new Exception('Something bad happened', 1); })->throwsUnless(false, Exception::class, 'Something bad happened', 1); -it('can just define the message if given condition is false', function () { +it('can just define the message if given condition is false', function (): void { throw new Exception('Something bad happened'); })->throwsUnless(false, 'Something bad happened'); -it('can just define the code if given condition is false', function () { +it('can just define the code if given condition is false', function (): void { throw new Exception('Something bad happened', 1); })->throwsUnless(false, 1); -it('can just define the message if given condition is 0', function () { +it('can just define the message if given condition is 0', function (): void { throw new Exception('Something bad happened'); })->throwsUnless(0, 'Something bad happened'); -it('can just define the code if given condition is 0', function () { +it('can just define the code if given condition is 0', function (): void { throw new Exception('Something bad happened', 1); })->throwsUnless(0, 1); diff --git a/tests/Features/Expect/HigherOrder/methods.php b/tests/Features/Expect/HigherOrder/methods.php index 5e693ea9..fa7caa72 100644 --- a/tests/Features/Expect/HigherOrder/methods.php +++ b/tests/Features/Expect/HigherOrder/methods.php @@ -1,73 +1,72 @@ name()->toBeString()->toEqual('Has Methods'); }); -it('can access multiple methods', function () { +it('can access multiple methods', function (): void { expect(new HasMethods) ->name()->toBeString()->toEqual('Has Methods') ->quantity()->toBeInt()->toEqual(20); }); -it('works with not', function () { +it('works with not', function (): void { expect(new HasMethods) ->name()->not->toEqual('world')->toEqual('Has Methods') ->quantity()->toEqual(20)->not()->toEqual('bar')->not->toBeNull; }); -it('can accept arguments', function () { +it('can accept arguments', function (): void { expect(new HasMethods) ->multiply(5, 4)->toBeInt->toEqual(20); }); -it('works with each', function () { +it('works with each', function (): void { expect(new HasMethods) ->attributes()->toBeArray->each->not()->toBeNull - ->attributes()->each(function ($attribute) { + ->attributes()->each(function ($attribute): void { $attribute->not->toBeNull(); }); }); -it('works inside of each', function () { +it('works inside of each', function (): void { expect(new HasMethods) - ->books()->each(function ($book) { + ->books()->each(function ($book): void { $book->title->not->toBeNull->cost->toBeGreaterThan(19); }); }); -it('works with sequence', function () { +it('works with sequence', function (): void { expect(new HasMethods) ->books()->sequence( - function ($book) { + function ($book): void { $book->title->toEqual('Foo')->cost->toEqual(20); }, - function ($book) { + function ($book): void { $book->title->toEqual('Bar')->cost->toEqual(30); }, ); }); -it('can compose complex expectations', function () { +it('can compose complex expectations', function (): void { expect(new HasMethods) - ->toBeObject() ->name()->toEqual('Has Methods')->not()->toEqual('bar') ->quantity()->not->toEqual('world')->toEqual(20)->toBeInt ->multiply(3, 4)->not->toBeString->toEqual(12) ->attributes()->toBeArray() ->books()->toBeArray->each->not->toBeEmpty ->books()->sequence( - function ($book) { + function ($book): void { $book->title->toEqual('Foo')->cost->toEqual(20); }, - function ($book) { + function ($book): void { $book->title->toEqual('Bar')->cost->toEqual(30); }, ); }); -it('can handle nested method calls', function () { +it('can handle nested method calls', function (): void { expect(new HasMethods) ->newInstance()->newInstance()->name()->toEqual('Has Methods')->toBeString() ->newInstance()->name()->toEqual('Has Methods')->not->toBeInt @@ -82,7 +81,7 @@ it('works with higher order tests') ->name()->toEqual('Has Methods') ->books()->each->toBeArray; -it('can use the scoped method to lock into the given level for expectations', function () { +it('can use the scoped method to lock into the given level for expectations', function (): void { expect(new HasMethods) ->attributes()->scoped(fn ($attributes) => $attributes ->name->toBe('Has Methods') @@ -99,7 +98,7 @@ it('can use the scoped method to lock into the given level for expectations', fu ); }); -it('works consistently with the json expectation method', function () { +it('works consistently with the json expectation method', function (): void { expect(new HasMethods) ->jsonString()->json()->id->toBe(1) ->jsonString()->json()->name->toBe('Has Methods')->toBeString() @@ -113,22 +112,22 @@ class HasMethods return '{ "id": 1, "name": "Has Methods", "quantity": 20 }'; } - public function name() + public function name(): string { return 'Has Methods'; } - public function quantity() + public function quantity(): int { return 20; } - public function multiply($x, $y) + public function multiply($x, $y): int|float { return $x * $y; } - public function attributes() + public function attributes(): array { return [ 'name' => $this->name(), @@ -136,7 +135,7 @@ class HasMethods ]; } - public function books() + public function books(): array { return [ [ @@ -150,7 +149,7 @@ class HasMethods ]; } - public function newInstance() + public function newInstance(): static { return new static; } diff --git a/tests/Features/Expect/HigherOrder/methodsAndProperties.php b/tests/Features/Expect/HigherOrder/methodsAndProperties.php index 0babb360..fd6234f8 100644 --- a/tests/Features/Expect/HigherOrder/methodsAndProperties.php +++ b/tests/Features/Expect/HigherOrder/methodsAndProperties.php @@ -1,24 +1,24 @@ name->toEqual('Has Methods and Properties')->not()->toEqual('bar') ->multiply(3, 4)->not->toBeString->toEqual(12) - ->posts->each(function ($post) { + ->posts->each(function ($post): void { $post->is_published->toBeTrue; })->books()->toBeArray() ->posts->toBeArray->each->not->toBeEmpty ->books()->sequence( - function ($book) { + function ($book): void { $book->title->toEqual('Foo')->cost->toEqual(20); }, - function ($book) { + function ($book): void { $book->title->toEqual('Bar')->cost->toEqual(30); }, ); }); -it('can handle nested methods and properties', function () { +it('can handle nested methods and properties', function (): void { expect(new HasMethodsAndProperties) ->meta->foo->bar->toBeString()->toEqual('baz')->not->toBeInt ->newInstance()->meta->foo->toBeArray() @@ -33,15 +33,14 @@ it('works with higher order tests') ->newInstance()->multiply(2, 2)->toEqual(4)->not->toEqual(5) ->newInstance()->books()->toBeArray(); -it('can start a new higher order expectation using the and syntax', function () { +it('can start a new higher order expectation using the and syntax', function (): void { expect(new HasMethodsAndProperties) ->toBeInstanceOf(HasMethodsAndProperties::class) ->meta->toBeArray ->and(['foo' => 'bar']) ->toBeArray() - ->foo->toEqual('bar'); - - expect(static::getCount())->toEqual(4); + ->foo->toEqual('bar') + ->and(static::getCount())->toEqual(4); }); it('can start a new higher order expectation using the and syntax in higher order tests') @@ -52,12 +51,12 @@ it('can start a new higher order expectation using the and syntax in higher orde ->toBeArray() ->foo->toEqual('bar'); -it('can start a new higher order expectation using the and syntax without nesting expectations', function () { +it('can start a new higher order expectation using the and syntax without nesting expectations', function (): void { expect(new HasMethodsAndProperties) ->toBeInstanceOf(HasMethodsAndProperties::class) ->meta ->sequence( - function ($value, $key) { + function ($value, $key): void { $value->toBeArray()->and($key)->toBe('foo'); }, ); @@ -80,7 +79,7 @@ class HasMethodsAndProperties ], ]; - public function books() + public function books(): array { return [ [ @@ -94,12 +93,12 @@ class HasMethodsAndProperties ]; } - public function multiply($x, $y) + public function multiply($x, $y): int|float { return $x * $y; } - public function newInstance() + public function newInstance(): static { return new static; } diff --git a/tests/Features/Expect/HigherOrder/properties.php b/tests/Features/Expect/HigherOrder/properties.php index a8b6674e..d9749701 100644 --- a/tests/Features/Expect/HigherOrder/properties.php +++ b/tests/Features/Expect/HigherOrder/properties.php @@ -1,50 +1,50 @@ 1])->foo->toBeInt()->toEqual(1); }); -it('can access multiple properties from the value', function () { +it('can access multiple properties from the value', function (): void { expect(['foo' => 'bar', 'hello' => 'world']) ->foo->toBeString()->toEqual('bar') ->hello->toBeString()->toEqual('world'); }); -it('works with not', function () { +it('works with not', function (): void { expect(['foo' => 'bar', 'hello' => 'world']) ->foo->not->not->toEqual('bar') ->foo->not->toEqual('world')->toEqual('bar') ->hello->toEqual('world')->not()->toEqual('bar')->not->toBeNull; }); -it('works with each', function () { +it('works with each', function (): void { expect(['numbers' => [1, 2, 3, 4], 'words' => ['hey', 'there']]) ->numbers->toEqual([1, 2, 3, 4])->each->toBeInt->toBeLessThan(5) - ->words->each(function ($word) { + ->words->each(function ($word): void { $word->toBeString()->not->toBeInt(); }); }); -it('works inside of each', function () { +it('works inside of each', function (): void { expect(['books' => [['title' => 'Foo', 'cost' => 20], ['title' => 'Bar', 'cost' => 30]]]) - ->books->each(function ($book) { + ->books->each(function ($book): void { $book->title->not->toBeNull->cost->toBeGreaterThan(19); }); }); -it('works with sequence', function () { +it('works with sequence', function (): void { expect(['books' => [['title' => 'Foo', 'cost' => 20], ['title' => 'Bar', 'cost' => 30]]]) ->books->sequence( - function ($book) { + function ($book): void { $book->title->toEqual('Foo')->cost->toEqual(20); }, - function ($book) { + function ($book): void { $book->title->toEqual('Bar')->cost->toEqual(30); }, ); }); -it('can compose complex expectations', function () { +it('can compose complex expectations', function (): void { expect(['foo' => 'bar', 'numbers' => [1, 2, 3, 4]]) ->toContain('bar')->toBeArray() ->numbers->toEqual([1, 2, 3, 4])->not()->toEqual('bar')->each->toBeInt @@ -52,23 +52,23 @@ it('can compose complex expectations', function () { ->numbers->toBeArray(); }); -it('works with objects', function () { +it('works with objects', function (): void { expect(new HasProperties) ->name->toEqual('foo')->not->toEqual('world') - ->posts->toHaveCount(2)->each(function ($post) { + ->posts->toHaveCount(2)->each(function ($post): void { $post->is_published->toBeTrue(); }) ->posts->sequence( - function ($post) { + function ($post): void { $post->title->toEqual('Foo'); }, - function ($post) { + function ($post): void { $post->title->toEqual('Bar'); }, ); }); -it('works with nested properties', function () { +it('works with nested properties', function (): void { expect(new HasProperties) ->nested->foo->bar->toBeString()->toEqual('baz') ->posts->toBeArray()->toHaveCount(2); diff --git a/tests/Features/Expect/each.php b/tests/Features/Expect/each.php index 63b3d60c..6b94b54b 100644 --- a/tests/Features/Expect/each.php +++ b/tests/Features/Expect/each.php @@ -2,16 +2,15 @@ use Pest\Expectation; -test('an exception is thrown if the the type is not iterable', function () { +test('an exception is thrown if the the type is not iterable', function (): void { expect('Foobar')->each()->toEqual('Foobar'); })->throws(BadMethodCallException::class, 'Expectation value is not iterable.'); -it('expects on each item', function () { +it('expects on each item', function (): void { expect([1, 1, 1]) ->each() - ->toEqual(1); - - expect(static::getCount())->toBe(3); // + 1 assertion + ->toEqual(1) + ->and(static::getCount())->toBe(3); // + 1 assertion expect([1, 1, 1]) ->each @@ -20,13 +19,12 @@ it('expects on each item', function () { expect(static::getCount())->toBe(7); }); -it('chains expectations on each item', function () { +it('chains expectations on each item', function (): void { expect([1, 1, 1]) ->each() ->toBeInt() - ->toEqual(1); - - expect(static::getCount())->toBe(6); // + 1 assertion + ->toEqual(1) + ->and(static::getCount())->toBe(6); // + 1 assertion expect([2, 2, 2]) ->each @@ -36,13 +34,12 @@ it('chains expectations on each item', function () { expect(static::getCount())->toBe(13); }); -test('opposite expectations on each item', function () { +test('opposite expectations on each item', function (): void { expect([1, 2, 3]) ->each() ->not() - ->toEqual(4); - - expect(static::getCount())->toBe(3); + ->toEqual(4) + ->and(static::getCount())->toBe(3); expect([1, 2, 3]) ->each() @@ -51,17 +48,16 @@ test('opposite expectations on each item', function () { expect(static::getCount())->toBe(7); }); -test('chained opposite and non-opposite expectations', function () { +test('chained opposite and non-opposite expectations', function (): void { expect([1, 2, 3]) ->each() ->not() ->toEqual(4) - ->toBeInt(); - - expect(static::getCount())->toBe(6); + ->toBeInt() + ->and(static::getCount())->toBe(6); }); -it('can add expectations via "and"', function () { +it('can add expectations via "and"', function (): void { expect([1, 2, 3]) ->each() ->toBeInt // + 3 @@ -78,20 +74,18 @@ it('can add expectations via "and"', function () { expect(static::getCount())->toBe(14); }); -it('accepts callables', function () { - expect([1, 2, 3])->each(function ($number) { - expect($number)->toBeInstanceOf(Expectation::class); - expect($number->value)->toBeInt(); +it('accepts callables', function (): void { + expect([1, 2, 3])->each(function ($number): void { + expect($number)->toBeInstanceOf(Expectation::class) + ->and($number->value)->toBeInt(); $number->toBeInt->not->toBeString; - }); - - expect(static::getCount())->toBe(12); + }) + ->and(static::getCount())->toBe(12); }); -it('passes the key of the current item to callables', function () { - expect([1, 2, 3])->each(function ($number, $key) { +it('passes the key of the current item to callables', function (): void { + expect([1, 2, 3])->each(function ($number, $key): void { expect($key)->toBeInt(); - }); - - expect(static::getCount())->toBe(3); + }) + ->and(static::getCount())->toBe(3); }); diff --git a/tests/Features/Expect/extend.php b/tests/Features/Expect/extend.php index 4be88241..7892e0f9 100644 --- a/tests/Features/Expect/extend.php +++ b/tests/Features/Expect/extend.php @@ -1,29 +1,29 @@ extend('toBeAMacroExpectation', function () { +expect()->extend('toBeAMacroExpectation', function (): object { $this->toBeTrue(); return $this; }); -expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value) { +expect()->extend('toBeAMacroExpectationWithArguments', function (bool $value): object { $this->toBe($value); return $this; }); -it('macros true is true', function () { +it('macros true is true', function (): void { expect(true)->toBeAMacroExpectation(); }); -it('macros false is not true', function () { +it('macros false is not true', function (): void { expect(false)->not->toBeAMacroExpectation(); }); -it('macros true is true with argument', function () { +it('macros true is true with argument', function (): void { expect(true)->toBeAMacroExpectationWithArguments(true); }); -it('macros false is not true with argument', function () { +it('macros false is not true with argument', function (): void { expect(false)->not->toBeAMacroExpectationWithArguments(true); }); diff --git a/tests/Features/Expect/json.php b/tests/Features/Expect/json.php index 2228fd56..e199871c 100644 --- a/tests/Features/Expect/json.php +++ b/tests/Features/Expect/json.php @@ -2,13 +2,13 @@ use PHPUnit\Framework\ExpectationFailedException; -test('it properly parses json string', function () { +test('it properly parses json string', function (): void { expect('{"name":"Nuno"}') ->json() ->name ->toBe('Nuno'); }); -test('fails with broken json string', function () { +test('fails with broken json string', function (): void { expect('{":"Nuno"}')->json(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/matchExpectation.php b/tests/Features/Expect/matchExpectation.php index 7328cdb9..0be393b6 100644 --- a/tests/Features/Expect/matchExpectation.php +++ b/tests/Features/Expect/matchExpectation.php @@ -2,11 +2,11 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->matched = null; }); -it('pass', function () { +it('pass', function (): void { expect('baz') ->match('foo', [ 'bar' => function ($value) { @@ -21,25 +21,20 @@ it('pass', function () { }, ] ) - ->toEqual($this->matched); - - expect(static::getCount())->toBe(2); + ->toEqual($this->matched) + ->and(static::getCount())->toBe(2); }); -it('failures', function () { +it('failures', function (): void { expect(true) ->match('foo', [ - 'bar' => function ($value) { - return $value->toBeTrue(); - }, - 'foo' => function ($value) { - return $value->toBeFalse(); - }, + 'bar' => fn ($value) => $value->toBeTrue(), + 'foo' => fn ($value) => $value->toBeFalse(), ] ); })->throws(ExpectationFailedException::class, 'true is false'); -it('runs with truthy', function () { +it('runs with truthy', function (): void { expect('foo') ->match(1, [ 'bar' => function ($value) { @@ -54,12 +49,11 @@ it('runs with truthy', function () { }, ] ) - ->toEqual($this->matched); - - expect(static::getCount())->toBe(2); + ->toEqual($this->matched) + ->and(static::getCount())->toBe(2); }); -it('runs with falsy', function () { +it('runs with falsy', function (): void { expect('foo') ->match(false, [ 'bar' => function ($value) { @@ -74,17 +68,14 @@ it('runs with falsy', function () { }, ] ) - ->toEqual($this->matched); - - expect(static::getCount())->toBe(2); + ->toEqual($this->matched) + ->and(static::getCount())->toBe(2); }); -it('runs with truthy closure condition', function () { +it('runs with truthy closure condition', function (): void { expect('foo') ->match( - function () { - return '1'; - }, [ + fn (): string => '1', [ 'bar' => function ($value) { $this->matched = 'bar'; @@ -97,17 +88,14 @@ it('runs with truthy closure condition', function () { }, ] ) - ->toEqual($this->matched); - - expect(static::getCount())->toBe(2); + ->toEqual($this->matched) + ->and(static::getCount())->toBe(2); }); -it('runs with falsy closure condition', function () { +it('runs with falsy closure condition', function (): void { expect('foo') ->match( - function () { - return '0'; - }, [ + fn (): string => '0', [ 'bar' => function ($value) { $this->matched = 'bar'; @@ -120,12 +108,11 @@ it('runs with falsy closure condition', function () { }, ] ) - ->toEqual($this->matched); - - expect(static::getCount())->toBe(2); + ->toEqual($this->matched) + ->and(static::getCount())->toBe(2); }); -it('can be passed non-callable values', function () { +it('can be passed non-callable values', function (): void { expect('foo') ->match('pest', [ 'bar' => 'foo', @@ -134,21 +121,15 @@ it('can be passed non-callable values', function () { ); })->throws(ExpectationFailedException::class, 'two strings are equal'); -it('fails with unhandled match', function () { +it('fails with unhandled match', function (): void { expect('foo')->match('bar', []); })->throws(ExpectationFailedException::class, 'Unhandled match value.'); it('can be used in higher order tests') ->expect(true) ->match( - function () { - return true; - }, [ - false => function ($value) { - return $value->toBeFalse(); - }, - true => function ($value) { - return $value->toBeTrue(); - }, + fn (): true => true, [ + false => fn ($value) => $value->toBeFalse(), + true => fn ($value) => $value->toBeTrue(), ] ); diff --git a/tests/Features/Expect/not.php b/tests/Features/Expect/not.php index 79220b19..749af399 100644 --- a/tests/Features/Expect/not.php +++ b/tests/Features/Expect/not.php @@ -1,6 +1,6 @@ toBeTrue() ->not()->toBeFalse() diff --git a/tests/Features/Expect/pipes.php b/tests/Features/Expect/pipes.php index 13640304..cc5fb5bc 100644 --- a/tests/Features/Expect/pipes.php +++ b/tests/Features/Expect/pipes.php @@ -61,7 +61,7 @@ $state = new State; /* * Overrides toBe to assert two Characters are the same */ -expect()->pipe('toBe', function ($next, $expected) use ($state) { +expect()->pipe('toBe', function ($next, $expected) use ($state): void { $state->runCount['char']++; if ($this->value instanceof Char) { @@ -81,7 +81,7 @@ expect()->pipe('toBe', function ($next, $expected) use ($state) { /* * Overrides toBe to assert two Number objects are the same */ -expect()->intercept('toBe', Number::class, function ($expected) use ($state) { +expect()->intercept('toBe', Number::class, function ($expected) use ($state): void { $state->runCount['number']++; $state->appliedCount['number']++; @@ -92,7 +92,7 @@ expect()->intercept('toBe', Number::class, function ($expected) use ($state) { /* * Overrides toBe to assert all integers are allowed if value is a wildcard (*) */ -expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numeric($expected), function ($expected) use ($state) { +expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numeric($expected), function ($expected) use ($state): void { $state->runCount['wildcard']++; $state->appliedCount['wildcard']++; }); @@ -100,7 +100,7 @@ expect()->intercept('toBe', fn ($value, $expected) => $value === '*' && is_numer /* * Overrides toBe to assert to Symbols are the same */ -expect()->pipe('toBe', function ($next, $expected) use ($state) { +expect()->pipe('toBe', function ($next, $expected) use ($state): void { $state->runCount['symbol']++; if ($this->value instanceof Symbol) { @@ -117,7 +117,7 @@ expect()->pipe('toBe', function ($next, $expected) use ($state) { /* * Overrides toBe to allow ignoring case when checking strings */ -expect()->intercept('toBe', fn ($value) => is_string($value), function ($expected, $ignoreCase = false) { +expect()->intercept('toBe', fn ($value) => is_string($value), function ($expected, $ignoreCase = false): void { if ($ignoreCase) { assertEqualsIgnoringCase($expected, $this->value); } else { @@ -125,7 +125,7 @@ expect()->intercept('toBe', fn ($value) => is_string($value), function ($expecte } }); -test('pipe is applied and can stop pipeline', function () use ($state) { +test('pipe is applied and can stop pipeline', function () use ($state): void { $char = new Char('A'); $state->reset(); @@ -146,7 +146,7 @@ test('pipe is applied and can stop pipeline', function () use ($state) { ]); }); -test('pipe is run and can let the pipeline keep going', function () use ($state) { +test('pipe is run and can let the pipeline keep going', function () use ($state): void { $state->reset(); expect(3)->toBe(3) @@ -165,7 +165,7 @@ test('pipe is run and can let the pipeline keep going', function () use ($state) ]); }); -test('pipe works with negated expectation', function () use ($state) { +test('pipe works with negated expectation', function () use ($state): void { $char = new Char('A'); $state->reset(); @@ -186,7 +186,7 @@ test('pipe works with negated expectation', function () use ($state) { ]); }); -test('interceptor is applied', function () use ($state) { +test('interceptor is applied', function () use ($state): void { $number = new Number(1); $state->reset(); @@ -197,7 +197,7 @@ test('interceptor is applied', function () use ($state) { ->appliedCount->toHaveKey('number', 1); }); -test('interceptor stops the pipeline', function () use ($state) { +test('interceptor stops the pipeline', function () use ($state): void { $number = new Number(1); $state->reset(); @@ -218,7 +218,7 @@ test('interceptor stops the pipeline', function () use ($state) { ]); }); -test('interceptor is called only when filter is met', function () use ($state) { +test('interceptor is called only when filter is met', function () use ($state): void { $state->reset(); expect(1)->toBe(1) @@ -227,7 +227,7 @@ test('interceptor is called only when filter is met', function () use ($state) { ->appliedCount->toHaveKey('number', 0); }); -test('interceptor can be filtered with a closure', function () use ($state) { +test('interceptor can be filtered with a closure', function () use ($state): void { $state->reset(); expect('*')->toBe(1) @@ -236,7 +236,7 @@ test('interceptor can be filtered with a closure', function () use ($state) { ->appliedCount->toHaveKey('wildcard', 1); }); -test('interceptor can be filter the expected parameter as well', function () use ($state) { +test('interceptor can be filter the expected parameter as well', function () use ($state): void { $state->reset(); expect('*')->toBe('*') @@ -245,13 +245,13 @@ test('interceptor can be filter the expected parameter as well', function () use ->appliedCount->toHaveKey('wildcard', 0); }); -test('interceptor works with negated expectation', function () { +test('interceptor works with negated expectation', function (): void { $char = new Number(1); expect($char)->not->toBe(new Char('B')); }); -test('intercept can add new parameters to the expectation', function () { +test('intercept can add new parameters to the expectation', function (): void { $ignoreCase = true; expect('Foo')->toBe('foo', $ignoreCase); diff --git a/tests/Features/Expect/ray.php b/tests/Features/Expect/ray.php index 9831a1f7..149b9f4c 100644 --- a/tests/Features/Expect/ray.php +++ b/tests/Features/Expect/ray.php @@ -1,5 +1,7 @@ ray()->toBe(true); +declare(strict_types=1); + +test('ray calls do not fail when ray is not installed', function (): void { + expect(true)->toBeTrue(); }); diff --git a/tests/Features/Expect/sequence.php b/tests/Features/Expect/sequence.php index 2c19e206..b9391df6 100644 --- a/tests/Features/Expect/sequence.php +++ b/tests/Features/Expect/sequence.php @@ -1,95 +1,91 @@ each->sequence(); })->throws(BadMethodCallException::class, 'Expectation value is not iterable.'); -test('an exception is thrown if there are no expectations', function () { +test('an exception is thrown if there are no expectations', function (): void { expect(['Foobar'])->sequence(); })->throws(InvalidArgumentException::class, 'No sequence expectations defined.'); -test('allows for sequences of checks to be run on iterable data', function () { +test('allows for sequences of checks to be run on iterable data', function (): void { expect([1, 2, 3]) ->sequence( - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(1); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(2); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(3); }, - ); - - expect(static::getCount())->toBe(6); + ) + ->and(static::getCount())->toBe(6); }); -test('loops back to the start if it runs out of sequence items', function () { +test('loops back to the start if it runs out of sequence items', function (): void { expect([1, 2, 3, 1, 2, 3, 1, 2]) ->sequence( - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(1); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(2); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(3); }, - ); - - expect(static::getCount())->toBe(16); + ) + ->and(static::getCount())->toBe(16); }); -test('fails if the number of iterable items is less than the number of expectations', function () { +test('fails if the number of iterable items is less than the number of expectations', function (): void { expect([1, 2]) ->sequence( - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(1); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(2); }, - function ($expectation) { + function ($expectation): void { $expectation->toBeInt()->toEqual(3); }, ); })->throws(OutOfRangeException::class, 'Sequence expectations are more than the iterable items.'); -test('it works with associative arrays', function () { +test('it works with associative arrays', function (): void { expect(['foo' => 'bar', 'baz' => 'boom']) ->sequence( - function ($expectation, $key) { + function ($expectation, $key): void { $expectation->toEqual('bar'); $key->toEqual('foo'); }, - function ($expectation, $key) { + function ($expectation, $key): void { $expectation->toEqual('boom'); $key->toEqual('baz'); }, ); }); -test('it can be passed non-callable values', function () { - expect(['foo', 'bar', 'baz'])->sequence('foo', 'bar', 'baz'); - - expect(static::getCount())->toBe(3); +test('it can be passed non-callable values', function (): void { + expect(['foo', 'bar', 'baz'])->sequence('foo', 'bar', 'baz') + ->and(static::getCount())->toBe(3); }); -test('it can be passed a mixture of value types', function () { +test('it can be passed a mixture of value types', function (): void { expect(['foo', 'bar', 'baz'])->sequence( 'foo', - function ($expectation) { + function ($expectation): void { $expectation->toEqual('bar')->toBeString(); }, 'baz' - ); - - expect(static::getCount())->toBe(4); + ) + ->and(static::getCount())->toBe(4); }); -test('it works with traversables', function () { +test('it works with traversables', function (): void { $generator = (function () { yield 'one' => (fn () => yield from [1, 2, 3])(); yield 'two' => (fn () => yield from [4, 5, 6])(); diff --git a/tests/Features/Expect/toBe.php b/tests/Features/Expect/toBe.php index ebb0f42b..eeb40f58 100644 --- a/tests/Features/Expect/toBe.php +++ b/tests/Features/Expect/toBe.php @@ -4,21 +4,21 @@ use PHPUnit\Framework\ExpectationFailedException; expect(true)->toBeTrue()->and(false)->toBeFalse(); -test('strict comparisons', function () { +test('strict comparisons', function (): void { $nuno = new stdClass; $dries = new stdClass; expect($nuno)->toBe($nuno)->not->toBe($dries); }); -test('failures', function () { +test('failures', function (): void { expect(1)->toBe(2); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(1)->toBe(2, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(1)->not->toBe(1); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeAlpha.php b/tests/Features/Expect/toBeAlpha.php index 659c2de1..9e76d554 100644 --- a/tests/Features/Expect/toBeAlpha.php +++ b/tests/Features/Expect/toBeAlpha.php @@ -1,20 +1,22 @@ toBeAlpha(); - expect('123')->not->toBeAlpha(); +test('pass', function (): void { + expect('abc')->toBeAlpha() + ->and('123')->not->toBeAlpha(); }); -test('failures', function () { +test('failures', function (): void { expect('123')->toBeAlpha(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('123')->toBeAlpha('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('abc')->not->toBeAlpha(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeAlphaNumeric.php b/tests/Features/Expect/toBeAlphaNumeric.php index 5f4670e8..90f5cb03 100644 --- a/tests/Features/Expect/toBeAlphaNumeric.php +++ b/tests/Features/Expect/toBeAlphaNumeric.php @@ -1,20 +1,22 @@ toBeAlphaNumeric(); - expect('-')->not->toBeAlphaNumeric(); +test('pass', function (): void { + expect('abc123')->toBeAlphaNumeric() + ->and('-')->not->toBeAlphaNumeric(); }); -test('failures', function () { +test('failures', function (): void { expect('-')->toBeAlphaNumeric(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('-')->toBeAlphaNumeric('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('abc123')->not->toBeAlphaNumeric(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeArray.php b/tests/Features/Expect/toBeArray.php index 04d8f4be..88f37885 100644 --- a/tests/Features/Expect/toBeArray.php +++ b/tests/Features/Expect/toBeArray.php @@ -1,20 +1,22 @@ toBeArray(); - expect('1, 2, 3')->not->toBeArray(); +test('pass', function (): void { + expect([1, 2, 3])->toBeArray() + ->and('1, 2, 3')->not->toBeArray(); }); -test('failures', function () { - expect(null)->toBeArray(); +test('failures', function (): void { + expect()->toBeArray(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeArray('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeArray('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(['a', 'b', 'c'])->not->toBeArray(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeBetween.php b/tests/Features/Expect/toBeBetween.php index d71526cb..6be2ffe9 100644 --- a/tests/Features/Expect/toBeBetween.php +++ b/tests/Features/Expect/toBeBetween.php @@ -1,43 +1,45 @@ toBeBetween(1, 3); }); -test('passes with float', function () { +test('passes with float', function (): void { expect(1.5)->toBeBetween(1.25, 1.75); }); -test('passes with float and int', function () { +test('passes with float and int', function (): void { expect(1.5)->toBeBetween(1, 2); }); -test('passes with DateTime', function () { +test('passes with DateTime', function (): void { expect(new DateTime('2023-09-22'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23')); }); -test('failure with int', function () { +test('failure with int', function (): void { expect(4)->toBeBetween(1, 3); })->throws(ExpectationFailedException::class); -test('failure with float', function () { +test('failure with float', function (): void { expect(2)->toBeBetween(1.5, 1.75); })->throws(ExpectationFailedException::class); -test('failure with float and int', function () { +test('failure with float and int', function (): void { expect(2.1)->toBeBetween(1, 2); })->throws(ExpectationFailedException::class); -test('failure with DateTime', function () { +test('failure with DateTime', function (): void { expect(new DateTime('2023-09-20'))->toBeBetween(new DateTime('2023-09-21'), new DateTime('2023-09-23')); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(4)->toBeBetween(1, 3, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(2)->not->toBeBetween(1, 3); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeBool.php b/tests/Features/Expect/toBeBool.php index 10e74c37..5036de47 100644 --- a/tests/Features/Expect/toBeBool.php +++ b/tests/Features/Expect/toBeBool.php @@ -1,20 +1,22 @@ toBeBool(); - expect(0)->not->toBeBool(); +test('pass', function (): void { + expect(true)->toBeBool() + ->and(0)->not->toBeBool(); }); -test('failures', function () { - expect(null)->toBeBool(); +test('failures', function (): void { + expect()->toBeBool(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeBool('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeBool('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(false)->not->toBeBool(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeCallable.php b/tests/Features/Expect/toBeCallable.php index 384a0c75..ca543e48 100644 --- a/tests/Features/Expect/toBeCallable.php +++ b/tests/Features/Expect/toBeCallable.php @@ -1,26 +1,26 @@ toBeCallable(); - expect(null)->not->toBeCallable(); +test('pass', function (): void { + expect(function (): void {})->toBeCallable() + ->and(null)->not->toBeCallable(); }); -test('failures', function () { +test('failures', function (): void { $hello = 5; expect($hello)->toBeCallable(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { $hello = 5; expect($hello)->toBeCallable('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(function () { - return 42; - })->not->toBeCallable(); +test('not failures', function (): void { + expect(fn (): int => 42)->not->toBeCallable(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeCamelCase.php b/tests/Features/Expect/toBeCamelCase.php index d2b38433..5221f4b8 100644 --- a/tests/Features/Expect/toBeCamelCase.php +++ b/tests/Features/Expect/toBeCamelCase.php @@ -1,23 +1,24 @@ toBeCamelCase(); - expect('abcDef')->toBeCamelCase(); - expect('abc-def')->not->toBeCamelCase(); - expect('abc-def')->not->toBeCamelCase(); - expect('AbcDef')->not->toBeCamelCase(); +test('pass', function (): void { + expect('abc')->toBeCamelCase() + ->and('abcDef')->toBeCamelCase() + ->and('abc-def')->not->toBeCamelCase()->not->toBeCamelCase() + ->and('AbcDef')->not->toBeCamelCase(); }); -test('failures', function () { +test('failures', function (): void { expect('Abc')->toBeCamelCase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('Abc')->toBeCamelCase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('abcDef')->not->toBeCamelCase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeDigits.php b/tests/Features/Expect/toBeDigits.php index 7b8d6d98..13acea0c 100644 --- a/tests/Features/Expect/toBeDigits.php +++ b/tests/Features/Expect/toBeDigits.php @@ -1,20 +1,22 @@ toBeDigits(); - expect('123.14')->not->toBeDigits(); +test('pass', function (): void { + expect('123')->toBeDigits() + ->and('123.14')->not->toBeDigits(); }); -test('failures', function () { +test('failures', function (): void { expect('123.14')->toBeDigits(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('123.14')->toBeDigits('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('445')->not->toBeDigits(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeDirectory.php b/tests/Features/Expect/toBeDirectory.php index faa09c5e..f7045215 100644 --- a/tests/Features/Expect/toBeDirectory.php +++ b/tests/Features/Expect/toBeDirectory.php @@ -1,21 +1,23 @@ toBeDirectory(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever')->toBeDirectory(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever')->toBeDirectory('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('.')->not->toBeDirectory(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeEmail.php b/tests/Features/Expect/toBeEmail.php index fc9edff7..0c55d5d1 100644 --- a/tests/Features/Expect/toBeEmail.php +++ b/tests/Features/Expect/toBeEmail.php @@ -1,24 +1,26 @@ toBeEmail() ->and('notanemail')->not->toBeEmail(); }); -test('failures', function () { +test('failures', function (): void { expect('notanemail')->toBeEmail(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('notanemail')->toBeEmail('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with default message', function () { +test('failures with default message', function (): void { expect('notanemail')->toBeEmail(); })->throws(ExpectationFailedException::class, 'Failed asserting that notanemail is an email address.'); -test('not failures', function () { +test('not failures', function (): void { expect('user@example.com')->not->toBeEmail(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeEmpty.php b/tests/Features/Expect/toBeEmpty.php index 2b0270eb..720f6534 100644 --- a/tests/Features/Expect/toBeEmpty.php +++ b/tests/Features/Expect/toBeEmpty.php @@ -1,23 +1,25 @@ toBeEmpty(); - expect(null)->toBeEmpty(); +test('pass', function (): void { + expect([])->toBeEmpty() + ->and(null)->toBeEmpty(); }); -test('failures', function () { - expect([1, 2])->toBeEmpty(); - expect(' ')->toBeEmpty(); +test('failures', function (): void { + expect([1, 2])->toBeEmpty() + ->and(' ')->toBeEmpty(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect([1, 2])->toBeEmpty('oh no!'); - expect(' ')->toBeEmpty('oh no!'); +test('failures with custom message', function (): void { + expect([1, 2])->toBeEmpty('oh no!') + ->and(' ')->toBeEmpty('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect([])->not->toBeEmpty(); - expect(null)->not->toBeEmpty(); +test('not failures', function (): void { + expect([])->not->toBeEmpty() + ->and(null)->not->toBeEmpty(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeFalse.php b/tests/Features/Expect/toBeFalse.php index 396413ce..9e32f74a 100644 --- a/tests/Features/Expect/toBeFalse.php +++ b/tests/Features/Expect/toBeFalse.php @@ -1,19 +1,21 @@ toBeFalse(); }); -test('failures', function () { +test('failures', function (): void { expect('')->toBeFalse(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('')->toBeFalse('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(false)->not->toBe(false); +test('not failures', function (): void { + expect(false)->toBeTrue(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeFalsy.php b/tests/Features/Expect/toBeFalsy.php index a48a16a4..8edb17e0 100644 --- a/tests/Features/Expect/toBeFalsy.php +++ b/tests/Features/Expect/toBeFalsy.php @@ -1,23 +1,25 @@ toBeFalsy(); })->with([false, '', null, 0, '0']); -test('passes as not falsy', function ($value) { +test('passes as not falsy', function ($value): void { expect($value)->not->toBeFalsy(); })->with([true, [1], 'false', 1, -1]); -test('failures', function () { +test('failures', function (): void { expect(1)->toBeFalsy(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(1)->toBeFalsy('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(null)->not->toBeFalsy(); +test('not failures', function (): void { + expect()->not->toBeFalsy(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeFile.php b/tests/Features/Expect/toBeFile.php index 72e17445..b74f9fbf 100644 --- a/tests/Features/Expect/toBeFile.php +++ b/tests/Features/Expect/toBeFile.php @@ -2,26 +2,26 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { touch($this->tempFile = sys_get_temp_dir().'/fake.file'); }); -afterEach(function () { +afterEach(function (): void { unlink($this->tempFile); }); -test('pass', function () { +test('pass', function (): void { expect($this->tempFile)->toBeFile(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever.file')->toBeFile(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever.file')->toBeFile('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->tempFile)->not->toBeFile(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeFloat.php b/tests/Features/Expect/toBeFloat.php index a1d47175..86d122c8 100644 --- a/tests/Features/Expect/toBeFloat.php +++ b/tests/Features/Expect/toBeFloat.php @@ -1,20 +1,22 @@ toBeFloat(); - expect(1)->not->toBeFloat(); +test('pass', function (): void { + expect(1.0)->toBeFloat() + ->and(1)->not->toBeFloat(); }); -test('failures', function () { +test('failures', function (): void { expect(42)->toBeFloat(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(42)->toBeFloat('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(log(3))->not->toBeFloat(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeGreaterThan.php b/tests/Features/Expect/toBeGreaterThan.php index 6c3e8cb4..d47780f4 100644 --- a/tests/Features/Expect/toBeGreaterThan.php +++ b/tests/Features/Expect/toBeGreaterThan.php @@ -2,33 +2,32 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { - expect(42)->toBeGreaterThan(41); - expect(4)->toBeGreaterThan(3.9); +test('passes', function (): void { + expect(42)->toBeGreaterThan(41) + ->and(4)->toBeGreaterThan(3.9); }); -test('passes with DateTime and DateTimeImmutable', function () { +test('passes with DateTime and DateTimeImmutable', function (): void { $now = new DateTime; $past = (new DateTimeImmutable)->modify('-1 day'); - expect($now)->toBeGreaterThan($past); - - expect($past)->not->toBeGreaterThan($now); + expect($now)->toBeGreaterThan($past) + ->and($past)->not->toBeGreaterThan($now); }); -test('passes with strings', function () { - expect('b')->toBeGreaterThan('a'); - expect('a')->not->toBeGreaterThan('a'); +test('passes with strings', function (): void { + expect('b')->toBeGreaterThan('a') + ->and('a')->not->toBeGreaterThan('a'); }); -test('failures', function () { +test('failures', function (): void { expect(4)->toBeGreaterThan(4); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(4)->toBeGreaterThan(4, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(5)->not->toBeGreaterThan(4); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeGreaterThanOrEqual.php b/tests/Features/Expect/toBeGreaterThanOrEqual.php index 9db7e351..e160fccf 100644 --- a/tests/Features/Expect/toBeGreaterThanOrEqual.php +++ b/tests/Features/Expect/toBeGreaterThanOrEqual.php @@ -2,35 +2,33 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { - expect(42)->toBeGreaterThanOrEqual(41); - expect(4)->toBeGreaterThanOrEqual(4); +test('passes', function (): void { + expect(42)->toBeGreaterThanOrEqual(41) + ->and(4)->toBeGreaterThanOrEqual(4); }); -test('passes with DateTime and DateTimeImmutable', function () { +test('passes with DateTime and DateTimeImmutable', function (): void { $now = new DateTime; $past = (new DateTimeImmutable)->modify('-1 day'); - expect($now)->toBeGreaterThanOrEqual($now); - - expect($now)->toBeGreaterThanOrEqual($past); - - expect($past)->not->toBeGreaterThanOrEqual($now); + expect($now)->toBeGreaterThanOrEqual($now) + ->toBeGreaterThanOrEqual($past) + ->and($past)->not->toBeGreaterThanOrEqual($now); }); -test('passes with strings', function () { - expect('b')->toBeGreaterThanOrEqual('a'); - expect('a')->toBeGreaterThanOrEqual('a'); +test('passes with strings', function (): void { + expect('b')->toBeGreaterThanOrEqual('a') + ->and('a')->toBeGreaterThanOrEqual('a'); }); -test('failures', function () { +test('failures', function (): void { expect(4)->toBeGreaterThanOrEqual(4.1); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(4)->toBeGreaterThanOrEqual(4.1, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(5)->not->toBeGreaterThanOrEqual(5); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeIn.php b/tests/Features/Expect/toBeIn.php index c6ec8188..791abf42 100644 --- a/tests/Features/Expect/toBeIn.php +++ b/tests/Features/Expect/toBeIn.php @@ -1,20 +1,22 @@ toBeIn(['a', 'b', 'c']); - expect('d')->not->toBeIn(['a', 'b', 'c']); +test('passes', function (): void { + expect('a')->toBeIn(['a', 'b', 'c']) + ->and('d')->not->toBeIn(['a', 'b', 'c']); }); -test('failures', function () { +test('failures', function (): void { expect('d')->toBeIn(['a', 'b', 'c']); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('d')->toBeIn(['a', 'b', 'c'], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('a')->not->toBeIn(['a', 'b', 'c']); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeInfinite.php b/tests/Features/Expect/toBeInfinite.php index 9a6dc646..6d30946d 100644 --- a/tests/Features/Expect/toBeInfinite.php +++ b/tests/Features/Expect/toBeInfinite.php @@ -1,20 +1,22 @@ toBeInfinite(); - expect(log(1))->not->toBeInfinite(); +test('pass', function (): void { + expect(log(0))->toBeInfinite() + ->and(log(1))->not->toBeInfinite(); }); -test('failures', function () { +test('failures', function (): void { expect(asin(2))->toBeInfinite(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(asin(2))->toBeInfinite('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(INF)->not->toBeInfinite(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeInstanceOf.php b/tests/Features/Expect/toBeInstanceOf.php index 186129f1..7e30d868 100644 --- a/tests/Features/Expect/toBeInstanceOf.php +++ b/tests/Features/Expect/toBeInstanceOf.php @@ -1,20 +1,21 @@ toBeInstanceOf(Exception::class); - expect(new Exception)->not->toBeInstanceOf(RuntimeException::class); +test('pass', function (): void { + expect(new Exception)->toBeInstanceOf(Exception::class)->not->toBeInstanceOf(RuntimeException::class); }); -test('failures', function () { +test('failures', function (): void { expect(new Exception)->toBeInstanceOf(RuntimeException::class); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(new Exception)->toBeInstanceOf(RuntimeException::class, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(new Exception)->not->toBeInstanceOf(Exception::class); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeInt.php b/tests/Features/Expect/toBeInt.php index 148688d6..e02ba0e4 100644 --- a/tests/Features/Expect/toBeInt.php +++ b/tests/Features/Expect/toBeInt.php @@ -1,20 +1,22 @@ toBeInt(); - expect(42.0)->not->toBeInt(); +test('pass', function (): void { + expect(42)->toBeInt() + ->and(42.0)->not->toBeInt(); }); -test('failures', function () { +test('failures', function (): void { expect(42.0)->toBeInt(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(42.0)->toBeInt('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(6 * 7)->not->toBeInt(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeInvokable.php b/tests/Features/Expect/toBeInvokable.php index c36567f7..72e4ecb0 100644 --- a/tests/Features/Expect/toBeInvokable.php +++ b/tests/Features/Expect/toBeInvokable.php @@ -1,29 +1,33 @@ expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass') + ->expect(InvokableClass::class) ->toBeInvokable(); test('opposite class is invokable') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClass') + ->expect(InvokableClass::class) ->not->toBeInvokable(); test('class is invokable via a parent class') - ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaParent') + ->expect(InvokableClassViaParent::class) ->toBeInvokable(); test('class is invokable via a trait') - ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsInvokable\\InvokableClassViaTrait') + ->expect(InvokableClassViaTrait::class) ->toBeInvokable(); test('failure when the class is not invokable') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass') + ->expect(IsNotInvokableClass::class) ->toBeInvokable(); test('class is not invokable') - ->expect('Tests\\Fixtures\\Arch\\ToBeInvokable\\IsNotInvokable\\IsNotInvokableClass') + ->expect(IsNotInvokableClass::class) ->not->toBeInvokable(); diff --git a/tests/Features/Expect/toBeIterable.php b/tests/Features/Expect/toBeIterable.php index db3ceda9..8403b0da 100644 --- a/tests/Features/Expect/toBeIterable.php +++ b/tests/Features/Expect/toBeIterable.php @@ -1,21 +1,23 @@ toBeIterable(); - expect(null)->not->toBeIterable(); +test('pass', function (): void { + expect([])->toBeIterable() + ->and(null)->not->toBeIterable(); }); -test('failures', function () { +test('failures', function (): void { expect(42)->toBeIterable(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(42)->toBeIterable('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { function gen(): iterable { yield 1; diff --git a/tests/Features/Expect/toBeJson.php b/tests/Features/Expect/toBeJson.php index 503b7755..d91e40f2 100644 --- a/tests/Features/Expect/toBeJson.php +++ b/tests/Features/Expect/toBeJson.php @@ -1,21 +1,23 @@ toBeJson(); - expect('foo')->not->toBeJson(); - expect('{"hello"')->not->toBeJson(); +test('pass', function (): void { + expect('{"hello":"world"}')->toBeJson() + ->and('foo')->not->toBeJson() + ->and('{"hello"')->not->toBeJson(); }); -test('failures', function () { +test('failures', function (): void { expect(':"world"}')->toBeJson(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(':"world"}')->toBeJson('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('{"hello":"world"}')->not->toBeJson(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeKebabCase.php b/tests/Features/Expect/toBeKebabCase.php index 1ca54ddc..89d18d34 100644 --- a/tests/Features/Expect/toBeKebabCase.php +++ b/tests/Features/Expect/toBeKebabCase.php @@ -1,23 +1,25 @@ toBeKebabCase(); - expect('abc-def')->toBeKebabCase(); - expect('abc_def')->not->toBeKebabCase(); - expect('abcDef')->not->toBeKebabCase(); - expect('AbcDef')->not->toBeKebabCase(); +test('pass', function (): void { + expect('abc')->toBeKebabCase() + ->and('abc-def')->toBeKebabCase() + ->and('abc_def')->not->toBeKebabCase() + ->and('abcDef')->not->toBeKebabCase() + ->and('AbcDef')->not->toBeKebabCase(); }); -test('failures', function () { +test('failures', function (): void { expect('Abc')->toBeKebabCase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('Abc')->toBeKebabCase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('abc-def')->not->toBeKebabCase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeLessThan.php b/tests/Features/Expect/toBeLessThan.php index ca798c37..df55c8d0 100644 --- a/tests/Features/Expect/toBeLessThan.php +++ b/tests/Features/Expect/toBeLessThan.php @@ -2,33 +2,31 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { - expect(41)->toBeLessThan(42); - expect(4)->toBeLessThan(5); +test('passes', function (): void { + expect(41)->toBeLessThan(42) + ->and(4)->toBeLessThan(5); }); -test('passes with DateTime and DateTimeImmutable', function () { +test('passes with DateTime and DateTimeImmutable', function (): void { $now = new DateTime; $past = (new DateTimeImmutable)->modify('-1 day'); - expect($past)->toBeLessThan($now); - - expect($now)->not->toBeLessThan($now); + expect($past)->toBeLessThan($now) + ->and($now)->not->toBeLessThan($now); }); -test('passes with strings', function () { - expect('a')->toBeLessThan('b'); - expect('a')->not->toBeLessThan('a'); +test('passes with strings', function (): void { + expect('a')->toBeLessThan('b')->not->toBeLessThan('a'); }); -test('failures', function () { +test('failures', function (): void { expect(4)->toBeLessThan(4); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(4)->toBeLessThan(4, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(5)->not->toBeLessThan(6); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeLessThanOrEqual.php b/tests/Features/Expect/toBeLessThanOrEqual.php index 3fe90189..ef688d9a 100644 --- a/tests/Features/Expect/toBeLessThanOrEqual.php +++ b/tests/Features/Expect/toBeLessThanOrEqual.php @@ -2,35 +2,33 @@ use PHPUnit\Framework\ExpectationFailedException; -test('passes', function () { - expect(41)->toBeLessThanOrEqual(42); - expect(4)->toBeLessThanOrEqual(4); +test('passes', function (): void { + expect(41)->toBeLessThanOrEqual(42) + ->and(4)->toBeLessThanOrEqual(4); }); -test('passes with DateTime and DateTimeImmutable', function () { +test('passes with DateTime and DateTimeImmutable', function (): void { $now = new DateTime; $past = (new DateTimeImmutable)->modify('-1 day'); - expect($now)->toBeLessThanOrEqual($now); - - expect($past)->toBeLessThanOrEqual($now); - - expect($now)->not->toBeLessThanOrEqual($past); + expect($now)->toBeLessThanOrEqual($now) + ->and($past)->toBeLessThanOrEqual($now) + ->and($now)->not->toBeLessThanOrEqual($past); }); -test('passes with strings', function () { - expect('a')->toBeLessThanOrEqual('b'); - expect('a')->toBeLessThanOrEqual('a'); +test('passes with strings', function (): void { + expect('a')->toBeLessThanOrEqual('b') + ->toBeLessThanOrEqual('a'); }); -test('failures', function () { +test('failures', function (): void { expect(4)->toBeLessThanOrEqual(3.9); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(4)->toBeLessThanOrEqual(3.9, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(5)->not->toBeLessThanOrEqual(5); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeList.php b/tests/Features/Expect/toBeList.php index 095fda9d..75b5eabb 100644 --- a/tests/Features/Expect/toBeList.php +++ b/tests/Features/Expect/toBeList.php @@ -1,21 +1,23 @@ toBeList(); - expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList(); - expect('1, 2, 3')->not->toBeList(); +test('pass', function (): void { + expect([1, 2, 3])->toBeList() + ->and(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList() + ->and('1, 2, 3')->not->toBeList(); }); -test('failures', function () { - expect(null)->toBeList(); +test('failures', function (): void { + expect()->toBeList(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeList('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeList('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(['a', 'b', 'c'])->not->toBeList(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeLowercase.php b/tests/Features/Expect/toBeLowercase.php index 4eda711b..08c9c25d 100644 --- a/tests/Features/Expect/toBeLowercase.php +++ b/tests/Features/Expect/toBeLowercase.php @@ -1,20 +1,22 @@ toBeLowercase(); - expect('UPPERCASE')->not->toBeLowercase(); +test('pass', function (): void { + expect('lowercase')->toBeLowercase() + ->and('UPPERCASE')->not->toBeLowercase(); }); -test('failures', function () { +test('failures', function (): void { expect('UPPERCASE')->toBeLowercase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('UPPERCASE')->toBeLowercase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('lowercase')->not->toBeLowercase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeNAN.php b/tests/Features/Expect/toBeNAN.php index af00e290..914cabab 100644 --- a/tests/Features/Expect/toBeNAN.php +++ b/tests/Features/Expect/toBeNAN.php @@ -1,20 +1,22 @@ toBeNan(); - expect(log(0))->not->toBeNan(); +test('pass', function (): void { + expect(asin(2))->toBeNan() + ->and(log(0))->not->toBeNan(); }); -test('failures', function () { +test('failures', function (): void { expect(1)->toBeNan(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(1)->toBeNan('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(acos(1.5))->not->toBeNan(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeNull.php b/tests/Features/Expect/toBeNull.php index c705f450..7ce1c623 100644 --- a/tests/Features/Expect/toBeNull.php +++ b/tests/Features/Expect/toBeNull.php @@ -1,20 +1,22 @@ toBeNull(); - expect('')->not->toBeNull(); +test('pass', function (): void { + expect()->toBeNull() + ->and('')->not->toBeNull(); }); -test('failures', function () { +test('failures', function (): void { expect('hello')->toBeNull(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('hello')->toBeNull('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(null)->not->toBeNull(); +test('not failures', function (): void { + expect()->not->toBeNull(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeNumeric.php b/tests/Features/Expect/toBeNumeric.php index 7ed030ae..df45c846 100644 --- a/tests/Features/Expect/toBeNumeric.php +++ b/tests/Features/Expect/toBeNumeric.php @@ -1,20 +1,22 @@ toBeNumeric(); - expect('A')->not->toBeNumeric(); +test('pass', function (): void { + expect(42)->toBeNumeric() + ->and('A')->not->toBeNumeric(); }); -test('failures', function () { - expect(null)->toBeNumeric(); +test('failures', function (): void { + expect()->toBeNumeric(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeNumeric('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeNumeric('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(6 * 7)->not->toBeNumeric(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeObject.php b/tests/Features/Expect/toBeObject.php index afdf68bd..49d2a640 100644 --- a/tests/Features/Expect/toBeObject.php +++ b/tests/Features/Expect/toBeObject.php @@ -1,20 +1,22 @@ 1])->toBeObject(); - expect(['a' => 1])->not->toBeObject(); +test('pass', function (): void { + expect((object) ['a' => 1])->toBeObject() + ->and(['a' => 1])->not->toBeObject(); }); -test('failures', function () { - expect(null)->toBeObject(); +test('failures', function (): void { + expect()->toBeObject(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeObject('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeObject('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect((object) 'ciao')->not->toBeObject(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeReadableDirectory.php b/tests/Features/Expect/toBeReadableDirectory.php index 5d0d4ef6..3f70408c 100644 --- a/tests/Features/Expect/toBeReadableDirectory.php +++ b/tests/Features/Expect/toBeReadableDirectory.php @@ -1,19 +1,21 @@ toBeReadableDirectory(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever')->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever')->toBeReadableDirectory('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(sys_get_temp_dir())->not->toBeReadableDirectory(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeReadableFile.php b/tests/Features/Expect/toBeReadableFile.php index 4f1e26f0..148acf64 100644 --- a/tests/Features/Expect/toBeReadableFile.php +++ b/tests/Features/Expect/toBeReadableFile.php @@ -2,26 +2,26 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { touch($this->tempFile = sys_get_temp_dir().'/fake.file'); }); -afterEach(function () { +afterEach(function (): void { unlink($this->tempFile); }); -test('pass', function () { +test('pass', function (): void { expect($this->tempFile)->toBeReadableFile(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever.file')->toBeReadableFile(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever.file')->toBeReadableFile('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->tempFile)->not->toBeReadableFile(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeResource.php b/tests/Features/Expect/toBeResource.php index 91422b80..0c471e66 100644 --- a/tests/Features/Expect/toBeResource.php +++ b/tests/Features/Expect/toBeResource.php @@ -1,26 +1,28 @@ toBeResource(); - expect(null)->not->toBeResource(); +test('pass', function () use ($resource): void { + expect($resource)->toBeResource() + ->and(null)->not->toBeResource(); }); -test('failures', function () { - expect(null)->toBeResource(); +test('failures', function (): void { + expect()->toBeResource(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeResource('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeResource('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($resource) { +test('not failures', function () use ($resource): void { expect($resource)->not->toBeResource(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeScalar.php b/tests/Features/Expect/toBeScalar.php index cc5d0225..e0d9dea4 100644 --- a/tests/Features/Expect/toBeScalar.php +++ b/tests/Features/Expect/toBeScalar.php @@ -1,19 +1,21 @@ toBeScalar(); }); -test('failures', function () { - expect(null)->toBeScalar(); +test('failures', function (): void { + expect()->toBeScalar(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeScalar('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeScalar('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(42)->not->toBeScalar(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeSlug.php b/tests/Features/Expect/toBeSlug.php index 2d7c19f8..354d6ef6 100644 --- a/tests/Features/Expect/toBeSlug.php +++ b/tests/Features/Expect/toBeSlug.php @@ -1,24 +1,26 @@ toBeSlug() ->and('Another Test String')->toBeSlug(); }); -test('failures', function () { +test('failures', function (): void { expect('')->toBeSlug(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('')->toBeSlug('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with default message', function () { +test('failures with default message', function (): void { expect('')->toBeSlug(); })->throws(ExpectationFailedException::class, 'Failed asserting that can be converted to a slug.'); -test('not failures', function () { +test('not failures', function (): void { expect('This is a Test String!')->not->toBeSlug(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeSnakeCase.php b/tests/Features/Expect/toBeSnakeCase.php index 121f9e51..09168b41 100644 --- a/tests/Features/Expect/toBeSnakeCase.php +++ b/tests/Features/Expect/toBeSnakeCase.php @@ -1,23 +1,25 @@ toBeSnakeCase(); - expect('abc_def')->toBeSnakeCase(); - expect('abc-def')->not->toBeSnakeCase(); - expect('abcDef')->not->toBeSnakeCase(); - expect('AbcDef')->not->toBeSnakeCase(); +test('pass', function (): void { + expect('abc')->toBeSnakeCase() + ->and('abc_def')->toBeSnakeCase() + ->and('abc-def')->not->toBeSnakeCase() + ->and('abcDef')->not->toBeSnakeCase() + ->and('AbcDef')->not->toBeSnakeCase(); }); -test('failures', function () { +test('failures', function (): void { expect('Abc')->toBeSnakeCase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('Abc')->toBeSnakeCase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('abc_def')->not->toBeSnakeCase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeString.php b/tests/Features/Expect/toBeString.php index 2336d313..a5ee29d4 100644 --- a/tests/Features/Expect/toBeString.php +++ b/tests/Features/Expect/toBeString.php @@ -1,20 +1,22 @@ toBeString(); - expect(1.1)->not->toBeString(); +test('pass', function (): void { + expect('1.1')->toBeString() + ->and(1.1)->not->toBeString(); }); -test('failures', function () { - expect(null)->toBeString(); +test('failures', function (): void { + expect()->toBeString(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeString('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeString('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('42')->not->toBeString(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeStudlyCase.php b/tests/Features/Expect/toBeStudlyCase.php index af6391dc..108d7026 100644 --- a/tests/Features/Expect/toBeStudlyCase.php +++ b/tests/Features/Expect/toBeStudlyCase.php @@ -1,23 +1,24 @@ toBeStudlyCase(); - expect('AbcDef')->toBeStudlyCase(); - expect('abc-def')->not->toBeStudlyCase(); - expect('abc-def')->not->toBeStudlyCase(); - expect('abc')->not->toBeStudlyCase(); +test('pass', function (): void { + expect('Abc')->toBeStudlyCase() + ->and('AbcDef')->toBeStudlyCase() + ->and('abc-def')->not->toBeStudlyCase()->not->toBeStudlyCase() + ->and('abc')->not->toBeStudlyCase(); }); -test('failures', function () { +test('failures', function (): void { expect('abc')->toBeStudlyCase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('abc')->toBeStudlyCase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('AbcDef')->not->toBeStudlyCase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeTrue.php b/tests/Features/Expect/toBeTrue.php index 542d8e72..6de30a46 100644 --- a/tests/Features/Expect/toBeTrue.php +++ b/tests/Features/Expect/toBeTrue.php @@ -1,19 +1,21 @@ toBeTrue(); }); -test('failures', function () { +test('failures', function (): void { expect('')->toBeTrue(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('')->toBeTrue('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(false)->not->toBe(false); +test('not failures', function (): void { + expect(false)->toBeTrue(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeTruthy.php b/tests/Features/Expect/toBeTruthy.php index 2b26965c..cc7b382b 100644 --- a/tests/Features/Expect/toBeTruthy.php +++ b/tests/Features/Expect/toBeTruthy.php @@ -1,23 +1,25 @@ toBeTruthy(); })->with([true, [1], 'false', 1, -1]); -test('passes as not truthy', function ($value) { +test('passes as not truthy', function ($value): void { expect($value)->not->toBeTruthy(); })->with([false, '', null, 0, '0']); -test('failures', function () { - expect(null)->toBeTruthy(); +test('failures', function (): void { + expect()->toBeTruthy(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(null)->toBeTruthy('oh no!'); +test('failures with custom message', function (): void { + expect()->toBeTruthy('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(1)->not->toBeTruthy(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeUlid.php b/tests/Features/Expect/toBeUlid.php index 0f4a0e67..180ab727 100644 --- a/tests/Features/Expect/toBeUlid.php +++ b/tests/Features/Expect/toBeUlid.php @@ -1,26 +1,28 @@ toBeUlid(); })->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].'); -test('pass', function () { - expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid(); - expect('01BX5ZZKBKACTAV9WEVGEMMVRE')->toBeUlid(); - expect('7ZZZZZZZZZ0000000000000000')->toBeUlid(); +test('pass', function (): void { + expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid() + ->and('01BX5ZZKBKACTAV9WEVGEMMVRE')->toBeUlid() + ->and('7ZZZZZZZZZ0000000000000000')->toBeUlid(); }); -test('failures', function () { +test('failures', function (): void { expect('foo')->toBeUlid(); })->throws(ExpectationFailedException::class); -test('failures with message', function () { +test('failures with message', function (): void { expect('bar')->toBeUlid('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('foo')->not->toBeUlid(); }); diff --git a/tests/Features/Expect/toBeUppercase.php b/tests/Features/Expect/toBeUppercase.php index 7a1345d7..3ee6aedb 100644 --- a/tests/Features/Expect/toBeUppercase.php +++ b/tests/Features/Expect/toBeUppercase.php @@ -1,20 +1,22 @@ toBeUppercase(); - expect('lowercase')->not->toBeUppercase(); +test('pass', function (): void { + expect('UPPERCASE')->toBeUppercase() + ->and('lowercase')->not->toBeUppercase(); }); -test('failures', function () { +test('failures', function (): void { expect('lowercase')->toBeUppercase(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('lowercase')->toBeUppercase('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('UPPERCASE')->not->toBeUppercase(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeUrl.php b/tests/Features/Expect/toBeUrl.php index 1191dbab..a56a492a 100644 --- a/tests/Features/Expect/toBeUrl.php +++ b/tests/Features/Expect/toBeUrl.php @@ -1,24 +1,26 @@ toBeUrl() ->and('pestphp.com')->not->toBeUrl(); }); -test('failures', function () { +test('failures', function (): void { expect('pestphp.com')->toBeUrl(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('pestphp.com')->toBeUrl('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with default message', function () { +test('failures with default message', function (): void { expect('pestphp.com')->toBeUrl(); })->throws(ExpectationFailedException::class, 'Failed asserting that pestphp.com is a url.'); -test('not failures', function () { +test('not failures', function (): void { expect('https://pestphp.com')->not->toBeUrl(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeUuid.php b/tests/Features/Expect/toBeUuid.php index 971a196a..c993ffb2 100644 --- a/tests/Features/Expect/toBeUuid.php +++ b/tests/Features/Expect/toBeUuid.php @@ -1,13 +1,15 @@ toBeUuid(); })->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [string].'); -test('pass', function () { +test('pass', function (): void { expect('3cafb226-4326-11ee-a516-846993788c86')->toBeUuid(); // version 1 expect('0000415c-4326-21ee-a700-846993788c86')->toBeUuid(); // version 2 expect('3f703955-aaba-3e70-a3cb-baff6aa3b28f')->toBeUuid(); // version 3 @@ -18,14 +20,14 @@ test('pass', function () { expect('00112233-4455-8677-8899-aabbccddeeff')->toBeUuid(); // version 8 }); -test('failures', function () { +test('failures', function (): void { expect('foo')->toBeUuid(); })->throws(ExpectationFailedException::class); -test('failures with message', function () { +test('failures with message', function (): void { expect('bar')->toBeUuid('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('foo')->not->toBeUuid(); }); diff --git a/tests/Features/Expect/toBeWritableDirectory.php b/tests/Features/Expect/toBeWritableDirectory.php index 21546d13..f2293305 100644 --- a/tests/Features/Expect/toBeWritableDirectory.php +++ b/tests/Features/Expect/toBeWritableDirectory.php @@ -1,19 +1,21 @@ toBeWritableDirectory(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever')->toBeWritableDirectory(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever')->toBeWritableDirectory('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(sys_get_temp_dir())->not->toBeWritableDirectory(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toBeWritableFile.php b/tests/Features/Expect/toBeWritableFile.php index 5bf04d3e..5621be04 100644 --- a/tests/Features/Expect/toBeWritableFile.php +++ b/tests/Features/Expect/toBeWritableFile.php @@ -2,26 +2,26 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { touch($this->tempFile = sys_get_temp_dir().'/fake.file'); }); -afterEach(function () { +afterEach(function (): void { unlink($this->tempFile); }); -test('pass', function () { +test('pass', function (): void { expect($this->tempFile)->toBeWritableFile(); }); -test('failures', function () { +test('failures', function (): void { expect('/random/path/whatever.file')->toBeWritableFile(); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('/random/path/whatever.file')->toBeWritableFile('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->tempFile)->not->toBeWritableFile(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toContain.php b/tests/Features/Expect/toContain.php index 0d17e56c..2b292fa0 100644 --- a/tests/Features/Expect/toContain.php +++ b/tests/Features/Expect/toContain.php @@ -1,47 +1,49 @@ toContain('Nu'); }); -test('passes strings with multiple needles', function () { +test('passes strings with multiple needles', function (): void { expect('Nuno')->toContain('Nu', 'no'); }); -test('passes arrays', function () { +test('passes arrays', function (): void { expect([1, 2, 42])->toContain(42); }); -test('passes arrays with multiple needles', function () { +test('passes arrays with multiple needles', function (): void { expect([1, 2, 42])->toContain(42, 2); }); -test('passes with array needles', function () { +test('passes with array needles', function (): void { expect([[1, 2, 3], 2, 42])->toContain(42, [1, 2, 3]); }); -test('failures', function () { +test('failures', function (): void { expect([1, 2, 42])->toContain(3); })->throws(ExpectationFailedException::class); -test('failures with multiple needles (all failing)', function () { +test('failures with multiple needles (all failing)', function (): void { expect([1, 2, 42])->toContain(3, 4); })->throws(ExpectationFailedException::class); -test('failures with multiple needles (some failing)', function () { +test('failures with multiple needles (some failing)', function (): void { expect([1, 2, 42])->toContain(1, 3, 4); })->throws(ExpectationFailedException::class); -test('not failures', function () { +test('not failures', function (): void { expect([1, 2, 42])->not->toContain(42); })->throws(ExpectationFailedException::class); -test('not failures with multiple needles (all failing)', function () { +test('not failures with multiple needles (all failing)', function (): void { expect([1, 2, 42])->not->toContain(42, 2); })->throws(ExpectationFailedException::class); -test('not failures with multiple needles (some failing)', function () { +test('not failures with multiple needles (some failing)', function (): void { expect([1, 2, 42])->not->toContain(42, 1); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toContainEqual.php b/tests/Features/Expect/toContainEqual.php index 796dadd7..1ea65e61 100644 --- a/tests/Features/Expect/toContainEqual.php +++ b/tests/Features/Expect/toContainEqual.php @@ -1,35 +1,37 @@ toContainEqual('42'); }); -test('passes arrays with multiple needles', function () { +test('passes arrays with multiple needles', function (): void { expect([1, 2, 42])->toContainEqual('42', '2'); }); -test('failures', function () { +test('failures', function (): void { expect([1, 2, 42])->toContainEqual('3'); })->throws(ExpectationFailedException::class); -test('failures with multiple needles (all failing)', function () { +test('failures with multiple needles (all failing)', function (): void { expect([1, 2, 42])->toContainEqual('3', '4'); })->throws(ExpectationFailedException::class); -test('failures with multiple needles (some failing)', function () { +test('failures with multiple needles (some failing)', function (): void { expect([1, 2, 42])->toContainEqual('1', '3', '4'); })->throws(ExpectationFailedException::class); -test('not failures', function () { +test('not failures', function (): void { expect([1, 2, 42])->not->toContainEqual('42'); })->throws(ExpectationFailedException::class); -test('not failures with multiple needles (all failing)', function () { +test('not failures with multiple needles (all failing)', function (): void { expect([1, 2, 42])->not->toContainEqual('42', '2'); })->throws(ExpectationFailedException::class); -test('not failures with multiple needles (some failing)', function () { +test('not failures with multiple needles (some failing)', function (): void { expect([1, 2, 42])->not->toContainEqual('42', '1'); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toContainOnlyInstancesOf.php b/tests/Features/Expect/toContainOnlyInstancesOf.php index 4adaaa20..d971dce6 100644 --- a/tests/Features/Expect/toContainOnlyInstancesOf.php +++ b/tests/Features/Expect/toContainOnlyInstancesOf.php @@ -2,23 +2,22 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->times = [new DateTimeImmutable, new DateTimeImmutable]; }); -test('pass', function () { - expect($this->times)->toContainOnlyInstancesOf(DateTimeImmutable::class); - expect($this->times)->not->toContainOnlyInstancesOf(DateTime::class); +test('pass', function (): void { + expect($this->times)->toContainOnlyInstancesOf(DateTimeImmutable::class)->not->toContainOnlyInstancesOf(DateTime::class); }); -test('failures', function () { +test('failures', function (): void { expect($this->times)->toContainOnlyInstancesOf(DateTime::class); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect($this->times)->toContainOnlyInstancesOf(DateTime::class, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->times)->not->toContainOnlyInstancesOf(DateTimeImmutable::class); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toEndWith.php b/tests/Features/Expect/toEndWith.php index 1b1e2cce..e1e343d4 100644 --- a/tests/Features/Expect/toEndWith.php +++ b/tests/Features/Expect/toEndWith.php @@ -1,19 +1,21 @@ toEndWith('name'); }); -test('failures', function () { +test('failures', function (): void { expect('username')->toEndWith('password'); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('username')->toEndWith('password', 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('username')->not->toEndWith('name'); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toEqual.php b/tests/Features/Expect/toEqual.php index 3fbed36f..d479e338 100644 --- a/tests/Features/Expect/toEqual.php +++ b/tests/Features/Expect/toEqual.php @@ -1,19 +1,21 @@ toEqual(123); }); -test('failures', function () { +test('failures', function (): void { expect(['a', 'b', 'c'])->toEqual(['a', 'b']); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(['a', 'b', 'c'])->toEqual(['a', 'b'], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('042')->not->toEqual(42); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toEqualCanonicalizing.php b/tests/Features/Expect/toEqualCanonicalizing.php index f8712f82..d0623136 100644 --- a/tests/Features/Expect/toEqualCanonicalizing.php +++ b/tests/Features/Expect/toEqualCanonicalizing.php @@ -1,20 +1,22 @@ toEqualCanonicalizing([3, 1, 2]); - expect(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']); +test('pass', function (): void { + expect([1, 2, 3])->toEqualCanonicalizing([3, 1, 2]) + ->and(['g', 'a', 'z'])->not->toEqualCanonicalizing(['a', 'z']); }); -test('failures', function () { +test('failures', function (): void { expect([3, 2, 1])->toEqualCanonicalizing([1, 2]); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect([3, 2, 1])->toEqualCanonicalizing([1, 2], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(['a', 'b', 'c'])->not->toEqualCanonicalizing(['b', 'a', 'c']); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toEqualWithDelta.php b/tests/Features/Expect/toEqualWithDelta.php index bbd0eee4..3bfc12d2 100644 --- a/tests/Features/Expect/toEqualWithDelta.php +++ b/tests/Features/Expect/toEqualWithDelta.php @@ -1,15 +1,17 @@ toEqualWithDelta(1.3, .4); }); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(1.0)->toEqualWithDelta(1.5, .1, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(1.0)->not->toEqualWithDelta(1.6, .7); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveAttribute.php b/tests/Features/Expect/toHaveAttribute.php index 6de6be72..b94a2fc4 100644 --- a/tests/Features/Expect/toHaveAttribute.php +++ b/tests/Features/Expect/toHaveAttribute.php @@ -1,18 +1,19 @@ expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute') - ->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute'); + ->toHaveAttribute(AsAttribute::class); test('opposite class has attribute') ->throws(ArchExpectationFailedException::class) ->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\HaveAttribute') ->not - ->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute'); + ->toHaveAttribute(AsAttribute::class); test('class not has attribute') ->expect('Tests\\Fixtures\\Arch\\ToHaveAttribute\\NotHaveAttribute') ->not - ->toHaveAttribute('Tests\\Fixtures\\Arch\\ToHaveAttribute\\Attributes\\AsAttribute'); + ->toHaveAttribute(AsAttribute::class); diff --git a/tests/Features/Expect/toHaveCamelCaseKeys.php b/tests/Features/Expect/toHaveCamelCaseKeys.php index cf465a99..f50e2c74 100644 --- a/tests/Features/Expect/toHaveCamelCaseKeys.php +++ b/tests/Features/Expect/toHaveCamelCaseKeys.php @@ -1,5 +1,7 @@ toHaveCamelCaseKeys(); }); -test('failures', function () { +test('failures', function (): void { expect('not-an-array')->toHaveCamelCaseKeys(); })->throws(InvalidExpectationValue::class); -test('failures with message', function () use ($array) { +test('failures with message', function () use ($array): void { expect($array)->not->toHaveCamelCaseKeys('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($array) { +test('not failures', function () use ($array): void { expect($array)->not->toHaveCamelCaseKeys(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveConstructor.php b/tests/Features/Expect/toHaveConstructor.php index 66f07e91..a976d8a0 100644 --- a/tests/Features/Expect/toHaveConstructor.php +++ b/tests/Features/Expect/toHaveConstructor.php @@ -1,9 +1,12 @@ expect('Tests\Fixtures\Arch\ToHaveConstructor\HasConstructor\HasConstructor') + ->expect(HasConstructor::class) ->toHaveConstructor(); test('class has no constructor') - ->expect('Tests\Fixtures\Arch\ToHaveConstructor\HasNoConstructor\HasNoConstructor') + ->expect(HasNoConstructor::class) ->not->toHaveConstructor(); diff --git a/tests/Features/Expect/toHaveCount.php b/tests/Features/Expect/toHaveCount.php index 153175cf..d26031d0 100644 --- a/tests/Features/Expect/toHaveCount.php +++ b/tests/Features/Expect/toHaveCount.php @@ -1,24 +1,26 @@ toHaveCount(3); }); -test('failures with invalid type', function () { +test('failures with invalid type', function (): void { expect('foo')->toHaveCount(3); })->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable]'); -test('failures', function () { +test('failures', function (): void { expect([1, 2, 3])->toHaveCount(4); })->throws(ExpectationFailedException::class); -test('failures with message', function () { +test('failures with message', function (): void { expect([1, 2, 3])->toHaveCount(4, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect([1, 2, 3])->not->toHaveCount(3); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveDestructor.php b/tests/Features/Expect/toHaveDestructor.php index a5126ed2..100802a9 100644 --- a/tests/Features/Expect/toHaveDestructor.php +++ b/tests/Features/Expect/toHaveDestructor.php @@ -1,9 +1,12 @@ expect('Tests\Fixtures\Arch\ToHaveDestructor\HasDestructor\HasDestructor') + ->expect(HasDestructor::class) ->toHaveDestructor(); test('class has no destructor') - ->expect('Tests\Fixtures\Arch\ToHaveDestructor\HasNoDestructor\HasNoDestructor') + ->expect(HasNoDestructor::class) ->not->toHaveDestructor(); diff --git a/tests/Features/Expect/toHaveFileSystemPermissions.php b/tests/Features/Expect/toHaveFileSystemPermissions.php index 6a3becfb..b1e0877e 100644 --- a/tests/Features/Expect/toHaveFileSystemPermissions.php +++ b/tests/Features/Expect/toHaveFileSystemPermissions.php @@ -1,3 +1,5 @@ toHaveKebabCaseKeys(); }); -test('failures', function () { +test('failures', function (): void { expect('not-an-array')->toHaveKebabCaseKeys(); })->throws(InvalidExpectationValue::class); -test('failures with message', function () use ($array) { +test('failures with message', function () use ($array): void { expect($array)->not->toHaveKebabCaseKeys('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($array) { +test('not failures', function () use ($array): void { expect($array)->not->toHaveKebabCaseKeys(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveKey.php b/tests/Features/Expect/toHaveKey.php index a0768e37..94f837c5 100644 --- a/tests/Features/Expect/toHaveKey.php +++ b/tests/Features/Expect/toHaveKey.php @@ -20,66 +20,66 @@ test('pass with value check')->expect($test_array)->toHaveKey('c', 'world'); test('pass with value check and nested key')->expect($test_array)->toHaveKey('d.e', 'hello'); test('pass with value check and plain key with dots')->expect($test_array)->toHaveKey('key.with.dots', false); -test('failures', function () use ($test_array) { +test('failures', function () use ($test_array): void { expect($test_array)->toHaveKey('foo'); })->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'foo'"); -test('failures with custom message', function () use ($test_array) { +test('failures with custom message', function () use ($test_array): void { expect($test_array)->toHaveKey('foo', message: 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with custom message and Any matcher', function () use ($test_array) { +test('failures with custom message and Any matcher', function () use ($test_array): void { expect($test_array)->toHaveKey('foo', expect()->any(), 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with nested key', function () use ($test_array) { +test('failures with nested key', function () use ($test_array): void { expect($test_array)->toHaveKey('d.bar'); })->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'd.bar'"); -test('failures with nested key and custom message', function () use ($test_array) { +test('failures with nested key and custom message', function () use ($test_array): void { expect($test_array)->toHaveKey('d.bar', message: 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with nested key and custom message with Any matcher', function () use ($test_array) { +test('failures with nested key and custom message with Any matcher', function () use ($test_array): void { expect($test_array)->toHaveKey('d.bar', expect()->any(), 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with plain key with dots', function () use ($test_array) { +test('failures with plain key with dots', function () use ($test_array): void { expect($test_array)->toHaveKey('missing.key.with.dots'); })->throws(ExpectationFailedException::class, "Failed asserting that an array has the key 'missing.key.with.dots'"); -test('fails with wrong value', function () use ($test_array) { +test('fails with wrong value', function () use ($test_array): void { expect($test_array)->toHaveKey('c', 'bar'); })->throws(ExpectationFailedException::class); -test('fails with wrong value and nested key', function () use ($test_array) { +test('fails with wrong value and nested key', function () use ($test_array): void { expect($test_array)->toHaveKey('d.e', 'foo'); })->throws(ExpectationFailedException::class); -test('fails with wrong value and plain key with dots', function () use ($test_array) { +test('fails with wrong value and plain key with dots', function () use ($test_array): void { expect($test_array)->toHaveKey('key.with.dots', true); })->throws(ExpectationFailedException::class); -test('not failures', function () use ($test_array) { +test('not failures', function () use ($test_array): void { expect($test_array)->not->toHaveKey('c'); })->throws(ExpectationFailedException::class, "Expecting […] not to have key 'c'"); -test('not failures with nested key', function () use ($test_array) { +test('not failures with nested key', function () use ($test_array): void { expect($test_array)->not->toHaveKey('d.e'); })->throws(ExpectationFailedException::class, "Expecting […] not to have key 'd.e'"); -test('not failures with plain key with dots', function () use ($test_array) { +test('not failures with plain key with dots', function () use ($test_array): void { expect($test_array)->not->toHaveKey('key.with.dots'); })->throws(ExpectationFailedException::class, "Expecting […] not to have key 'key.with.dots'"); -test('not failures with correct value', function () use ($test_array) { +test('not failures with correct value', function () use ($test_array): void { expect($test_array)->not->toHaveKey('c', 'world'); })->throws(ExpectationFailedException::class); -test('not failures with correct value and with nested key', function () use ($test_array) { +test('not failures with correct value and with nested key', function () use ($test_array): void { expect($test_array)->not->toHaveKey('d.e', 'hello'); })->throws(ExpectationFailedException::class); -test('not failures with correct value and with plain key with dots', function () use ($test_array) { +test('not failures with correct value and with plain key with dots', function () use ($test_array): void { expect($test_array)->not->toHaveKey('key.with.dots', false); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveKeys.php b/tests/Features/Expect/toHaveKeys.php index e8a9cef3..95f61460 100644 --- a/tests/Features/Expect/toHaveKeys.php +++ b/tests/Features/Expect/toHaveKeys.php @@ -2,34 +2,34 @@ use PHPUnit\Framework\ExpectationFailedException; -test('pass', function () { +test('pass', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'c', 'foo.bar']); }); -test('pass with multi-dimensional arrays', function () { +test('pass with multi-dimensional arrays', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'c', 'foo' => ['bar' => ['bir']]]); }); -test('failures', function () { +test('failures', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'd', 'foo.bar', 'hello.world']); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->toHaveKeys(['a', 'd', 'foo.bar', 'hello.world'], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with multi-dimensional arrays', function () { +test('failures with multi-dimensional arrays', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'd', 'foo' => ['bar' => 'bir'], 'hello.world']); })->throws(ExpectationFailedException::class); -test('failures with multi-dimensional arrays and custom message', function () { +test('failures with multi-dimensional arrays and custom message', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->toHaveKeys(['a', 'd', 'foo' => ['bar' => 'bir'], 'hello.world'], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => 'baz']])->not->toHaveKeys(['foo.bar', 'c', 'z']); })->throws(ExpectationFailedException::class); -test('not failures with multi-dimensional arrays', function () { +test('not failures with multi-dimensional arrays', function (): void { expect(['a' => 1, 'b', 'c' => 'world', 'foo' => ['bar' => ['bir' => 'biz']]])->not->toHaveKeys(['foo' => ['bar' => 'bir'], 'c', 'z']); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveLength.php b/tests/Features/Expect/toHaveLength.php index b8ccb428..531d153f 100644 --- a/tests/Features/Expect/toHaveLength.php +++ b/tests/Features/Expect/toHaveLength.php @@ -1,8 +1,10 @@ toHaveLength(9); })->with([ 'Fortaleza', @@ -11,22 +13,22 @@ it('passes', function ($value) { (object) [1, 2, 3, 4, 5, 6, 7, 8, 9], ]); -it('passes with array', function () { +it('passes with array', function (): void { expect([1, 2, 3])->toHaveLength(3); }); -it('passes with *not*', function () { +it('passes with *not*', function (): void { expect('')->not->toHaveLength(1); }); -it('properly fails with *not*', function () { +it('properly fails with *not*', function (): void { expect('pest')->not->toHaveLength(4, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -it('fails', function () { +it('fails', function (): void { expect([1, 1.5, true, null])->toHaveLength(1); })->throws(ExpectationFailedException::class); -it('fails with message', function () { +it('fails with message', function (): void { expect([1, 1.5, true, null])->toHaveLength(1, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); diff --git a/tests/Features/Expect/toHaveLineCountLessThan.php b/tests/Features/Expect/toHaveLineCountLessThan.php index caf932d1..93b70d8e 100644 --- a/tests/Features/Expect/toHaveLineCountLessThan.php +++ b/tests/Features/Expect/toHaveLineCountLessThan.php @@ -3,10 +3,10 @@ use Pest\Arch\Exceptions\ArchExpectationFailedException; use Pest\Expectation; -it('passes', function () { +it('passes', function (): void { expect(Expectation::class)->toHaveLineCountLessThan(2000); }); -it('fails', function () { +it('fails', function (): void { expect(Expectation::class)->toHaveLineCountLessThan(10); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveMethod.php b/tests/Features/Expect/toHaveMethod.php index ffe2f743..2acfaf5c 100644 --- a/tests/Features/Expect/toHaveMethod.php +++ b/tests/Features/Expect/toHaveMethod.php @@ -1,29 +1,33 @@ expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod') + ->expect(HasMethod::class) ->toHaveMethod('foo'); test('opposite class has method') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod') + ->expect(HasMethod::class) ->not->toHaveMethod('foo'); test('class has method via a parent class') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent') + ->expect(HasMethodViaParent::class) ->toHaveMethod('foo'); test('class has method via a trait') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait') + ->expect(HasMethodViaTrait::class) ->toHaveMethod('foo'); test('failure when the class has no method') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass') + ->expect(HasNoMethodClass::class) ->toHaveMethod('foo'); test('class has no method') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass') + ->expect(HasNoMethodClass::class) ->not->toHaveMethod('foo'); diff --git a/tests/Features/Expect/toHaveMethods.php b/tests/Features/Expect/toHaveMethods.php index f149251c..39c4de16 100644 --- a/tests/Features/Expect/toHaveMethods.php +++ b/tests/Features/Expect/toHaveMethods.php @@ -1,29 +1,33 @@ expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod') + ->expect(HasMethod::class) ->toHaveMethods(['foo']); test('opposite class has method') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethod') + ->expect(HasMethod::class) ->not->toHaveMethods(['foo']); test('class has method via a parent class') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaParent') + ->expect(HasMethodViaParent::class) ->toHaveMethods(['foo']); test('class has method via a trait') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasMethod\HasMethodViaTrait') + ->expect(HasMethodViaTrait::class) ->toHaveMethods(['foo']); test('failure when the class has no method') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass') + ->expect(HasNoMethodClass::class) ->toHaveMethods(['foo']); test('class has no method') - ->expect('Tests\Fixtures\Arch\ToHaveMethod\HasNoMethod\HasNoMethodClass') + ->expect(HasNoMethodClass::class) ->not->toHaveMethods(['foo']); diff --git a/tests/Features/Expect/toHaveMethodsDocumented.php b/tests/Features/Expect/toHaveMethodsDocumented.php index abe9f259..ff620e78 100644 --- a/tests/Features/Expect/toHaveMethodsDocumented.php +++ b/tests/Features/Expect/toHaveMethodsDocumented.php @@ -5,15 +5,15 @@ use Pest\Configuration; use Pest\Expectation; use Tests\Fixtures\Inheritance\ExampleTest; -it('passes', function () { +it('passes', function (): void { expect(Expectation::class)->toHaveMethodsDocumented() ->and(ExampleTest::class)->not->toHaveMethodsDocumented(); }); -it('fails 1', function () { +it('fails 1', function (): void { expect(ExampleTest::class)->toHaveMethodsDocumented(); })->throws(ArchExpectationFailedException::class); -it('fails 2', function () { +it('fails 2', function (): void { expect(Configuration::class)->not->toHaveMethodsDocumented(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHavePrivateMethodsBesides.php b/tests/Features/Expect/toHavePrivateMethodsBesides.php index efd3595c..812df26e 100644 --- a/tests/Features/Expect/toHavePrivateMethodsBesides.php +++ b/tests/Features/Expect/toHavePrivateMethodsBesides.php @@ -3,10 +3,10 @@ use Pest\Arch\Exceptions\ArchExpectationFailedException; use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController; -test('pass', function () { +test('pass', function (): void { expect(UserController::class)->not->toHavePrivateMethodsBesides(['privateMethod']); }); -test('failures', function () { +test('failures', function (): void { expect(UserController::class)->not->toHavePrivateMethods(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveProperties.php b/tests/Features/Expect/toHaveProperties.php index 1d521f04..811a866f 100644 --- a/tests/Features/Expect/toHaveProperties.php +++ b/tests/Features/Expect/toHaveProperties.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\ExpectationFailedException; -test('pass', function () { +test('pass', function (): void { $object = new stdClass; $object->name = 'John'; $object->age = 21; @@ -15,7 +15,7 @@ test('pass', function () { ]); }); -test('failures', function () { +test('failures', function (): void { $object = new stdClass; $object->name = 'John'; @@ -27,7 +27,7 @@ test('failures', function () { ]); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { $object = new stdClass; $object->name = 'John'; @@ -39,7 +39,7 @@ test('failures with custom message', function () { ], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { $object = new stdClass; $object->name = 'John'; $object->age = 21; diff --git a/tests/Features/Expect/toHavePropertiesDocumented.php b/tests/Features/Expect/toHavePropertiesDocumented.php index 8ea3cb96..b3d0c58d 100644 --- a/tests/Features/Expect/toHavePropertiesDocumented.php +++ b/tests/Features/Expect/toHavePropertiesDocumented.php @@ -5,15 +5,15 @@ use Pest\Expectation; use Pest\Factories\TestCaseFactory; use Tests\Fixtures\Inheritance\ExampleTest; -it('passes', function () { +it('passes', function (): void { expect(Expectation::class)->toHavePropertiesDocumented() ->and(ExampleTest::class)->not->toHavePropertiesDocumented(); }); -it('fails 1', function () { +it('fails 1', function (): void { expect(ExampleTest::class)->toHavePropertiesDocumented(); })->throws(ArchExpectationFailedException::class); -it('fails 2', function () { +it('fails 2', function (): void { expect(TestCaseFactory::class)->not->toHavePropertiesDocumented(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveProperty.php b/tests/Features/Expect/toHaveProperty.php index 0f4cf672..65d7fc0e 100644 --- a/tests/Features/Expect/toHaveProperty.php +++ b/tests/Features/Expect/toHaveProperty.php @@ -6,25 +6,25 @@ $obj = new stdClass; $obj->foo = 'bar'; $obj->fooNull = null; -test('pass', function () use ($obj) { - expect($obj)->toHaveProperty('foo'); - expect($obj)->toHaveProperty('foo', 'bar'); - expect($obj)->toHaveProperty('fooNull'); - expect($obj)->toHaveProperty('fooNull', null); +test('pass', function () use ($obj): void { + expect($obj)->toHaveProperty('foo') + ->toHaveProperty('foo', 'bar') + ->toHaveProperty('fooNull') + ->toHaveProperty('fooNull', null); }); -test('failures', function () use ($obj) { +test('failures', function () use ($obj): void { expect($obj)->toHaveProperty('bar'); })->throws(ExpectationFailedException::class); -test('failures with message', function () use ($obj) { +test('failures with message', function () use ($obj): void { expect($obj)->toHaveProperty(name: 'bar', message: 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('failures with message and Any matcher', function () use ($obj) { +test('failures with message and Any matcher', function () use ($obj): void { expect($obj)->toHaveProperty('bar', expect()->any(), 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($obj) { +test('not failures', function () use ($obj): void { expect($obj)->not->toHaveProperty('foo'); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveProtectedMethodsBesides.php b/tests/Features/Expect/toHaveProtectedMethodsBesides.php index ee0ecb54..35dd1391 100644 --- a/tests/Features/Expect/toHaveProtectedMethodsBesides.php +++ b/tests/Features/Expect/toHaveProtectedMethodsBesides.php @@ -3,10 +3,10 @@ use Pest\Arch\Exceptions\ArchExpectationFailedException; use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController; -test('pass', function () { +test('pass', function (): void { expect(UserController::class)->not->toHaveProtectedMethodsBesides(['protectedMethod']); }); -test('failures', function () { +test('failures', function (): void { expect(UserController::class)->not->toHaveProtectedMethods(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHavePublicMethodsBesides.php b/tests/Features/Expect/toHavePublicMethodsBesides.php index a7df7711..fce09d98 100644 --- a/tests/Features/Expect/toHavePublicMethodsBesides.php +++ b/tests/Features/Expect/toHavePublicMethodsBesides.php @@ -3,10 +3,10 @@ use Pest\Arch\Exceptions\ArchExpectationFailedException; use Tests\Fixtures\Arch\ToHavePublicMethodsBesides\UserController; -test('pass', function () { +test('pass', function (): void { expect(UserController::class)->not->toHavePublicMethodsBesides(['publicMethod']); }); -test('failures', function () { +test('failures', function (): void { expect(UserController::class)->not->toHavePublicMethods(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveSameSize.php b/tests/Features/Expect/toHaveSameSize.php index 9039f0c1..9955a0fb 100644 --- a/tests/Features/Expect/toHaveSameSize.php +++ b/tests/Features/Expect/toHaveSameSize.php @@ -1,24 +1,26 @@ toHaveSameSize([1]); })->throws(InvalidExpectationValue::class, 'Invalid expectation value type. Expected [countable|iterable].'); -test('pass', function () { +test('pass', function (): void { expect([1, 2, 3])->toHaveSameSize([4, 5, 6]); }); -test('failures', function () { +test('failures', function (): void { expect([1, 2, 3])->toHaveSameSize([1]); })->throws(ExpectationFailedException::class); -test('failures with message', function () { +test('failures with message', function (): void { expect([1, 2, 3])->toHaveSameSize([1], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect([1, 2, 3])->not->toHaveSameSize([1]); }); diff --git a/tests/Features/Expect/toHaveSnakeCaseKeys.php b/tests/Features/Expect/toHaveSnakeCaseKeys.php index f43d91c4..ab5f66e5 100644 --- a/tests/Features/Expect/toHaveSnakeCaseKeys.php +++ b/tests/Features/Expect/toHaveSnakeCaseKeys.php @@ -1,5 +1,7 @@ toHaveSnakeCaseKeys(); }); -test('failures', function () { +test('failures', function (): void { expect('not-an-array')->toHaveSnakeCaseKeys(); })->throws(InvalidExpectationValue::class); -test('failures with message', function () use ($array) { +test('failures with message', function () use ($array): void { expect($array)->not->toHaveSnakeCaseKeys('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($array) { +test('not failures', function () use ($array): void { expect($array)->not->toHaveSnakeCaseKeys(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toHaveStudlyCaseKeys.php b/tests/Features/Expect/toHaveStudlyCaseKeys.php index caab167e..d9e4caca 100644 --- a/tests/Features/Expect/toHaveStudlyCaseKeys.php +++ b/tests/Features/Expect/toHaveStudlyCaseKeys.php @@ -1,5 +1,7 @@ toHaveStudlyCaseKeys(); }); -test('failures', function () { +test('failures', function (): void { expect('not-an-array')->toHaveStudlyCaseKeys(); })->throws(InvalidExpectationValue::class); -test('failures with message', function () use ($array) { +test('failures with message', function () use ($array): void { expect($array)->not->toHaveStudlyCaseKeys('oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () use ($array) { +test('not failures', function () use ($array): void { expect($array)->not->toHaveStudlyCaseKeys(); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toMatch.php b/tests/Features/Expect/toMatch.php index 82925a75..bb452834 100644 --- a/tests/Features/Expect/toMatch.php +++ b/tests/Features/Expect/toMatch.php @@ -1,19 +1,21 @@ toMatch('/^hello wo.*$/i'); }); -test('failures', function () { +test('failures', function (): void { expect('Hello World')->toMatch('/^hello$/i'); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('Hello World')->toMatch('/^hello$/i', 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('Hello World')->not->toMatch('/^hello wo.*$/i'); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toMatchArray.php b/tests/Features/Expect/toMatchArray.php index 116bff19..1c392582 100644 --- a/tests/Features/Expect/toMatchArray.php +++ b/tests/Features/Expect/toMatchArray.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->user = [ 'id' => 1, 'name' => 'Nuno', @@ -10,28 +10,28 @@ beforeEach(function () { ]; }); -test('pass', function () { +test('pass', function (): void { expect($this->user)->toMatchArray([ 'name' => 'Nuno', 'email' => 'enunomaduro@gmail.com', ]); }); -test('failures', function () { +test('failures', function (): void { expect($this->user)->toMatchArray([ 'name' => 'Not the same name', 'email' => 'enunomaduro@gmail.com', ]); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect($this->user)->toMatchArray([ 'name' => 'Not the same name', 'email' => 'enunomaduro@gmail.com', ], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->user)->not->toMatchArray([ 'id' => 1, ]); diff --git a/tests/Features/Expect/toMatchConstraint.php b/tests/Features/Expect/toMatchConstraint.php index 9a76e86b..e10276c6 100644 --- a/tests/Features/Expect/toMatchConstraint.php +++ b/tests/Features/Expect/toMatchConstraint.php @@ -3,18 +3,18 @@ use PHPUnit\Framework\Constraint\IsTrue; use PHPUnit\Framework\ExpectationFailedException; -test('pass', function () { +test('pass', function (): void { expect(true)->toMatchConstraint(new IsTrue); }); -test('failures', function () { +test('failures', function (): void { expect(false)->toMatchConstraint(new IsTrue); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect(false)->toMatchConstraint(new IsTrue, 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect(true)->not->toMatchConstraint(new IsTrue); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toMatchObject.php b/tests/Features/Expect/toMatchObject.php index 4402ff24..7796bbc3 100644 --- a/tests/Features/Expect/toMatchObject.php +++ b/tests/Features/Expect/toMatchObject.php @@ -2,7 +2,7 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->user = (object) [ 'id' => 1, 'name' => 'Nuno', @@ -10,14 +10,14 @@ beforeEach(function () { ]; }); -test('pass', function () { +test('pass', function (): void { expect($this->user)->toMatchObject([ 'name' => 'Nuno', 'email' => 'enunomaduro@gmail.com', ]); }); -test('pass with class', function () { +test('pass with class', function (): void { expect(new class { public $name = 'Nuno'; @@ -29,21 +29,21 @@ test('pass with class', function () { ]); }); -test('failures', function () { +test('failures', function (): void { expect($this->user)->toMatchObject([ 'name' => 'Not the same name', 'email' => 'enunomaduro@gmail.com', ]); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect($this->user)->toMatchObject([ 'name' => 'Not the same name', 'email' => 'enunomaduro@gmail.com', ], 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect($this->user)->not->toMatchObject([ 'id' => 1, ]); diff --git a/tests/Features/Expect/toMatchSnapshot.php b/tests/Features/Expect/toMatchSnapshot.php index 6e444eba..5ed86e61 100644 --- a/tests/Features/Expect/toMatchSnapshot.php +++ b/tests/Features/Expect/toMatchSnapshot.php @@ -3,7 +3,7 @@ use Pest\TestSuite; use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->snapshotable = <<<'HTML'
@@ -15,7 +15,7 @@ beforeEach(function () { HTML; }); -test('pass', function () { +test('pass', function (): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); expect($this->snapshotable)->toMatchSnapshot(); @@ -33,19 +33,19 @@ expect()->pipe('toMatchSnapshot', function (Closure $next) { return $next(); }); -test('pass using pipes', function () { +test('pass using pipes', function (): void { expect('') ->toMatchSnapshot(); }); -test('pass with `__toString`', function () { +test('pass with `__toString`', function (): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); $object = new class($this->snapshotable) { public function __construct(protected string $snapshotable) {} - public function __toString() + public function __toString(): string { return $this->snapshotable; } @@ -54,14 +54,14 @@ test('pass with `__toString`', function () { expect($object)->toMatchSnapshot(); }); -test('pass with `toString`', function () { +test('pass with `toString`', function (): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); $object = new class($this->snapshotable) { public function __construct(protected string $snapshotable) {} - public function toString() + public function toString(): string { return $this->snapshotable; } @@ -70,7 +70,7 @@ test('pass with `toString`', function () { expect($object)->toMatchSnapshot(); }); -test('pass with dataset', function ($data) { +test('pass with dataset', function ($data): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); [$filename] = TestSuite::getInstance()->snapshots->get(); @@ -79,8 +79,8 @@ test('pass with dataset', function ($data) { ->and($this->snapshotable)->toMatchSnapshot(); })->with(['my-datas-set-value']); -describe('within describe', function () { - test('pass with dataset', function ($data) { +describe('within describe', function (): void { + test('pass with dataset', function ($data): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); [$filename] = TestSuite::getInstance()->snapshots->get(); @@ -90,14 +90,14 @@ describe('within describe', function () { }); })->with(['my-datas-set-value']); -test('pass with `toArray`', function () { +test('pass with `toArray`', function (): void { TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT)); $object = new class($this->snapshotable) { public function __construct(protected string $snapshotable) {} - public function toArray() + public function toArray(): array { return [ 'key' => $this->snapshotable, @@ -108,7 +108,7 @@ test('pass with `toArray`', function () { expect($object)->toMatchSnapshot(); }); -test('pass with array', function () { +test('pass with array', function (): void { TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT)); expect([ @@ -116,14 +116,14 @@ test('pass with array', function () { ])->toMatchSnapshot(); }); -test('pass with `toSnapshot`', function () { +test('pass with `toSnapshot`', function (): void { TestSuite::getInstance()->snapshots->save(json_encode(['key' => $this->snapshotable], JSON_PRETTY_PRINT)); $object = new class($this->snapshotable) { public function __construct(protected string $snapshotable) {} - public function toSnapshot() + public function toSnapshot(): string|false { return json_encode([ 'key' => $this->snapshotable, @@ -134,34 +134,30 @@ test('pass with `toSnapshot`', function () { expect($object)->toMatchSnapshot(); }); -test('not failures', function () { +test('not failures', function (): void { TestSuite::getInstance()->snapshots->save($this->snapshotable); expect($this->snapshotable)->not->toMatchSnapshot(); })->throws(ExpectationFailedException::class); -test('multiple snapshot expectations', function () { - expect('foo bar 1')->toMatchSnapshot(); - - expect('foo bar 2')->toMatchSnapshot(); +test('multiple snapshot expectations', function (): void { + expect('foo bar 1')->toMatchSnapshot() + ->and('foo bar 2')->toMatchSnapshot(); }); -test('multiple snapshot expectations with datasets', function () { - expect('foo bar 1')->toMatchSnapshot(); - - expect('foo bar 2')->toMatchSnapshot(); +test('multiple snapshot expectations with datasets', function (): void { + expect('foo bar 1')->toMatchSnapshot() + ->and('foo bar 2')->toMatchSnapshot(); })->with([1, 'foo', 'bar', 'baz']); -describe('describable', function () { - test('multiple snapshot expectations with describe', function () { - expect('foo bar 1')->toMatchSnapshot(); - - expect('foo bar 2')->toMatchSnapshot(); +describe('describable', function (): void { + test('multiple snapshot expectations with describe', function (): void { + expect('foo bar 1')->toMatchSnapshot() + ->and('foo bar 2')->toMatchSnapshot(); }); }); -test('multiple snapshot expectations with repeat', function () { - expect('foo bar 1')->toMatchSnapshot(); - - expect('foo bar 2')->toMatchSnapshot(); +test('multiple snapshot expectations with repeat', function (): void { + expect('foo bar 1')->toMatchSnapshot() + ->and('foo bar 2')->toMatchSnapshot(); })->repeat(10); diff --git a/tests/Features/Expect/toStartWith.php b/tests/Features/Expect/toStartWith.php index ebc2d8ee..4fc11eab 100644 --- a/tests/Features/Expect/toStartWith.php +++ b/tests/Features/Expect/toStartWith.php @@ -1,19 +1,21 @@ toStartWith('user'); }); -test('failures', function () { +test('failures', function (): void { expect('username')->toStartWith('password'); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { +test('failures with custom message', function (): void { expect('username')->toStartWith('password', 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { +test('not failures', function (): void { expect('username')->not->toStartWith('user'); })->throws(ExpectationFailedException::class); diff --git a/tests/Features/Expect/toThrow.php b/tests/Features/Expect/toThrow.php index c84493a5..84ee8e6c 100644 --- a/tests/Features/Expect/toThrow.php +++ b/tests/Features/Expect/toThrow.php @@ -4,118 +4,109 @@ use PHPUnit\Framework\ExpectationFailedException; class CustomException extends Exception {} -test('passes', function () { - expect(function () { +test('passes', function (): void { + expect(function (): void { throw new RuntimeException; - })->toThrow(RuntimeException::class); - expect(function () { - throw new RuntimeException; - })->toThrow(Exception::class); - expect(function () { - throw new RuntimeException; - })->toThrow(function (RuntimeException $e) {}); - expect(function () { - throw new RuntimeException('actual message'); - })->toThrow(function (Exception $e) { - expect($e->getMessage())->toBe('actual message'); - }); - expect(function () {})->not->toThrow(Exception::class); - expect(function () { - throw new RuntimeException('actual message'); - })->toThrow('actual message'); - expect(function () { - throw new Exception; - })->not->toThrow(RuntimeException::class); - expect(function () { - throw new RuntimeException('actual message'); - })->toThrow(RuntimeException::class, 'actual message'); - expect(function () { - throw new RuntimeException('actual message'); - })->toThrow(function (RuntimeException $e) {}, 'actual message'); - expect(function () { - throw new CustomException('foo'); - })->toThrow(new CustomException('foo')); + })->toThrow(RuntimeException::class) + ->toThrow(Exception::class) + ->toThrow(function (RuntimeException $e): void {}) + ->and(function (): void { + throw new RuntimeException('actual message'); + })->toThrow(function (Exception $e): void { + expect($e->getMessage())->toBe('actual message'); + }) + ->and(function (): void {})->not->toThrow(Exception::class) + ->and(function (): void { + throw new RuntimeException('actual message'); + })->toThrow('actual message') + ->and(function (): void { + throw new Exception; + })->not->toThrow(RuntimeException::class) + ->and(function (): void { + throw new RuntimeException('actual message'); + })->toThrow(RuntimeException::class, 'actual message') + ->toThrow(function (RuntimeException $e): void {}, 'actual message') + ->and(function (): void { + throw new CustomException('foo'); + })->toThrow(new CustomException('foo')); }); -test('failures 1', function () { - expect(function () {})->toThrow(RuntimeException::class); +test('failures 1', function (): void { + expect(function (): void {})->toThrow(RuntimeException::class); })->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.'); -test('failures 2', function () { - expect(function () {})->toThrow(function (RuntimeException $e) {}); +test('failures 2', function (): void { + expect(function (): void {})->toThrow(function (RuntimeException $e): void {}); })->throws(ExpectationFailedException::class, 'Exception "'.RuntimeException::class.'" not thrown.'); -test('failures 3', function () { - expect(function () { +test('failures 3', function (): void { + expect(function (): void { throw new Exception; - })->toThrow(function (RuntimeException $e) { + })->toThrow(function (RuntimeException $e): void { // }); })->throws(ExpectationFailedException::class, 'Failed asserting that an instance of class Exception is an instance of class RuntimeException.'); -test('failures 4', function () { - expect(function () { +test('failures 4', function (): void { + expect(function (): void { throw new Exception('actual message'); }) - ->toThrow(function (Exception $e) { + ->toThrow(function (Exception $e): void { expect($e->getMessage())->toBe('expected message'); }); })->throws(ExpectationFailedException::class, 'Failed asserting that two strings are identical'); -test('failures 5', function () { - expect(function () { +test('failures 5', function (): void { + expect(function (): void { throw new Exception('actual message'); })->toThrow('expected message'); })->throws(ExpectationFailedException::class, 'Failed asserting that \'actual message\' [ASCII](length: 14) contains "expected message" [ASCII](length: 16).'); -test('failures 6', function () { - expect(function () {})->toThrow('actual message'); +test('failures 6', function (): void { + expect(function (): void {})->toThrow('actual message'); })->throws(ExpectationFailedException::class, 'Exception with message "actual message" not thrown'); -test('failures 7', function () { - expect(function () { +test('failures 7', function (): void { + expect(function (): void { throw new RuntimeException('actual message'); })->toThrow(RuntimeException::class, 'expected message'); })->throws(ExpectationFailedException::class); -test('failures 8', function () { - expect(function () { +test('failures 8', function (): void { + expect(function (): void { throw new CustomException('actual message'); })->toThrow(new CustomException('expected message')); })->throws(ExpectationFailedException::class); -test('failures with custom message', function () { - expect(function () { +test('failures with custom message', function (): void { + expect(function (): void { throw new RuntimeException('actual message'); })->toThrow(RuntimeException::class, 'expected message', 'oh no!'); })->throws(ExpectationFailedException::class, 'oh no!'); -test('not failures', function () { - expect(function () { +test('not failures', function (): void { + expect(function (): void { throw new RuntimeException; })->not->toThrow(RuntimeException::class); })->throws(ExpectationFailedException::class); -test('closure missing parameter', function () { - expect(function () {})->toThrow(function () {}); +test('closure missing parameter', function (): void { + expect(function (): void {})->toThrow(function (): void {}); })->throws(InvalidArgumentException::class, 'The given closure must have a single parameter type-hinted as the class string.'); -test('closure missing type-hint', function () { - expect(function () {})->toThrow(function ($e) {}); +test('closure missing type-hint', function (): void { + expect(function (): void {})->toThrow(function ($e): void {}); })->throws(InvalidArgumentException::class, 'The given closure\'s parameter must be type-hinted as the class string.'); -it('can handle a non-defined exception', function () { - expect(function () { +it('can handle a non-defined exception', function (): void { + expect(function (): void { throw new NonExistingException; })->toThrow(NonExistingException::class); })->throws(Error::class, 'Class "NonExistingException" not found'); -it('can handle a class not found Error', function () { - expect(function () { +it('can handle a class not found Error', function (): void { + expect(function (): void { throw new NonExistingException; - })->toThrow('Class "NonExistingException" not found'); - - expect(function () { - throw new NonExistingException; - })->toThrow(Error::class, 'Class "NonExistingException" not found'); + })->toThrow('Class "NonExistingException" not found') + ->toThrow(Error::class, 'Class "NonExistingException" not found'); }); diff --git a/tests/Features/Expect/toUseStrictEquality.php b/tests/Features/Expect/toUseStrictEquality.php index c8c2ce2a..dfb10063 100644 --- a/tests/Features/Expect/toUseStrictEquality.php +++ b/tests/Features/Expect/toUseStrictEquality.php @@ -1,21 +1,23 @@ throws(ArchExpectationFailedException::class) - ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality') + ->expect(NotStrictEquality::class) ->toUseStrictEquality(); test('has strict equality') - ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality') + ->expect(StrictEquality::class) ->toUseStrictEquality(); test('opposite missing strict equality') ->throws(ArchExpectationFailedException::class) - ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\StrictEquality') + ->expect(StrictEquality::class) ->not->toUseStrictEquality(); test('opposite has strict equality') - ->expect('Tests\\Fixtures\\Arch\\ToUseStrictEquality\\NotStrictEquality') + ->expect(NotStrictEquality::class) ->not->toUseStrictEquality(); diff --git a/tests/Features/Expect/toUseStrictTypes.php b/tests/Features/Expect/toUseStrictTypes.php index 9a609e50..0eb4abd4 100644 --- a/tests/Features/Expect/toUseStrictTypes.php +++ b/tests/Features/Expect/toUseStrictTypes.php @@ -7,11 +7,11 @@ use Tests\Fixtures\Arch\ToUseStrictTypes\HasNoStrictType; use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictType; use Tests\Fixtures\Arch\ToUseStrictTypes\HasStrictTypeWithCommentsAbove; -test('pass', function () { +test('pass', function (): void { expect(HasStrictType::class)->toUseStrictTypes() ->and(HasStrictTypeWithCommentsAbove::class)->toUseStrictTypes(); }); -test('failures', function () { +test('failures', function (): void { expect(HasNoStrictType::class)->toUseStrictTypes(); })->throws(ArchExpectationFailedException::class); diff --git a/tests/Features/Expect/toUseTrait.php b/tests/Features/Expect/toUseTrait.php index 806490b3..64ed2833 100644 --- a/tests/Features/Expect/toUseTrait.php +++ b/tests/Features/Expect/toUseTrait.php @@ -1,32 +1,39 @@ toUseTrait('Pest\Concerns\Retrievable') - ->and('Pest\Expectations\EachExpectation')->not->toUseTrait('Pest\Concerns\Retrievable'); +test('pass', function (): void { + expect(HigherOrderExpectation::class)->toUseTrait(Retrievable::class) + ->and(EachExpectation::class)->not->toUseTrait(Retrievable::class); }); -test('failures', function () { - expect('Pest\Expectations\EachExpectation')->toUseTrait('Pest\Concerns\Foo'); +test('failures', function (): void { + expect(EachExpectation::class)->toUseTrait('Pest\Concerns\Foo'); })->throws(ArchExpectationFailedException::class); -test('not failures', function () { - expect('Pest\Expectations\HigherOrderExpectation')->not->toUseTrait('Pest\Concerns\Retrievable'); +test('not failures', function (): void { + expect(HigherOrderExpectation::class)->not->toUseTrait(Retrievable::class); })->throws(ArchExpectationFailedException::class); -test('trait inheritance - direct usage', function () { - expect('Tests\Fixtures\Arch\ToUseTrait\HasTrait\ParentClassWithTrait')->toUseTrait('Tests\Fixtures\Arch\ToUseTrait\HasTrait\TestTraitForInheritance'); +test('trait inheritance - direct usage', function (): void { + expect(ParentClassWithTrait::class)->toUseTrait(TestTraitForInheritance::class); }); -test('trait inheritance - inherited usage', function () { - expect('Tests\Fixtures\Arch\ToUseTrait\HasInheritedTrait\ChildClassExtendingParent')->toUseTrait('Tests\Fixtures\Arch\ToUseTrait\HasTrait\TestTraitForInheritance'); +test('trait inheritance - inherited usage', function (): void { + expect(ChildClassExtendingParent::class)->toUseTrait(TestTraitForInheritance::class); }); -test('trait inheritance - negative case', function () { - expect('Tests\Fixtures\Arch\ToUseTrait\HasInheritedTrait\ChildClassExtendingParent')->not->toUseTrait('NonExistentTrait'); +test('trait inheritance - negative case', function (): void { + expect(ChildClassExtendingParent::class)->not->toUseTrait('NonExistentTrait'); }); -test('nested trait inheritance', function () { - expect('Tests\Fixtures\Arch\ToUseTrait\HasInheritedTrait\ChildClassExtendingParent')->toUseTrait('Tests\Fixtures\Arch\ToUseTrait\HasNestedTrait\NestedTrait'); +test('nested trait inheritance', function (): void { + expect(ChildClassExtendingParent::class)->toUseTrait(NestedTrait::class); }); diff --git a/tests/Features/Expect/unless.php b/tests/Features/Expect/unless.php index be28e225..1e9a6c76 100644 --- a/tests/Features/Expect/unless.php +++ b/tests/Features/Expect/unless.php @@ -2,50 +2,42 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->unlessObject = new stdClass; $this->unlessObject->trueValue = true; $this->unlessObject->foo = 'foo'; }); -it('pass', function () { +it('pass', function (): void { expect('foo') ->unless( true, - function ($value) { - return $value->toEqual('bar'); - } + fn ($value) => $value->toEqual('bar') ) - ->toEqual('foo'); - - expect(static::getCount())->toBe(1); + ->toEqual('foo') + ->and(static::getCount())->toBe(1); }); -it('failures', function () { +it('failures', function (): void { expect('foo') ->unless( false, - function ($value) { - return $value->toBeTrue(); - } + fn ($value) => $value->toBeTrue() ) ->toEqual('foo'); })->throws(ExpectationFailedException::class, 'is true'); -it('runs with truthy', function () { +it('runs with truthy', function (): void { expect($this->unlessObject) ->unless( 0, - function ($value) { - return $value->trueValue->toBeTrue(); - } + fn ($value) => $value->trueValue->toBeTrue() ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(2); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(2); }); -it('skips with falsy', function () { +it('skips with falsy', function (): void { expect($this->unlessObject) ->unless( 1, @@ -59,49 +51,36 @@ it('skips with falsy', function () { return $value->trueValue->toBeFalse(); // fails } ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(1); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(1); }); -it('runs with truthy closure condition', function () { +it('runs with truthy closure condition', function (): void { expect($this->unlessObject) ->unless( - function () { - return '0'; - }, - function ($value) { - return $value->trueValue->toBeTrue(); - } + fn (): string => '0', + fn ($value) => $value->trueValue->toBeTrue() ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(2); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(2); }); -it('skips with falsy closure condition', function () { +it('skips with falsy closure condition', function (): void { expect($this->unlessObject) ->unless( - function () { - return '1'; - }, + fn (): string => '1', function ($value) { return $value->trueValue->toBeFalse(); // fails } ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(1); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(1); }); it('can be used in higher order tests') ->expect(true) ->unless( - function () { - return false; - }, - function ($value) { - return $value->toBeFalse(); - } + fn (): false => false, + fn ($value) => $value->toBeFalse() ) ->throws(ExpectationFailedException::class, 'true is false'); diff --git a/tests/Features/Expect/when.php b/tests/Features/Expect/when.php index cee894ec..3261a17c 100644 --- a/tests/Features/Expect/when.php +++ b/tests/Features/Expect/when.php @@ -2,50 +2,42 @@ use PHPUnit\Framework\ExpectationFailedException; -beforeEach(function () { +beforeEach(function (): void { $this->whenObject = new stdClass; $this->whenObject->trueValue = true; $this->whenObject->foo = 'foo'; }); -it('pass', function () { +it('pass', function (): void { expect('foo') ->when( true, - function ($value) { - return $value->toEqual('foo'); - } + fn ($value) => $value->toEqual('foo') ) - ->toEqual('foo'); - - expect(static::getCount())->toBe(2); + ->toEqual('foo') + ->and(static::getCount())->toBe(2); }); -it('failures', function () { +it('failures', function (): void { expect('foo') ->when( true, - function ($value) { - return $value->toBeTrue(); - } + fn ($value) => $value->toBeTrue() ) ->toEqual('foo'); })->throws(ExpectationFailedException::class, 'is true'); -it('runs with truthy', function () { +it('runs with truthy', function (): void { expect($this->whenObject) ->when( 1, - function ($value) { - return $value->trueValue->toBeTrue(); - } + fn ($value) => $value->trueValue->toBeTrue() ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(2); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(2); }); -it('skips with falsy', function () { +it('skips with falsy', function (): void { expect($this->whenObject) ->when( 0, @@ -59,49 +51,36 @@ it('skips with falsy', function () { return $value->trueValue->toBeFalse(); // fails } ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(1); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(1); }); -it('runs with truthy closure condition', function () { +it('runs with truthy closure condition', function (): void { expect($this->whenObject) ->when( - function () { - return '1'; - }, - function ($value) { - return $value->trueValue->toBeTrue(); - } + fn (): string => '1', + fn ($value) => $value->trueValue->toBeTrue() ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(2); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(2); }); -it('skips with falsy closure condition', function () { +it('skips with falsy closure condition', function (): void { expect($this->whenObject) ->when( - function () { - return '0'; - }, + fn (): string => '0', function ($value) { return $value->trueValue->toBeFalse(); // fails } ) - ->foo->toEqual('foo'); - - expect(static::getCount())->toBe(1); + ->foo->toEqual('foo') + ->and(static::getCount())->toBe(1); }); it('can be used in higher order tests') ->expect(false) ->when( - function () { - return true; - }, - function ($value) { - return $value->toBeTrue(); - } + fn (): true => true, + fn ($value) => $value->toBeTrue() ) ->throws(ExpectationFailedException::class, 'false is true'); diff --git a/tests/Features/Fail.php b/tests/Features/Fail.php index 7f5c98aa..7bf0727a 100644 --- a/tests/Features/Fail.php +++ b/tests/Features/Fail.php @@ -2,10 +2,10 @@ use PHPUnit\Framework\AssertionFailedError; -it('may fail', function () { +it('may fail', function (): void { $this->fail(); })->throws(AssertionFailedError::class); -it('may fail with the given message', function () { +it('may fail with the given message', function (): void { $this->fail('this is a failure'); })->throws(AssertionFailedError::class, 'this is a failure'); diff --git a/tests/Features/Fails.php b/tests/Features/Fails.php index 7a9b908b..f60f3292 100644 --- a/tests/Features/Fails.php +++ b/tests/Features/Fails.php @@ -1,9 +1,9 @@ fail(); })->fails(); -it('may fail with the given message', function () { +it('may fail with the given message', function (): void { $this->fail('this is a failure'); })->fails('this is a failure'); diff --git a/tests/Features/Fixture.php b/tests/Features/Fixture.php index 1ac538b8..cf3d21ce 100644 --- a/tests/Features/Fixture.php +++ b/tests/Features/Fixture.php @@ -1,12 +1,14 @@ toBeString() ->toBeFile(); }); -it('may throw an exception if the file does not exist', function () { +it('may throw an exception if the file does not exist', function (): void { fixture('file-that-does-not-exist.php'); })->throws(InvalidArgumentException::class); diff --git a/tests/Features/Flaky.php b/tests/Features/Flaky.php index 2a55bad1..bf4a2d72 100644 --- a/tests/Features/Flaky.php +++ b/tests/Features/Flaky.php @@ -2,11 +2,11 @@ use Symfony\Component\Process\Process; -it('passes on first try', function () { +it('passes on first try', function (): void { expect(true)->toBeTrue(); })->flaky(); -it('passes on a subsequent try', function () { +it('passes on a subsequent try', function (): void { $file = sys_get_temp_dir().'/pest_flaky_'.crc32(__FILE__.__LINE__); $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -19,11 +19,11 @@ it('passes on a subsequent try', function () { expect(true)->toBeTrue(); })->flaky(tries: 3); -it('has a default of 3 tries', function () { +it('has a default of 3 tries', function (): void { expect(true)->toBeTrue(); })->flaky(); -it('succeeds on the last possible try', function () { +it('succeeds on the last possible try', function (): void { $file = sys_get_temp_dir().'/pest_flaky_last_try'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -36,11 +36,11 @@ it('succeeds on the last possible try', function () { expect(true)->toBeTrue(); })->flaky(tries: 3); -it('works with tries of 1', function () { +it('works with tries of 1', function (): void { expect(true)->toBeTrue(); })->flaky(tries: 1); -it('retries assertion failures', function () { +it('retries assertion failures', function (): void { $file = sys_get_temp_dir().'/pest_flaky_assertion'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -53,11 +53,11 @@ it('retries assertion failures', function () { expect(true)->toBeTrue(); })->flaky(tries: 3); -it('works with a dataset', function (int $number) { +it('works with a dataset', function (int $number): void { expect($number)->toBeGreaterThan(0); })->flaky(tries: 2)->with([1, 2, 3]); -it('retries each dataset independently', function (string $label) { +it('retries each dataset independently', function (string $label): void { $file = sys_get_temp_dir().'/pest_flaky_dataset_'.md5($label); $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -70,8 +70,8 @@ it('retries each dataset independently', function (string $label) { expect(true)->toBeTrue(); })->flaky(tries: 3)->with(['alpha', 'beta']); -describe('within a describe block', function () { - it('retries inside describe', function () { +describe('within a describe block', function (): void { + it('retries inside describe', function (): void { $file = sys_get_temp_dir().'/pest_flaky_describe'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -85,12 +85,12 @@ describe('within a describe block', function () { })->flaky(tries: 2); }); -describe('lifecycle hooks with flaky', function () { - beforeEach(function () { +describe('lifecycle hooks with flaky', function (): void { + beforeEach(function (): void { $this->setupCount = ($this->setupCount ?? 0) + 1; }); - it('re-runs beforeEach on each retry', function () { + it('re-runs beforeEach on each retry', function (): void { $file = sys_get_temp_dir().'/pest_flaky_lifecycle'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -105,15 +105,15 @@ describe('lifecycle hooks with flaky', function () { })->flaky(tries: 3); }); -describe('afterEach with flaky', function () { +describe('afterEach with flaky', function (): void { $state = new stdClass; $state->teardownCount = 0; - afterEach(function () use ($state) { + afterEach(function () use ($state): void { $state->teardownCount++; }); - it('runs afterEach between retries', function () use ($state) { + it('runs afterEach between retries', function () use ($state): void { $file = sys_get_temp_dir().'/pest_flaky_aftereach'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -132,7 +132,7 @@ it('does not retry skipped tests') ->skip('intentionally skipped') ->flaky(tries: 3); -it('works with repeat and flaky', function () { +it('works with repeat and flaky', function (): void { expect(true)->toBeTrue(); })->repeat(times: 2)->flaky(tries: 2); @@ -140,34 +140,33 @@ it('works as higher order test') ->assertTrue(true) ->flaky(tries: 2); -it('fails after exhausting all retries', function () { +it('fails after exhausting all retries', function (): void { $process = new Process( ['php', 'bin/pest', 'tests/.tests/FlakyFailure.php'], dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); - expect($process->getExitCode())->not->toBe(0); - expect(removeAnsiEscapeSequences($process->getOutput())) - ->toContain('FAILED') + expect($process->getExitCode())->not->toBe(0) + ->and(removeAnsiEscapeSequences($process->getOutput()))->toContain('FAILED') ->toContain('Always fails'); }); -it('throws when tries is less than 1', function () { - it('invalid', function () {})->flaky(tries: 0); +it('throws when tries is less than 1', function (): void { + it('invalid', function (): void {})->flaky(tries: 0); })->throws(InvalidArgumentException::class, 'The number of tries must be greater than 0.'); -it('throws when tries is negative', function () { - it('invalid negative', function () {})->flaky(tries: -1); +it('throws when tries is negative', function (): void { + it('invalid negative', function (): void {})->flaky(tries: -1); })->throws(InvalidArgumentException::class, 'The number of tries must be greater than 0.'); it('does not retry todo tests') ->todo() ->flaky(tries: 3); -it('retries php errors', function () { +it('retries php errors', function (): void { $file = sys_get_temp_dir().'/pest_flaky_error'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -180,11 +179,11 @@ it('retries php errors', function () { expect(true)->toBeTrue(); })->flaky(tries: 3); -it('works with throws and flaky', function () { +it('works with throws and flaky', function (): void { throw new RuntimeException('Expected exception'); })->throws(RuntimeException::class, 'Expected exception')->flaky(tries: 2); -it('does not retry expected exceptions', function () { +it('does not retry expected exceptions', function (): void { // If flaky retried this, the temp file counter would reach 2 and // the test would NOT throw — causing PHPUnit's "expected exception // was not raised" to fail. The test passes only if we don't retry. @@ -204,11 +203,11 @@ it('does not retry expected exceptions', function () { throw new RuntimeException('Expected on first attempt'); })->throws(RuntimeException::class)->flaky(tries: 3); -it('does not retry fails()', function () { +it('does not retry fails()', function (): void { $this->fail('Expected failure'); })->fails('Expected failure')->flaky(tries: 2); -it('retries unexpected exceptions even with throws set', function () { +it('retries unexpected exceptions even with throws set', function (): void { $file = sys_get_temp_dir().'/pest_flaky_unexpected'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -221,7 +220,7 @@ it('retries unexpected exceptions even with throws set', function () { throw new RuntimeException('Expected exception'); })->throws(RuntimeException::class)->flaky(tries: 3); -it('does not leak mock objects between retries', function () { +it('does not leak mock objects between retries', function (): void { $mock = $this->createMock(Countable::class); $mock->expects($this->once())->method('count')->willReturn(1); @@ -240,7 +239,7 @@ it('does not leak mock objects between retries', function () { expect($mock->count())->toBe(1); })->flaky(tries: 3); -it('does not stop retrying when snapshot changes are absent', function () { +it('does not stop retrying when snapshot changes are absent', function (): void { // Ensures the snapshot guard only triggers when __snapshotChanges is non-empty $file = sys_get_temp_dir().'/pest_flaky_no_snapshot'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; @@ -254,7 +253,7 @@ it('does not stop retrying when snapshot changes are absent', function () { expect(true)->toBeTrue(); })->flaky(tries: 3); -it('does not leak dynamic properties between retries', function () { +it('does not leak dynamic properties between retries', function (): void { $file = sys_get_temp_dir().'/pest_flaky_props'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -265,10 +264,10 @@ it('does not leak dynamic properties between retries', function () { } @unlink($file); - expect(isset($this->leakedProperty))->toBeFalse(); + expect(property_exists($this, 'leakedProperty') && $this->leakedProperty !== null)->toBeFalse(); })->flaky(tries: 3); -it('clears output buffer between retries when expectOutputString is used', function () { +it('clears output buffer between retries when expectOutputString is used', function (): void { $file = sys_get_temp_dir().'/pest_flaky_output'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); @@ -284,7 +283,7 @@ it('clears output buffer between retries when expectOutputString is used', funct echo 'clean'; })->flaky(tries: 3); -it('preserves output between retries when no output expectation is set', function () { +it('preserves output between retries when no output expectation is set', function (): void { $file = sys_get_temp_dir().'/pest_flaky_output_no_expect'; $count = file_exists($file) ? (int) file_get_contents($file) : 0; file_put_contents($file, (string) ++$count); diff --git a/tests/Features/Helpers.php b/tests/Features/Helpers.php index d2ea9485..4df77e5d 100644 --- a/tests/Features/Helpers.php +++ b/tests/Features/Helpers.php @@ -1,22 +1,22 @@ user = 'nuno'; } -it('can set/get properties on $this', function () { +it('can set/get properties on $this', function (): void { addUser(); expect($this->user)->toBe('nuno'); }); -it('gets null if property do not exist', function () { - expect(test()->wqdwqdqw)->toBe(null); +it('gets null if property do not exist', function (): void { + expect(test()->wqdwqdqw)->toBeNull(); }); class User { - public function getName() + public function getName(): string { return 'nuno'; } @@ -32,12 +32,12 @@ function mockUser() return $mock; } -it('allows to call underlying protected/private methods', function () { +it('allows to call underlying protected/private methods', function (): void { $user = mockUser(); expect($user->getName())->toBe('maduro'); }); -it('throws error if method do not exist', function () { +it('throws error if method do not exist', function (): void { test()->foo(); })->throws(ReflectionException::class, 'Call to undefined method PHPUnit\Framework\TestCase::foo()'); diff --git a/tests/Features/HigherOrderTests.php b/tests/Features/HigherOrderTests.php index a1bef96d..9adafd44 100644 --- a/tests/Features/HigherOrderTests.php +++ b/tests/Features/HigherOrderTests.php @@ -11,9 +11,7 @@ it('is capable doing multiple assertions') ->assertFalse(false); it('resolves expect callables correctly') - ->expect(function () { - return 'foo'; - }) + ->expect(fn (): string => 'foo') ->toBeString() ->toBe('foo') ->and('bar') @@ -25,7 +23,7 @@ test('does not treat method names as callables') it('can defer a method until after test setup') ->expect('foo')->toBeString() - ->defer(function () { + ->defer(function (): void { expect($this)->toBeInstanceOf(TestCase::class); }) ->toBe('foo') @@ -33,28 +31,20 @@ it('can defer a method until after test setup') it('can pass datasets into the expect callables') ->with([[1, 2, 3]]) - ->expect(function (...$numbers) { - return $numbers; - })->toBe([1, 2, 3]) - ->and(function (...$numbers) { - return $numbers; - })->toBe([1, 2, 3]); + ->expect(fn (...$numbers): array => $numbers)->toBe([1, 2, 3]) + ->and(fn (...$numbers): array => $numbers)->toBe([1, 2, 3]); it('can pass datasets into the defer callable') ->with([[1, 2, 3]]) - ->defer(function (...$numbers) { + ->defer(function (...$numbers): void { expect($numbers)->toBe([1, 2, 3]); }); it('can pass shared datasets into callables') ->with('numbers.closure.wrapped') - ->expect(function ($value) { - return $value; - }) - ->and(function ($value) { - return $value; - }) - ->defer(function ($value) { + ->expect(fn ($value) => $value) + ->and(fn ($value) => $value) + ->defer(function ($value): void { expect($value)->toBeInt(); }) ->toBeInt(); diff --git a/tests/Features/Incompleted.php b/tests/Features/Incompleted.php index c55c1c2b..2e3bb0cc 100644 --- a/tests/Features/Incompleted.php +++ b/tests/Features/Incompleted.php @@ -12,10 +12,10 @@ it('is not incompleted because of expect')->expect(true)->toBeTrue(); it('is not incompleted because of assert')->assertTrue(true); -it('is not incompleted because of test with assertions', function () { +it('is not incompleted because of test with assertions', function (): void { expect(true)->toBeTrue(); }); -describe('a "describe" group of tests', function () { +describe('a "describe" group of tests', function (): void { it('is incompleted'); }); diff --git a/tests/Features/Issue.php b/tests/Features/Issue.php index 958d5271..0210fb91 100644 --- a/tests/Features/Issue.php +++ b/tests/Features/Issue.php @@ -1,15 +1,15 @@ toBeTrue(); })->issue(1); -it('may be associated with an issue', function () { +it('may be associated with an issue', function (): void { expect(true)->toBeTrue(); })->issue(2); -describe('nested', function () { - it('may be associated with an issue', function () { +describe('nested', function (): void { + it('may be associated with an issue', function (): void { expect(true)->toBeTrue(); })->issue('#3'); })->issue(4)->note('an note between an the issue')->issue([5, 6]); diff --git a/tests/Features/It.php b/tests/Features/It.php index a9582b2a..e876f791 100644 --- a/tests/Features/It.php +++ b/tests/Features/It.php @@ -1,13 +1,13 @@ 'foo'])->toHaveKey('key')->key->toBeString(); }); it('is a higher order message test')->expect(true)->toBeTrue(); -describe('a "describe" group of tests', function () { - it('is a test', function () { +describe('a "describe" group of tests', function (): void { + it('is a test', function (): void { expect(['key' => 'foo'])->toHaveKey('key')->key->toBeString(); }); diff --git a/tests/Features/Note.php b/tests/Features/Note.php index 22d73b4f..842ef49b 100644 --- a/tests/Features/Note.php +++ b/tests/Features/Note.php @@ -1,42 +1,42 @@ note('This is before each runtime note'); })->note('This is before each static note'); -it('may have a static note', function () { +it('may have a static note', function (): void { expect(true)->toBeTrue(); })->note('This is a note'); -it('may have a runtime note', function () { +it('may have a runtime note', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note'); }); -it('may have static note and runtime note', function () { +it('may have static note and runtime note', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note'); })->note('This is a static note'); -describe('nested', function () { - beforeEach(function () { +describe('nested', function (): void { + beforeEach(function (): void { $this->note('This is before each describe runtime note'); })->note('This is before each describe static note'); - it('may have static note and runtime note', function () { + it('may have static note and runtime note', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note within describe'); })->note('This is a static note within describe'); - describe('describe nested within describe', function () { - beforeEach(function () { + describe('describe nested within describe', function (): void { + beforeEach(function (): void { $this->note('This is before each nested describe runtime note'); })->note('This is before each nested describe static note'); - it('may have a static note and runtime note', function () { + it('may have a static note and runtime note', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note within a nested describe'); @@ -44,29 +44,29 @@ describe('nested', function () { })->note('This is a nested describe static note'); })->note('This is describe static note'); -describe('matching describe names', function () { - beforeEach(function () { +describe('matching describe names', function (): void { + beforeEach(function (): void { $this->note('This is before each matching describe runtime note'); })->note('This is before each matching describe static note'); - describe('describe block', function () { - beforeEach(function () { + describe('describe block', function (): void { + beforeEach(function (): void { $this->note('This is before each matching describe runtime note'); })->note('This is before each matching describe static note'); - it('may have a static note and runtime note', function () { + it('may have a static note and runtime note', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note within a matching describe'); })->note('This is a static note within a matching describe'); })->note('This is a nested matching static note'); - describe('describe block', function () { - beforeEach(function () { + describe('describe block', function (): void { + beforeEach(function (): void { $this->note('This is before each matching describe runtime note, and should not contain the matching describe notes'); })->note('This is before each matching describe static note, and should not contain the matching describe notes'); - it('may have a static note and runtime note, that are different than the matching describe block', function () { + it('may have a static note and runtime note, that are different than the matching describe block', function (): void { expect(true)->toBeTrue(true); $this->note('This is a runtime note within a matching describe, and should not contain the matching describe notes'); @@ -74,7 +74,7 @@ describe('matching describe names', function () { })->note('This is a nested matching static note, and should not contain the matching describe notes'); }); -test('multiple notes', function () { +test('multiple notes', function (): void { expect(true)->toBeTrue(true); $this->note([ diff --git a/tests/Features/Notices.php b/tests/Features/Notices.php index fb94fcf9..f6e367e7 100644 --- a/tests/Features/Notices.php +++ b/tests/Features/Notices.php @@ -1,13 +1,15 @@ toBeTrue(); }); -describe('a "describe" group of tests', function () { - test('notice', function () { +describe('a "describe" group of tests', function (): void { + test('notice', function (): void { trigger_error('This is a notice description', E_USER_NOTICE); expect(true)->toBeTrue(); diff --git a/tests/Features/Pr.php b/tests/Features/Pr.php index 42c7ee14..72df27cd 100644 --- a/tests/Features/Pr.php +++ b/tests/Features/Pr.php @@ -1,15 +1,15 @@ toBeTrue(); })->pr(1); -it('may be associated with an pr', function () { +it('may be associated with an pr', function (): void { expect(true)->toBeTrue(); })->pr(2); -describe('nested', function () { - it('may be associated with an pr', function () { +describe('nested', function (): void { + it('may be associated with an pr', function (): void { expect(true)->toBeTrue(); })->pr('#3'); })->pr(4)->note('an note between an the pr')->pr(['#5', 6]); diff --git a/tests/Features/References.php b/tests/Features/References.php index a19db35a..cd04ab54 100644 --- a/tests/Features/References.php +++ b/tests/Features/References.php @@ -2,10 +2,10 @@ use Pest\Panic; -it('can reference a specific class', function () { +it('can reference a specific class', function (): void { expect(Panic::class)->toBeString(); })->references(Panic::class); -it('can reference a specific class method', function () { +it('can reference a specific class method', function (): void { expect(Panic::with(...))->toBeCallable(); })->references([Panic::class, 'with']); diff --git a/tests/Features/Repeat.php b/tests/Features/Repeat.php index 89d0c322..e1fa5ef7 100644 --- a/tests/Features/Repeat.php +++ b/tests/Features/Repeat.php @@ -1,29 +1,29 @@ toBeTrue(); })->repeat(times: 1); -test('multiple times', function () { +test('multiple times', function (): void { expect(true)->toBeTrue(); })->repeat(times: 5); -test('multiple times with single dataset', function (int $number) { +test('multiple times with single dataset', function (int $number): void { 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) { +test('multiple times with multiple dataset', function (int $numberA, int $numberB): void { 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]); -test('multiple times with iterator', function (int $iteration) { +test('multiple times with iterator', function (int $iteration): void { expect($iteration) ->toBeNumeric() ->toBeGreaterThan(0); })->repeat(times: 2); -test('multiple times with repeat iterator with single dataset', function (string $letter, int $iteration) { +test('multiple times with repeat iterator with single dataset', function (string $letter, int $iteration): void { expect($letter) ->toBeString() ->toBeIn(['a', 'b', 'c']) @@ -32,7 +32,7 @@ test('multiple times with repeat iterator with single dataset', function (string ->toBeGreaterThan(0); })->repeat(times: 2)->with(['a', 'b', 'c']); -test('multiple times with repeat iterator with multiple dataset', function (string $letterA, string $letterB, int $iteration) { +test('multiple times with repeat iterator with multiple dataset', function (string $letterA, string $letterB, int $iteration): void { expect($letterA) ->toBeString() ->toBeIn(['a', 'b', 'c']) @@ -44,51 +44,51 @@ test('multiple times with repeat iterator with multiple dataset', function (stri ->toBeGreaterThan(0); })->repeat(times: 2)->with(['a', 'b', 'c'], ['d', 'e', 'f']); -describe('describe blocks', function () { - test('multiple times', function () { +describe('describe blocks', function (): void { + test('multiple times', function (): void { expect(true)->toBeTrue(); })->repeat(times: 3); - describe('describe with repeat', function () { - test('test with no repeat should repeat the number of times specified in the parent describe block', function () { + describe('describe with repeat', function (): void { + test('test with no repeat should repeat the number of times specified in the parent describe block', function (): void { expect(true)->toBeTrue(); }); - test('test with repeat should repeat the number of times specified in the test', function () { + test('test with repeat should repeat the number of times specified in the test', function (): void { expect(true)->toBeTrue(); })->repeat(times: 2); - describe('nested describe without repeat', function () { - test("test with no repeat should repeat the number of times specified in the parent's parent describe block", function () { + describe('nested describe without repeat', function (): void { + test("test with no repeat should repeat the number of times specified in the parent's parent describe block", function (): void { expect(true)->toBeTrue(); }); - test('test with repeat should repeat the number of times specified in the test', function () { + test('test with repeat should repeat the number of times specified in the test', function (): void { expect(true)->toBeTrue(); })->repeat(times: 2); }); - describe('nested describe with repeat', function () { - test('test with no repeat should repeat the number of times specified in the parent describe block', function () { + describe('nested describe with repeat', function (): void { + test('test with no repeat should repeat the number of times specified in the parent describe block', function (): void { expect(true)->toBeTrue(); }); - test('test with repeat should repeat the number of times specified in the test', function () { + test('test with repeat should repeat the number of times specified in the test', function (): void { expect(true)->toBeTrue(); })->repeat(times: 2); })->repeat(times: 2); })->repeat(times: 3); }); -describe('matching describe blocks', function () { - describe('describe block', function () { - it('should repeat the number of times specified in the parent describe block', function () { +describe('matching describe blocks', function (): void { + describe('describe block', function (): void { + it('should repeat the number of times specified in the parent describe block', function (): void { expect(true)->toBeTrue(); }); })->repeat(times: 3); - describe('describe block', function () { - test('should not repeat the number of times of the describe block with the same name', function () { + describe('describe block', function (): void { + test('should not repeat the number of times of the describe block with the same name', function (): void { expect(true)->toBeTrue(); }); }); diff --git a/tests/Features/ScopedDatasets/Directory/Datasets/Scoped.php b/tests/Features/ScopedDatasets/Directory/Datasets/Scoped.php index d49e32c3..465e3fca 100644 --- a/tests/Features/ScopedDatasets/Directory/Datasets/Scoped.php +++ b/tests/Features/ScopedDatasets/Directory/Datasets/Scoped.php @@ -1,5 +1,7 @@ text = ''; -test('uses dataset', function ($value) use ($state) { +test('uses dataset', function ($value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('numbers.array'); -test('the right dataset is taken', function () use ($state) { +test('the right dataset is taken', function () use ($state): void { expect($state->text)->toBe('12345ScopedDatasets/NestedDirectory1/Datasets.php'); }); diff --git a/tests/Features/ScopedDatasets/Directory/NestedDirectory2/TestFileInNestedDirectory.php b/tests/Features/ScopedDatasets/Directory/NestedDirectory2/TestFileInNestedDirectory.php index a0224119..71a34c05 100644 --- a/tests/Features/ScopedDatasets/Directory/NestedDirectory2/TestFileInNestedDirectory.php +++ b/tests/Features/ScopedDatasets/Directory/NestedDirectory2/TestFileInNestedDirectory.php @@ -2,11 +2,11 @@ $state = new stdClass; $state->text = ''; -test('uses dataset', function ($value) use ($state) { +test('uses dataset', function ($value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('numbers.array'); -test('the right dataset is taken', function () use ($state) { +test('the right dataset is taken', function () use ($state): void { expect($state->text)->toBe('12345ScopedDatasets/Datasets/Scoped.php'); }); diff --git a/tests/Features/ScopedDatasets/Directory/TestFileWithLocallyDefinedDataset.php b/tests/Features/ScopedDatasets/Directory/TestFileWithLocallyDefinedDataset.php index 557eb983..372ef2c6 100644 --- a/tests/Features/ScopedDatasets/Directory/TestFileWithLocallyDefinedDataset.php +++ b/tests/Features/ScopedDatasets/Directory/TestFileWithLocallyDefinedDataset.php @@ -6,11 +6,11 @@ dataset('numbers.array', [ $state = new stdClass; $state->text = ''; -test('uses dataset', function ($value) use ($state) { +test('uses dataset', function ($value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('numbers.array'); -test('the right dataset is taken', function () use ($state) { +test('the right dataset is taken', function () use ($state): void { expect($state->text)->toBe('12345ScopedDatasets/ScopedDatasets.php'); }); diff --git a/tests/Features/ScopedDatasets/Directory/TestFileWithScopedDataset.php b/tests/Features/ScopedDatasets/Directory/TestFileWithScopedDataset.php index a0224119..71a34c05 100644 --- a/tests/Features/ScopedDatasets/Directory/TestFileWithScopedDataset.php +++ b/tests/Features/ScopedDatasets/Directory/TestFileWithScopedDataset.php @@ -2,11 +2,11 @@ $state = new stdClass; $state->text = ''; -test('uses dataset', function ($value) use ($state) { +test('uses dataset', function ($value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('numbers.array'); -test('the right dataset is taken', function () use ($state) { +test('the right dataset is taken', function () use ($state): void { expect($state->text)->toBe('12345ScopedDatasets/Datasets/Scoped.php'); }); diff --git a/tests/Features/ScopedDatasets/TestFileOutOfScope.php b/tests/Features/ScopedDatasets/TestFileOutOfScope.php index 559c09a7..5cff2b16 100644 --- a/tests/Features/ScopedDatasets/TestFileOutOfScope.php +++ b/tests/Features/ScopedDatasets/TestFileOutOfScope.php @@ -2,20 +2,20 @@ $state = new stdClass; $state->text = ''; -test('uses dataset', function ($value) use ($state) { +test('uses dataset', function ($value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('numbers.array'); -test('the right dataset is taken', function () use ($state) { +test('the right dataset is taken', function () use ($state): void { expect($state->text)->toBe('12'); }); -it('can see datasets defined in Pest.php file', function (string $value) use ($state) { +it('can see datasets defined in Pest.php file', function (string $value) use ($state): void { $state->text .= $value; - expect(true)->toBe(true); + expect(true)->toBeTrue(); })->with('dataset_in_pest_file'); -test('Pest.php dataset is taken', function () use ($state) { +test('Pest.php dataset is taken', function () use ($state): void { expect($state->text)->toBe('12AB'); }); diff --git a/tests/Features/See.php b/tests/Features/See.php index 7c9393ee..ae2bf204 100644 --- a/tests/Features/See.php +++ b/tests/Features/See.php @@ -2,10 +2,10 @@ use Pest\Panic; -it('can reference a specific class', function () { +it('can reference a specific class', function (): void { expect(Panic::class)->toBeString(); })->see(Panic::class); -it('can reference a specific class method', function () { +it('can reference a specific class method', function (): void { expect(Panic::with(...))->toBeCallable(); })->see([Panic::class, 'with']); diff --git a/tests/Features/Skip.php b/tests/Features/Skip.php index 9c305d35..c03d9000 100644 --- a/tests/Features/Skip.php +++ b/tests/Features/Skip.php @@ -1,6 +1,6 @@ shouldSkip = true; }); @@ -21,15 +21,11 @@ it('skips with message') ->assertTrue(false); it('skips with truthy closure condition') - ->skip(function () { - return '1'; - }) + ->skip(fn (): string => '1') ->assertTrue(false); it('do not skips with falsy closure condition') - ->skip(function () { - return false; - }) + ->skip(fn (): false => false) ->assertTrue(true); it('skips with condition and message') @@ -41,162 +37,156 @@ it('skips when skip after assertion') ->skip(); it('can use something in the test case as a condition') - ->skip(function () { - return $this->shouldSkip; - }, 'This test was skipped') + ->skip(fn () => $this->shouldSkip, 'This test was skipped') ->assertTrue(false); it('can user higher order callables and skip') - ->skip(function () { - return $this->shouldSkip; - }) - ->expect(function () { - return $this->shouldSkip; - }) + ->skip(fn () => $this->shouldSkip) + ->expect(fn () => $this->shouldSkip) ->toBeFalse(); -describe('skip on describe', function () { - beforeEach(function () { +describe('skip on describe', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__skip_on_describe__→__skipped_tests__→__nested_inside_skipped_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__skip_on_describe__→__skipped_tests__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__skip_on_describe__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__skip_on_describe__→__skipped_tests__→__nested_inside_skipped_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__skip_on_describe__→__skipped_tests__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__skip_on_describe__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('skipped tests', function () { - describe('nested inside skipped block', function () { - it('should not execute', function () { + describe('skipped tests', function (): void { + describe('nested inside skipped block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - it('should not execute', function () { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); })->skip(); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -describe('skip on beforeEach', function () { - beforeEach(function () { +describe('skip on beforeEach', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__skip_on_beforeEach__→__skipped_tests__→__nested_inside_skipped_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__skip_on_beforeEach__→__skipped_tests__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__skip_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__skip_on_beforeEach__→__skipped_tests__→__nested_inside_skipped_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__skip_on_beforeEach__→__skipped_tests__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__skip_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('skipped tests', function () { + describe('skipped tests', function (): void { beforeEach()->skip(); - describe('nested inside skipped block', function () { - it('should not execute', function () { + describe('nested inside skipped block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - it('should not execute', function () { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -describe('matching describe with skip', function () { - beforeEach(function () { +describe('matching describe with skip', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBe(true), - '__pest_evaluable__matching_describe_with_skip__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__matching_describe_with_skip__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBeTrue(), + '__pest_evaluable__matching_describe_with_skip__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('describe block', function () { - it('should not execute', function () { + describe('describe block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); })->skip(); - describe('describe block', function () { - it('should execute a test in a describe block with the same name as a skipped describe block', function () { + describe('describe block', function (): void { + it('should execute a test in a describe block with the same name as a skipped describe block', function (): void { $this->ran = true; }); }); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -describe('matching describe with skip on beforeEach', function () { - beforeEach(function () { +describe('matching describe with skip on beforeEach', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBe(true), - '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_skipped_describe_block' => expect($this->ran)->toBeTrue(), + '__pest_evaluable__matching_describe_with_skip_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('describe block', function () { + describe('describe block', function (): void { beforeEach()->skip(); - it('should not execute', function () { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - describe('describe block', function () { - it('should execute a test in a describe block with the same name as a skipped describe block', function () { + describe('describe block', function (): void { + it('should execute a test in a describe block with the same name as a skipped describe block', function (): void { $this->ran = true; }); }); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -it('does not skip after the describe block', function () { +it('does not skip after the describe block', function (): void { expect(true)->toBeTrue(); }); -it('can skip after the describe block', function () { +it('can skip after the describe block', function (): void { expect(true)->toBeTrue(); })->skip(); diff --git a/tests/Features/Test.php b/tests/Features/Test.php index e3334305..b0a4aad7 100644 --- a/tests/Features/Test.php +++ b/tests/Features/Test.php @@ -1,6 +1,6 @@ assertArrayHasKey('key', ['key' => 'foo']); }); diff --git a/tests/Features/TestCycle.php b/tests/Features/TestCycle.php index 799afe91..e9e0b24f 100644 --- a/tests/Features/TestCycle.php +++ b/tests/Features/TestCycle.php @@ -8,20 +8,20 @@ $foo->beforeEach = false; $foo->afterEach = false; $foo->afterAll = false; -beforeAll(function () use ($foo) { +beforeAll(function () use ($foo): void { $foo->beforeAll = true; }); -beforeEach(function () use ($foo) { +beforeEach(function () use ($foo): void { $foo->beforeEach = true; }); -afterEach(function () use ($foo) { +afterEach(function () use ($foo): void { $foo->afterEach = true; }); -afterAll(function () use ($foo) { +afterAll(function () use ($foo): void { $foo->afterAll = true; }); -register_shutdown_function(function () use ($foo) { +register_shutdown_function(function () use ($foo): void { assertFalse($foo->beforeAll); assertFalse($foo->beforeEach); assertFalse($foo->afterEach); diff --git a/tests/Features/ThrowsNoExceptions.php b/tests/Features/ThrowsNoExceptions.php index 5ae0422c..60124198 100644 --- a/tests/Features/ThrowsNoExceptions.php +++ b/tests/Features/ThrowsNoExceptions.php @@ -1,17 +1,17 @@ expectNotToPerformAssertions(); $result = 1 + 1; }); -it('allows performing no expectations without being risky', function () { +it('allows performing no expectations without being risky', function (): void { $result = 1 + 1; })->throwsNoExceptions(); -describe('a "describe" group of tests', function () { - it('allows performing no expectations without being risky', function () { +describe('a "describe" group of tests', function (): void { + it('allows performing no expectations without being risky', function (): void { $result = 1 + 1; }); })->throwsNoExceptions(); diff --git a/tests/Features/Ticket.php b/tests/Features/Ticket.php index 3413e4b4..c06fef6e 100644 --- a/tests/Features/Ticket.php +++ b/tests/Features/Ticket.php @@ -1,15 +1,15 @@ toBeTrue(); })->ticket(1); -it('may be associated with an ticket', function () { +it('may be associated with an ticket', function (): void { expect(true)->toBeTrue(); })->ticket(2); -describe('nested', function () { - it('may be associated with an ticket', function () { +describe('nested', function (): void { + it('may be associated with an ticket', function (): void { expect(true)->toBeTrue(); })->ticket(3); })->ticket(4)->note('an note between an the ticket')->ticket([5, 6]); diff --git a/tests/Features/Todo.php b/tests/Features/Todo.php index d6e8d978..6a2b7c6d 100644 --- a/tests/Features/Todo.php +++ b/tests/Features/Todo.php @@ -4,232 +4,232 @@ todo('something todo later'); test('something todo later chained')->todo(); -test('something todo later chained and with function body', function () { +test('something todo later chained and with function body', function (): void { expect(true)->toBeFalse(); })->todo(); -it('does something within a file with a todo', function () { +it('does something within a file with a todo', function (): void { expect(true)->toBeTrue(); }); -it('may have an associated assignee', function () { +it('may have an associated assignee', function (): void { expect(true)->toBeTrue(); })->todo(assignee: 'nunomaduro'); -it('may have an associated issue', function () { +it('may have an associated issue', function (): void { expect(true)->toBeTrue(); })->todo(issue: 1); -it('may have an associated PR', function () { +it('may have an associated PR', function (): void { expect(true)->toBeTrue(); })->todo(pr: 1); -it('may have an associated note', function () { +it('may have an associated note', function (): void { expect(true)->toBeTrue(); })->todo(note: 'a note'); -describe('todo on describe', function () { - beforeEach(function () { +describe('todo on describe', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__todo_on_describe__→__todo_block__→__nested_inside_todo_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__nested_inside_todo_block__→_it_should_set_the_note' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_without_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_with_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_as_well_as_the_note_from_the_test' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_without_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_with_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_as_well_as_the_note_from_the_test' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→__todo_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__todo_on_describe__→__todo_block__→__nested_inside_todo_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__nested_inside_todo_block__→_it_should_set_the_note' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_without_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_with_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_as_well_as_the_note_from_the_test' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_without_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_with_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_as_well_as_the_note_from_the_test' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→__todo_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('todo block', function () { - describe('nested inside todo block', function () { - it('should not execute', function () { + describe('todo block', function (): void { + describe('nested inside todo block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); - it('should set the note', function () { + it('should set the note', function (): void { $this->ran = true; $this->fail(); })->todo(note: 'hi'); }); - describe('describe with note', function () { - it('should apply the note to a test without a todo', function () { + describe('describe with note', function (): void { + it('should apply the note to a test without a todo', function (): void { $this->ran = true; $this->fail(); }); - it('should apply the note to a test with a todo', function () { + it('should apply the note to a test with a todo', function (): void { $this->ran = true; $this->fail(); })->todo(); - it('should apply the note as well as the note from the test', function () { + it('should apply the note as well as the note from the test', function (): void { $this->ran = true; $this->fail(); })->todo(note: 'test note'); - describe('nested describe with note', function () { - it('should apply all parent notes to a test without a todo', function () { + describe('nested describe with note', function (): void { + it('should apply all parent notes to a test without a todo', function (): void { $this->ran = true; $this->fail(); }); - it('should apply all parent notes to a test with a todo', function () { + it('should apply all parent notes to a test with a todo', function (): void { $this->ran = true; $this->fail(); })->todo(); - it('should apply all parent notes as well as the note from the test', function () { + it('should apply all parent notes as well as the note from the test', function (): void { $this->ran = true; $this->fail(); })->todo(note: 'test note'); })->todo(note: 'nested describe note'); })->todo(note: 'describe note'); - it('should not execute', function () { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); })->todo(); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -describe('todo on describe with matching name', function () { - beforeEach(function () { +describe('todo on describe with matching name', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__todo_on_describe_with_matching_name__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_describe_with_matching_name__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_todo_describe_block' => expect($this->ran)->toBe(true), - '__pest_evaluable__todo_on_describe_with_matching_name__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__todo_on_describe_with_matching_name__→__describe_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_describe_with_matching_name__→__describe_block__→_it_should_execute_a_test_in_a_describe_block_with_the_same_name_as_a_todo_describe_block' => expect($this->ran)->toBeTrue(), + '__pest_evaluable__todo_on_describe_with_matching_name__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('describe block', function () { - it('should not execute', function () { + describe('describe block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); })->todo(); - describe('describe block', function () { - it('should execute a test in a describe block with the same name as a todo describe block', function () { + describe('describe block', function (): void { + it('should execute a test in a describe block with the same name as a todo describe block', function (): void { $this->ran = true; }); }); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -test('todo on test after describe block', function () { +test('todo on test after describe block', function (): void { $this->fail(); })->todo(); -test('todo with note on test after describe block', function () { +test('todo with note on test after describe block', function (): void { $this->fail(); })->todo(note: 'test note'); -describe('todo on beforeEach', function () { - beforeEach(function () { +describe('todo on beforeEach', function (): void { + beforeEach(function (): void { $this->ran = false; }); - afterEach(function () { + afterEach(function (): void { match ($this->name()) { - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__nested_inside_todo_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→_it_should_not_execute' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_without_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_with_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_as_well_as_the_note_from_the_test' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_without_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_with_a_todo' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_as_well_as_the_note_from_the_test' => expect($this->ran)->toBe(false), - '__pest_evaluable__todo_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBe(true), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__nested_inside_todo_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→_it_should_not_execute' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_without_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_to_a_test_with_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→_it_should_apply_the_note_as_well_as_the_note_from_the_test' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_without_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_to_a_test_with_a_todo' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→__todo_block__→__describe_with_note__→__nested_describe_with_note__→_it_should_apply_all_parent_notes_as_well_as_the_note_from_the_test' => expect($this->ran)->toBeFalse(), + '__pest_evaluable__todo_on_beforeEach__→_it_should_execute' => expect($this->ran)->toBeTrue(), default => $this->fail('Unexpected test name: '.$this->name()), }; }); - describe('todo block', function () { + describe('todo block', function (): void { beforeEach()->todo(); - describe('nested inside todo block', function () { - it('should not execute', function () { + describe('nested inside todo block', function (): void { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - describe('describe with note', function () { - it('should apply the note to a test without a todo', function () { + describe('describe with note', function (): void { + it('should apply the note to a test without a todo', function (): void { $this->ran = true; $this->fail(); }); - it('should apply the note to a test with a todo', function () { + it('should apply the note to a test with a todo', function (): void { $this->ran = true; $this->fail(); })->todo(); - it('should apply the note as well as the note from the test', function () { + it('should apply the note as well as the note from the test', function (): void { $this->ran = true; $this->fail(); })->todo(note: 'test note'); - describe('nested describe with note', function () { - it('should apply all parent notes to a test without a todo', function () { + describe('nested describe with note', function (): void { + it('should apply all parent notes to a test without a todo', function (): void { $this->ran = true; $this->fail(); }); - it('should apply all parent notes to a test with a todo', function () { + it('should apply all parent notes to a test with a todo', function (): void { $this->ran = true; $this->fail(); })->todo(); - it('should apply all parent notes as well as the note from the test', function () { + it('should apply all parent notes as well as the note from the test', function (): void { $this->ran = true; $this->fail(); })->todo(note: 'test note'); })->todo(note: 'nested describe note'); })->todo(note: 'describe note'); - it('should not execute', function () { + it('should not execute', function (): void { $this->ran = true; $this->fail(); }); }); - it('should execute', function () { + it('should execute', function (): void { $this->ran = true; - expect($this->ran)->toBe(true); + expect($this->ran)->toBeTrue(); }); }); -test('todo on test after describe block with beforeEach', function () { +test('todo on test after describe block with beforeEach', function (): void { $this->fail(); })->todo(); -test('todo with note on test after describe block with beforeEach', function () { +test('todo with note on test after describe block with beforeEach', function (): void { $this->fail(); })->todo(note: 'test note'); diff --git a/tests/Features/Warnings.php b/tests/Features/Warnings.php index 76a51f2c..52382e97 100644 --- a/tests/Features/Warnings.php +++ b/tests/Features/Warnings.php @@ -1,19 +1,21 @@ fooqwdfwqdfqw; expect(true)->toBeTrue(); }); -test('user warning', function () { +test('user warning', function (): void { trigger_error('This is a warning description', E_USER_WARNING); expect(true)->toBeTrue(); }); -describe('a "describe" group of tests', function () { - test('user warning', function () { +describe('a "describe" group of tests', function (): void { + test('user warning', function (): void { trigger_error('This is a warning description', E_USER_WARNING); expect(true)->toBeTrue(); diff --git a/tests/Features/Wip.php b/tests/Features/Wip.php index 74b31d76..3c027335 100644 --- a/tests/Features/Wip.php +++ b/tests/Features/Wip.php @@ -1,17 +1,19 @@ toBeTrue(); })->wip(assignee: 'nunomaduro'); -it('may have an associated issue', function () { +it('may have an associated issue', function (): void { expect(true)->toBeTrue(); })->wip(issue: 1); -it('may have an associated PR', function () { +it('may have an associated PR', function (): void { expect(true)->toBeTrue(); })->wip(pr: 1); -it('may have an associated note', function () { +it('may have an associated note', function (): void { expect(true)->toBeTrue(); })->wip(note: 'a note'); diff --git a/tests/Fixtures/CollisionTest.php b/tests/Fixtures/CollisionTest.php index 316f9709..cae880b6 100644 --- a/tests/Fixtures/CollisionTest.php +++ b/tests/Fixtures/CollisionTest.php @@ -1,9 +1,11 @@ skip(! isset($_SERVER['COLLISION_TEST'])); -test('success', function () { +test('success', function (): void { expect(true)->toBeTrue(); })->skip(! isset($_SERVER['COLLISION_TEST'])); diff --git a/tests/Fixtures/Covers/CoversClass1.php b/tests/Fixtures/Covers/CoversClass1.php index ee0a4d40..8f5ad25e 100644 --- a/tests/Fixtures/Covers/CoversClass1.php +++ b/tests/Fixtures/Covers/CoversClass1.php @@ -1,5 +1,7 @@ markTestSkipped(); } diff --git a/tests/Fixtures/Inheritance/ExampleTest.php b/tests/Fixtures/Inheritance/ExampleTest.php index e6bd3ea3..6e10c613 100644 --- a/tests/Fixtures/Inheritance/ExampleTest.php +++ b/tests/Fixtures/Inheritance/ExampleTest.php @@ -1,12 +1,15 @@ assertTrue(true); } diff --git a/tests/Fixtures/ParallelNestedDatasets/Datasets/Nested/Users.php b/tests/Fixtures/ParallelNestedDatasets/Datasets/Nested/Users.php index dbff16da..1c6d6e3d 100644 --- a/tests/Fixtures/ParallelNestedDatasets/Datasets/Nested/Users.php +++ b/tests/Fixtures/ParallelNestedDatasets/Datasets/Nested/Users.php @@ -1,5 +1,7 @@ not->toBeEmpty(); })->with('nested.users'); diff --git a/tests/Fixtures/UnexpectedOutput.php b/tests/Fixtures/UnexpectedOutput.php index 170d17d7..b2835229 100644 --- a/tests/Fixtures/UnexpectedOutput.php +++ b/tests/Fixtures/UnexpectedOutput.php @@ -1,6 +1,8 @@ toBeTrue(); diff --git a/tests/Helpers.php b/tests/Helpers.php index f7870f38..46b04608 100644 --- a/tests/Helpers.php +++ b/tests/Helpers.php @@ -1,11 +1,13 @@ assertTrue($value); diff --git a/tests/Helpers/Helper.php b/tests/Helpers/Helper.php index b5958142..67819fde 100644 --- a/tests/Helpers/Helper.php +++ b/tests/Helpers/Helper.php @@ -1,6 +1,6 @@ assertTrue($value); } diff --git a/tests/Helpers/TestInHelpers.php b/tests/Helpers/TestInHelpers.php index 91dcb038..9871160c 100644 --- a/tests/Helpers/TestInHelpers.php +++ b/tests/Helpers/TestInHelpers.php @@ -1,5 +1,7 @@ toBeTrue(); }); diff --git a/tests/Hooks/AfterEachTest.php b/tests/Hooks/AfterEachTest.php index bbcf98ce..551d1b5f 100644 --- a/tests/Hooks/AfterEachTest.php +++ b/tests/Hooks/AfterEachTest.php @@ -1,10 +1,10 @@ ith = 0; }); -pest()->afterEach(function () { +pest()->afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -13,7 +13,7 @@ pest()->afterEach(function () { $this->ith++; }); -pest()->afterEach(function () { +pest()->afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -22,7 +22,7 @@ pest()->afterEach(function () { $this->ith++; }); -afterEach(function () { +afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -31,8 +31,8 @@ afterEach(function () { $this->ith++; }); -describe('nested', function () { - afterEach(function () { +describe('nested', function (): void { + afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -41,7 +41,7 @@ describe('nested', function () { $this->ith++; }); - test('nested afterEach execution order', function () { + test('nested afterEach execution order', function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -50,7 +50,7 @@ describe('nested', function () { $this->ith++; }); - afterEach(function () { + afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -60,7 +60,7 @@ describe('nested', function () { }); }); -afterEach(function () { +afterEach(function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) @@ -69,7 +69,7 @@ afterEach(function () { $this->ith++; }); -test('global afterEach execution order', function () { +test('global afterEach execution order', function (): void { expect($this) ->toHaveProperty('ith') ->and($this->ith) diff --git a/tests/Hooks/BeforeAllTest.php b/tests/Hooks/BeforeAllTest.php index d411d263..960394b6 100644 --- a/tests/Hooks/BeforeAllTest.php +++ b/tests/Hooks/BeforeAllTest.php @@ -1,16 +1,18 @@ beforeAll(function () { +declare(strict_types=1); + +pest()->beforeAll(function (): void { expect($_SERVER['globalHook']->calls->beforeAll) ->toBe(0); $_SERVER['globalHook']->calls->beforeAll++; }); -it('gets called before all tests 1', function () { +it('gets called before all tests 1', function (): void { expect($_SERVER['globalHook']->calls->beforeAll)->toBe(1); })->repeat(2); -it('gets called before all tests 2', function () { +it('gets called before all tests 2', function (): void { expect($_SERVER['globalHook']->calls->beforeAll)->toBe(1); }); diff --git a/tests/Hooks/BeforeEachTest.php b/tests/Hooks/BeforeEachTest.php index 78f9fa54..f1c411fe 100644 --- a/tests/Hooks/BeforeEachTest.php +++ b/tests/Hooks/BeforeEachTest.php @@ -1,6 +1,6 @@ beforeEach(function () { +pest()->beforeEach(function (): void { expect($this) ->toHaveProperty('baz') ->and($this->baz) @@ -9,7 +9,7 @@ pest()->beforeEach(function () { $this->baz = 2; }); -beforeEach(function () { +beforeEach(function (): void { expect($this) ->toHaveProperty('baz') ->and($this->baz) @@ -18,7 +18,7 @@ beforeEach(function () { $this->baz = 3; }); -test('global beforeEach execution order', function () { +test('global beforeEach execution order', function (): void { expect($this) ->toHaveProperty('baz') ->and($this->baz) diff --git a/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php b/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php index 2162c121..ed285079 100644 --- a/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php +++ b/tests/PHPUnit/CustomAffixes/FolderWithAn@/ExampleTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; class MyCustomClassTest extends TestCase { - public function assertTrueIsTrue() + public function assertTrueIsTrue(): void { $this->assertTrue(true); } @@ -13,7 +13,7 @@ class MyCustomClassTest extends TestCase pest()->extend(MyCustomClassTest::class); -test('custom traits can be used', function () { +test('custom traits can be used', function (): void { $this->assertTrueIsTrue(); }); diff --git a/tests/PHPUnit/CustomTestCase/ChildTest.php b/tests/PHPUnit/CustomTestCase/ChildTest.php index 15ad37cc..c6f91196 100644 --- a/tests/PHPUnit/CustomTestCase/ChildTest.php +++ b/tests/PHPUnit/CustomTestCase/ChildTest.php @@ -4,10 +4,4 @@ declare(strict_types=1); namespace Tests\CustomTestCase; -class ChildTest extends ParentTest -{ - private function getEntity(): bool - { - return true; - } -} +class ChildTest extends ParentTest {} diff --git a/tests/PHPUnit/CustomTestCase/CustomTestCase.php b/tests/PHPUnit/CustomTestCase/CustomTestCase.php index 8a7a07a4..66c251cd 100644 --- a/tests/PHPUnit/CustomTestCase/CustomTestCase.php +++ b/tests/PHPUnit/CustomTestCase/CustomTestCase.php @@ -10,7 +10,7 @@ use function PHPUnit\Framework\assertTrue; abstract class CustomTestCase extends TestCase { - public function assertCustomTrue() + public function assertCustomTrue(): void { assertTrue(true); } diff --git a/tests/PHPUnit/CustomTestCase/UsesPerDirectory.php b/tests/PHPUnit/CustomTestCase/UsesPerDirectory.php index c81afec5..bd08b5dd 100644 --- a/tests/PHPUnit/CustomTestCase/UsesPerDirectory.php +++ b/tests/PHPUnit/CustomTestCase/UsesPerDirectory.php @@ -4,6 +4,6 @@ use Tests\CustomTestCase\CustomTestCase; pest()->use(CustomTestCase::class)->in(__DIR__); -test('closure was bound to CustomTestCase', function () { +test('closure was bound to CustomTestCase', function (): void { $this->assertCustomTrue(); }); diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php index 205c227a..15997eff 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/CustomTestCaseInSubFolder.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; class CustomTestCaseInSubFolder extends TestCase { - public function assertCustomInSubFolderTrue() + public function assertCustomInSubFolderTrue(): void { $this->assertTrue(true); } diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/UsesPerSubDirectory.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/UsesPerSubDirectory.php index 01bb8456..75322063 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/UsesPerSubDirectory.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder/SubFolder/UsesPerSubDirectory.php @@ -1,5 +1,5 @@ assertCustomInSubFolderTrue(); }); diff --git a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php index edce0fe6..c114778a 100644 --- a/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php +++ b/tests/PHPUnit/CustomTestCaseInSubFolders/SubFolder2/UsesPerFile.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; trait MyCustomTrait { - public function assertFalseIsFalse() + public function assertFalseIsFalse(): void { assertFalse(false); } @@ -12,7 +12,7 @@ trait MyCustomTrait abstract class MyCustomClass extends TestCase { - public function assertTrueIsTrue() + public function assertTrueIsTrue(): void { $this->assertTrue(true); } @@ -20,7 +20,7 @@ abstract class MyCustomClass extends TestCase pest()->extend(MyCustomClass::class)->use(MyCustomTrait::class); -test('custom traits can be used', function () { +test('custom traits can be used', function (): void { $this->assertTrueIsTrue(); }); diff --git a/tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php b/tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php index 196fea3a..f22d23a8 100644 --- a/tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php +++ b/tests/PHPUnit/GlobPatternTests/SubFolder/InnerFolder/UsesPerDirectoryAsPattern.php @@ -1,5 +1,5 @@ assertCustomTrue(); }); diff --git a/tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php b/tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php index 196fea3a..f22d23a8 100644 --- a/tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php +++ b/tests/PHPUnit/GlobPatternTests/SubFolder2/UsesPerFileAsPattern.php @@ -1,5 +1,5 @@ assertCustomTrue(); }); diff --git a/tests/PHPUnit/IgnorableTest.php b/tests/PHPUnit/IgnorableTest.php index b3d9bbc7..174d7fd7 100644 --- a/tests/PHPUnit/IgnorableTest.php +++ b/tests/PHPUnit/IgnorableTest.php @@ -1 +1,3 @@ (object) ['beforeAll' => 0, 'after pest() ->in('Hooks') - ->beforeEach(function () { + ->beforeEach(function (): void { $this->baz = 0; }) - ->beforeAll(function () { + ->beforeAll(function (): void { $_SERVER['globalHook']->beforeAll = 0; }) - ->afterEach(function () { + ->afterEach(function (): void { if (! isset($this->ith)) { return; } @@ -38,13 +38,13 @@ pest() assert($this->ith === 1, 'Expected $this->ith to be 1, but got '.$this->ith); $this->ith++; }) - ->afterAll(function () { + ->afterAll(function (): void { $_SERVER['globalHook']->afterAll = 0; $_SERVER['globalHook']->calls->afterAll++; }); pest()->in('Hooks') - ->beforeEach(function () { + ->beforeEach(function (): void { expect($this) ->toHaveProperty('baz') ->and($this->baz) @@ -52,7 +52,7 @@ pest()->in('Hooks') $this->baz = 1; }) - ->beforeAll(function () { + ->beforeAll(function (): void { expect($_SERVER['globalHook']) ->toHaveProperty('beforeAll') ->and($_SERVER['globalHook']->beforeAll) @@ -60,7 +60,7 @@ pest()->in('Hooks') $_SERVER['globalHook']->beforeAll = 1; }) - ->afterEach(function () { + ->afterEach(function (): void { if (! isset($this->ith)) { return; } @@ -68,7 +68,7 @@ pest()->in('Hooks') assert($this->ith === 2, 'Expected $this->ith to be 1, but got '.$this->ith); $this->ith++; }) - ->afterAll(function () { + ->afterAll(function (): void { expect($_SERVER['globalHook']) ->toHaveProperty('afterAll') ->and($_SERVER['globalHook']->afterAll) @@ -77,7 +77,7 @@ pest()->in('Hooks') $_SERVER['globalHook']->afterAll = 1; }); -function helper_returns_string() +function helper_returns_string(): string { return 'string'; } diff --git a/tests/Playground.php b/tests/Playground.php index be30ae7d..115bc881 100644 --- a/tests/Playground.php +++ b/tests/Playground.php @@ -1,5 +1,7 @@ toBeTrue(); }); diff --git a/tests/Plugins/Coverage.php b/tests/Plugins/Coverage.php index 358a9d9d..a9c581ef 100644 --- a/tests/Plugins/Coverage.php +++ b/tests/Plugins/Coverage.php @@ -3,7 +3,7 @@ use Pest\Plugins\Coverage; use Symfony\Component\Console\Output\NullOutput; -test('compute comparable coverage', function (float $givenValue, float $expectedValue) { +test('compute comparable coverage', function (float $givenValue, float $expectedValue): void { $output = new NullOutput; $plugin = new Coverage($output); diff --git a/tests/Unit/Configuration/In.php b/tests/Unit/Configuration/In.php index 5dd26100..812d0522 100644 --- a/tests/Unit/Configuration/In.php +++ b/tests/Unit/Configuration/In.php @@ -1,8 +1,10 @@ in(); expect($in)->toBeInstanceOf(UsesCall::class); diff --git a/tests/Unit/Configuration/Theme.php b/tests/Unit/Configuration/Theme.php index 308cf1f3..7c2e91cf 100644 --- a/tests/Unit/Configuration/Theme.php +++ b/tests/Unit/Configuration/Theme.php @@ -1,8 +1,10 @@ printer(); expect($theme)->toBeInstanceOf(Printer::class); diff --git a/tests/Unit/Console/Help.php b/tests/Unit/Console/Help.php index 120a6f8e..2ca1c0bc 100644 --- a/tests/Unit/Console/Help.php +++ b/tests/Unit/Console/Help.php @@ -3,7 +3,7 @@ use Pest\Console\Help; use Symfony\Component\Console\Output\BufferedOutput; -it('outputs the help information when --help is used', function () { +it('outputs the help information when --help is used', function (): void { $output = new BufferedOutput; $plugin = new Help($output); diff --git a/tests/Unit/DatasetsTests.php b/tests/Unit/DatasetsTests.php index 543c30ae..a11bb97a 100644 --- a/tests/Unit/DatasetsTests.php +++ b/tests/Unit/DatasetsTests.php @@ -2,7 +2,7 @@ use Pest\Repositories\DatasetsRepository; -it('show only the names of named datasets in their description', function () { +it('show only the names of named datasets in their description', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ 'one' => [1], @@ -14,7 +14,7 @@ it('show only the names of named datasets in their description', function () { ->and($descriptions[1])->toBe('dataset "two"'); }); -it('show the actual dataset of non-named datasets in their description', function () { +it('show the actual dataset of non-named datasets in their description', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ [1], @@ -22,11 +22,11 @@ it('show the actual dataset of non-named datasets in their description', functio ], ], __FILE__)); - expect($descriptions[0])->toBe('(1)'); - expect($descriptions[1])->toBe('([2])'); + expect($descriptions[0])->toBe('(1)') + ->and($descriptions[1])->toBe('([2])'); }); -it('show only the names of multiple named datasets in their description', function () { +it('show only the names of multiple named datasets in their description', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ 'one' => [1], @@ -38,13 +38,13 @@ it('show only the names of multiple named datasets in their description', functi ], ], __FILE__)); - expect($descriptions[0])->toBe('dataset "one" / dataset "three"'); - expect($descriptions[1])->toBe('dataset "one" / dataset "four"'); - expect($descriptions[2])->toBe('dataset "two" / dataset "three"'); - expect($descriptions[3])->toBe('dataset "two" / dataset "four"'); + expect($descriptions[0])->toBe('dataset "one" / dataset "three"') + ->and($descriptions[1])->toBe('dataset "one" / dataset "four"') + ->and($descriptions[2])->toBe('dataset "two" / dataset "three"') + ->and($descriptions[3])->toBe('dataset "two" / dataset "four"'); }); -it('show the actual dataset of multiple non-named datasets in their description', function () { +it('show the actual dataset of multiple non-named datasets in their description', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ [1], @@ -56,13 +56,13 @@ it('show the actual dataset of multiple non-named datasets in their description' ], ], __FILE__)); - expect($descriptions[0])->toBe('(1) / (3)'); - expect($descriptions[1])->toBe('(1) / ([4])'); - expect($descriptions[2])->toBe('([2]) / (3)'); - expect($descriptions[3])->toBe('([2]) / ([4])'); + expect($descriptions[0])->toBe('(1) / (3)') + ->and($descriptions[1])->toBe('(1) / ([4])') + ->and($descriptions[2])->toBe('([2]) / (3)') + ->and($descriptions[3])->toBe('([2]) / ([4])'); }); -it('show the correct description for mixed named and not-named datasets', function () { +it('show the correct description for mixed named and not-named datasets', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ 'one' => [1], @@ -74,13 +74,13 @@ it('show the correct description for mixed named and not-named datasets', functi ], ], __FILE__)); - expect($descriptions[0])->toBe('dataset "one" / (3)'); - expect($descriptions[1])->toBe('dataset "one" / dataset "four"'); - expect($descriptions[2])->toBe('([2]) / (3)'); - expect($descriptions[3])->toBe('([2]) / dataset "four"'); + expect($descriptions[0])->toBe('dataset "one" / (3)') + ->and($descriptions[1])->toBe('dataset "one" / dataset "four"') + ->and($descriptions[2])->toBe('([2]) / (3)') + ->and($descriptions[3])->toBe('([2]) / dataset "four"'); }); -it('shows the correct description for long texts with newlines', function () { +it('shows the correct description for long texts with newlines', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ ['some very \nlong text with \n newlines'], @@ -90,7 +90,7 @@ it('shows the correct description for long texts with newlines', function () { expect($descriptions[0])->toBe('(\'some very long text with …wlines\')'); }); -it('shows the correct description for arrays with many elements', function () { +it('shows the correct description for arrays with many elements', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ [[1, 2, 3, 4, 5]], @@ -100,7 +100,7 @@ it('shows the correct description for arrays with many elements', function () { expect($descriptions[0])->toBe('([1, 2, 3, …])'); }); -it('shows the correct description of datasets with html', function () { +it('shows the correct description of datasets with html', function (): void { $descriptions = array_keys(DatasetsRepository::resolve([ [ '
', diff --git a/tests/Unit/Expectations/OppositeExpectation.php b/tests/Unit/Expectations/OppositeExpectation.php index 856a38e6..5ba7a193 100644 --- a/tests/Unit/Expectations/OppositeExpectation.php +++ b/tests/Unit/Expectations/OppositeExpectation.php @@ -1,5 +1,7 @@ toBe($arguments); }); -test('popArgument preserves duplicate values when removing an existing argument', function () { +test('popArgument preserves duplicate values when removing an existing argument', function (): void { $obj = new class { use HandleArguments; diff --git a/tests/Unit/Plugins/Environment.php b/tests/Unit/Plugins/Environment.php index 0107ed4b..c7303bc3 100644 --- a/tests/Unit/Plugins/Environment.php +++ b/tests/Unit/Plugins/Environment.php @@ -2,7 +2,7 @@ use Pest\Plugins\Environment; -test('environment is set to CI when --ci option is used', function () { +test('environment is set to CI when --ci option is used', function (): void { $previousName = Environment::name(); $plugin = new Environment; @@ -14,7 +14,7 @@ test('environment is set to CI when --ci option is used', function () { Environment::name($previousName); }); -test('environment is set to Local when --ci option is not used', function () { +test('environment is set to Local when --ci option is not used', function (): void { $plugin = new Environment; $plugin->handleArguments(['foo', 'bar', 'baz']); diff --git a/tests/Unit/Plugins/Retry.php b/tests/Unit/Plugins/Retry.php index 5649aeb0..c8fe996a 100644 --- a/tests/Unit/Plugins/Retry.php +++ b/tests/Unit/Plugins/Retry.php @@ -2,7 +2,7 @@ use Pest\Plugins\Retry; -it('orders by defects and stop on defects if when --retry is used ', function () { +it('orders by defects and stop on defects if when --retry is used ', function (): void { $retry = new Retry; $arguments = $retry->handleArguments(['--retry']); diff --git a/tests/Unit/Plugins/Shard.php b/tests/Unit/Plugins/Shard.php index 347a3035..f31b2cc1 100644 --- a/tests/Unit/Plugins/Shard.php +++ b/tests/Unit/Plugins/Shard.php @@ -5,8 +5,8 @@ use Pest\Plugins\Shard; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Output\BufferedOutput; -describe('getShard', function () { - it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal) { +describe('getShard', function (): void { + it('parses valid shard format', function (string $format, int $expectedIndex, int $expectedTotal): void { $input = new ArgvInput(['test', '--shard', $format]); $result = Shard::getShard($input); @@ -25,7 +25,7 @@ describe('getShard', function () { ['5/100', 5, 100], ]); - it('throws exception for invalid format', function (array $arguments) { + it('throws exception for invalid format', function (array $arguments): void { $input = new ArgvInput($arguments); Shard::getShard($input); @@ -38,7 +38,7 @@ describe('getShard', function () { [['test', '--shard', '1.5/2']], ])->throws(InvalidOption::class); - it('throws exception for invalid index or total values', function (array $arguments) { + it('throws exception for invalid index or total values', function (array $arguments): void { $input = new ArgvInput($arguments); Shard::getShard($input); @@ -50,8 +50,8 @@ describe('getShard', function () { ])->throws(InvalidOption::class); }); -describe('buildFilterArgument', function () { - it('generates compact filter for single test', function () { +describe('buildFilterArgument', function (): void { + it('generates compact filter for single test', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -63,7 +63,7 @@ describe('buildFilterArgument', function () { expect($filter)->toBe('Tests\\\\Unit\\\\ExampleTest'); }); - it('generates compact filter for multiple tests with common prefix', function () { + it('generates compact filter for multiple tests with common prefix', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -78,7 +78,7 @@ describe('buildFilterArgument', function () { expect($filter)->toBe('Tests\\\\Unit\\\\Foo\\\\(BarTest|BazTest)'); }); - it('generates compact filter for tests with different namespaces', function () { + it('generates compact filter for tests with different namespaces', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -93,7 +93,7 @@ describe('buildFilterArgument', function () { expect($filter)->toBe('Tests\\\\(Unit\\\\FooTest|Feature\\\\BarTest)'); }); - it('returns empty string for empty test list', function () { + it('returns empty string for empty test list', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -102,10 +102,10 @@ describe('buildFilterArgument', function () { $filter = $method->invoke($shard, []); - expect($filter)->toBe(''); + expect($filter)->toBeEmpty(); }); - it('generates compact filter for deeply nested namespaces', function () { + it('generates compact filter for deeply nested namespaces', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -121,7 +121,7 @@ describe('buildFilterArgument', function () { expect($filter)->toBe('Tests\\\\Unit\\\\Plugins\\\\Concerns\\\\(Foo|Bar|Baz)'); }); - it('handles mix of nested and flat namespaces', function () { + it('handles mix of nested and flat namespaces', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -142,8 +142,8 @@ describe('buildFilterArgument', function () { }); }); -describe('ensureFilterLengthIsSafe', function () { - it('accepts filter within length limit', function () { +describe('ensureFilterLengthIsSafe', function (): void { + it('accepts filter within length limit', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -157,7 +157,7 @@ describe('ensureFilterLengthIsSafe', function () { expect(true)->toBeTrue(); }); - it('throws exception when filter exceeds default limit', function () { + it('throws exception when filter exceeds default limit', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -169,7 +169,7 @@ describe('ensureFilterLengthIsSafe', function () { $method->invoke($shard, $filter); })->throws(InvalidOption::class, 'The generated filter for this shard is too long'); - it('respects custom limit from environment variable', function () { + it('respects custom limit from environment variable', function (): void { putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000'); $output = new BufferedOutput; @@ -191,7 +191,7 @@ describe('ensureFilterLengthIsSafe', function () { } }); - it('accepts filter within custom limit', function () { + it('accepts filter within custom limit', function (): void { putenv('PEST_SHARD_MAX_FILTER_LENGTH=1000'); $output = new BufferedOutput; @@ -213,8 +213,8 @@ describe('ensureFilterLengthIsSafe', function () { }); }); -describe('handleArguments', function () { - it('returns original arguments when shard option is not present', function () { +describe('handleArguments', function (): void { + it('returns original arguments when shard option is not present', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -225,7 +225,7 @@ describe('handleArguments', function () { expect($result)->toBe($arguments); }); - it('removes parallel arguments from test discovery', function () { + it('removes parallel arguments from test discovery', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -240,8 +240,8 @@ describe('handleArguments', function () { }); }); -describe('parseListTestsOutput', function () { - it('parses Tests\\ namespaced classes from --list-tests output', function () { +describe('parseListTestsOutput', function (): void { + it('parses Tests\\ namespaced classes from --list-tests output', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -262,7 +262,7 @@ OUT; ]); }); - it('deduplicates repeated class names from multiple test methods', function () { + it('deduplicates repeated class names from multiple test methods', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -278,18 +278,18 @@ OUT; expect($method->invoke($shard, $listOutput))->toBe(['Tests\\Same']); }); - it('returns an empty list for output with no matching lines', function () { + it('returns an empty list for output with no matching lines', function (): void { $output = new BufferedOutput; $shard = new Shard($output); $reflection = new ReflectionClass($shard); $method = $reflection->getMethod('parseListTestsOutput'); - expect($method->invoke($shard, ''))->toBe([]) - ->and($method->invoke($shard, 'some random text'))->toBe([]); + expect($method->invoke($shard, ''))->toBeEmpty() + ->and($method->invoke($shard, 'some random text'))->toBeEmpty(); }); - it('parses non-Tests namespaced classes', function () { + it('parses non-Tests namespaced classes', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -309,7 +309,7 @@ OUT; ]); }); - it('parses unnamespaced top-level classes', function () { + it('parses unnamespaced top-level classes', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -319,7 +319,7 @@ OUT; expect($method->invoke($shard, ' - P\FooTest::test_bar'))->toBe(['FooTest']); }); - it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function () { + it('strips the P\\ Pest prefix but keeps the rest of the FQCN', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -337,7 +337,7 @@ OUT; ]); }); - it('ignores junk lines that lack the " - …::" framing', function () { + it('ignores junk lines that lack the " - …::" framing', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -356,8 +356,8 @@ OUT; }); }); -describe('buildListTestsCommand', function () { - it('builds the list-tests command with the forwarded --test-directory', function () { +describe('buildListTestsCommand', function (): void { + it('builds the list-tests command with the forwarded --test-directory', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -375,7 +375,7 @@ describe('buildListTestsCommand', function () { ]); }); - it('strips --parallel and -p when building the list-tests command', function () { + it('strips --parallel and -p when building the list-tests command', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -393,7 +393,7 @@ describe('buildListTestsCommand', function () { ]); }); - it('forwards --test-directory even when input arguments include one', function () { + it('forwards --test-directory even when input arguments include one', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -405,7 +405,7 @@ describe('buildListTestsCommand', function () { expect($command)->toContain('--test-directory=suites'); }); - it('strips --processes=N when building the list-tests command', function () { + it('strips --processes=N when building the list-tests command', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -423,7 +423,7 @@ describe('buildListTestsCommand', function () { ]); }); - it('strips --processes N (space-separated) when building the list-tests command', function () { + it('strips --processes N (space-separated) when building the list-tests command', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -438,8 +438,8 @@ describe('buildListTestsCommand', function () { }); }); -describe('addOutput', function () { - it('displays shard information after test execution', function () { +describe('addOutput', function (): void { + it('displays shard information after test execution', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -462,7 +462,7 @@ describe('addOutput', function () { ->and($outputText)->toContain('out of 100'); }); - it('uses singular form for single test file', function () { + it('uses singular form for single test file', function (): void { $output = new BufferedOutput; $shard = new Shard($output); @@ -482,7 +482,7 @@ describe('addOutput', function () { ->and($outputText)->not->toContain('1 files'); }); - it('returns original exit code when shard is not set', function () { + it('returns original exit code when shard is not set', function (): void { $output = new BufferedOutput; $shard = new Shard($output); diff --git a/tests/Unit/Plugins/Tia/ContentHash.php b/tests/Unit/Plugins/Tia/ContentHash.php index 6b235167..f81f3edb 100644 --- a/tests/Unit/Plugins/Tia/ContentHash.php +++ b/tests/Unit/Plugins/Tia/ContentHash.php @@ -2,12 +2,12 @@ use Pest\Plugins\Tia\ContentHash; -describe('of()', function () { - it('returns false when file does not exist', function () { +describe('of()', function (): void { + it('returns false when file does not exist', function (): void { expect(ContentHash::of('/path/that/does/not/exist.php'))->toBeFalse(); }); - it('hashes an existing file', function () { + it('hashes an existing file', function (): void { $path = tempnam(sys_get_temp_dir(), 'pest_').'.php'; file_put_contents($path, "toBe($b); }); - it('ignores single-line comments', function () { + it('ignores single-line comments', function (): void { $a = ContentHash::ofContent('a.php', "toBe($b); }); - it('ignores hash-style comments', function () { + it('ignores hash-style comments', function (): void { $a = ContentHash::ofContent('a.php', "toBe($b); }); - it('ignores multi-line comments', function () { + it('ignores multi-line comments', function (): void { $a = ContentHash::ofContent('a.php', "toBe($b); }); - it('ignores doc comments', function () { + it('ignores doc comments', function (): void { $a = ContentHash::ofContent('a.php', "toBe($b); }); - it('detects code changes', function () { + it('detects code changes', function (): void { $a = ContentHash::ofContent('a.php', 'not->toBe($b); }); - it('preserves whitespace inside string literals', function () { + it('preserves whitespace inside string literals', function (): void { $a = ContentHash::ofContent('a.php', "not->toBe($b); }); - it('treats variable renames as a change', function () { + it('treats variable renames as a change', function (): void { $a = ContentHash::ofContent('a.php', 'not->toBe($b); }); - it('falls back to a raw hash for unparseable PHP', function () { + it('falls back to a raw hash for unparseable PHP', function (): void { $hash = ContentHash::ofContent('a.php', 'not valid php at all'); expect($hash)->toBeString()->not->toBeEmpty(); }); - it('is case-insensitive on the file extension', function () { + it('is case-insensitive on the file extension', function (): void { $a = ContentHash::ofContent('a.PHP', "{{-- a comment --}}Hello
'); $b = ContentHash::ofContent('a.blade.php', '
Hello
'); expect($a)->toBe($b); }); - it('strips multi-line blade comments', function () { + it('strips multi-line blade comments', function (): void { $a = ContentHash::ofContent('a.blade.php', "
\n{{--\n multi\n line\n--}}\nHello\n
"); $b = ContentHash::ofContent('a.blade.php', '
Hello
'); expect($a)->toBe($b); }); - it('collapses whitespace', function () { + it('collapses whitespace', function (): void { $a = ContentHash::ofContent('a.blade.php', "
\n Hello\n World\n
"); $b = ContentHash::ofContent('a.blade.php', '
Hello World
'); expect($a)->toBe($b); }); - it('detects content changes', function () { + it('detects content changes', function (): void { $a = ContentHash::ofContent('a.blade.php', '
Hello
'); $b = ContentHash::ofContent('a.blade.php', '
Goodbye
'); expect($a)->not->toBe($b); }); - it('keeps blade directives intact', function () { + it('keeps blade directives intact', function (): void { $a = ContentHash::ofContent('a.blade.php', '@if($user)Hi @endif'); $b = ContentHash::ofContent('a.blade.php', '@if($user)Bye @endif'); expect($a)->not->toBe($b); }); - it('does not use the PHP tokenizer for blade files', function () { + it('does not use the PHP tokenizer for blade files', function (): void { $a = ContentHash::ofContent('a.blade.php', ' hello'); $b = ContentHash::ofContent('a.blade.php', ' hello'); @@ -134,78 +134,78 @@ describe('Blade files', function () { }); }); -describe('JavaScript-like files', function () { - it('strips line comments', function () { +describe('JavaScript-like files', function (): void { + it('strips line comments', function (): void { $a = ContentHash::ofContent('a.js', "// a comment\nconst foo = 1;"); $b = ContentHash::ofContent('a.js', 'const foo = 1;'); expect($a)->toBe($b); }); - it('strips block comments on their own lines', function () { + it('strips block comments on their own lines', function (): void { $a = ContentHash::ofContent('a.js', "/* block */\nconst foo = 1;"); $b = ContentHash::ofContent('a.js', 'const foo = 1;'); expect($a)->toBe($b); }); - it('collapses whitespace', function () { + it('collapses whitespace', function (): void { $a = ContentHash::ofContent('a.js', "const foo = 1;\n\nconst bar = 2;"); $b = ContentHash::ofContent('a.js', 'const foo = 1; const bar = 2;'); expect($a)->toBe($b); }); - it('detects code changes', function () { + it('detects code changes', function (): void { $a = ContentHash::ofContent('a.js', 'const foo = 1;'); $b = ContentHash::ofContent('a.js', 'const foo = 2;'); expect($a)->not->toBe($b); }); - it('does not strip inline trailing comments', function () { + it('does not strip inline trailing comments', function (): void { $a = ContentHash::ofContent('a.js', 'const foo = 1; // inline'); $b = ContentHash::ofContent('a.js', 'const foo = 1;'); expect($a)->not->toBe($b); }); - it('applies the same rules to .ts files', function () { + it('applies the same rules to .ts files', function (): void { $a = ContentHash::ofContent('a.ts', "// comment\nconst foo: number = 1;"); $b = ContentHash::ofContent('a.ts', 'const foo: number = 1;'); expect($a)->toBe($b); }); - it('applies the same rules to .tsx files', function () { + it('applies the same rules to .tsx files', function (): void { $a = ContentHash::ofContent('a.tsx', "// comment\nconst Foo = () =>
;"); $b = ContentHash::ofContent('a.tsx', 'const Foo = () =>
;'); expect($a)->toBe($b); }); - it('applies the same rules to .jsx files', function () { + it('applies the same rules to .jsx files', function (): void { $a = ContentHash::ofContent('a.jsx', "// comment\nconst Foo = () =>
;"); $b = ContentHash::ofContent('a.jsx', 'const Foo = () =>
;'); expect($a)->toBe($b); }); - it('applies the same rules to .vue files', function () { + it('applies the same rules to .vue files', function (): void { $a = ContentHash::ofContent('a.vue', ""); $b = ContentHash::ofContent('a.vue', ''); expect($a)->toBe($b); }); - it('applies the same rules to .svelte files', function () { + it('applies the same rules to .svelte files', function (): void { $a = ContentHash::ofContent('a.svelte', ""); $b = ContentHash::ofContent('a.svelte', ''); expect($a)->toBe($b); }); - it('applies the same rules to .mjs, .cjs, and .mts files', function () { + it('applies the same rules to .mjs, .cjs, and .mts files', function (): void { foreach (['mjs', 'cjs', 'mts'] as $ext) { $a = ContentHash::ofContent("a.$ext", "// comment\nexport const foo = 1;"); $b = ContentHash::ofContent("a.$ext", 'export const foo = 1;'); @@ -215,29 +215,29 @@ describe('JavaScript-like files', function () { }); }); -describe('unknown extensions', function () { - it('hashes the raw content for unknown extensions', function () { +describe('unknown extensions', function (): void { + it('hashes the raw content for unknown extensions', function (): void { $a = ContentHash::ofContent('a.txt', 'hello world'); $b = ContentHash::ofContent('a.txt', 'hello world'); expect($a)->toBe($b); }); - it('does not normalise whitespace for unknown extensions', function () { + it('does not normalise whitespace for unknown extensions', function (): void { $a = ContentHash::ofContent('a.txt', 'hello world'); $b = ContentHash::ofContent('a.txt', 'hello world'); expect($a)->not->toBe($b); }); - it('does not strip comments for unknown extensions', function () { + it('does not strip comments for unknown extensions', function (): void { $a = ContentHash::ofContent('a.txt', "// not a comment here\nhello"); $b = ContentHash::ofContent('a.txt', 'hello'); expect($a)->not->toBe($b); }); - it('hashes files with no extension as raw content', function () { + it('hashes files with no extension as raw content', function (): void { $a = ContentHash::ofContent('Makefile', "all:\n\techo hi"); $b = ContentHash::ofContent('Makefile', "all:\n\techo hi"); @@ -245,14 +245,14 @@ describe('unknown extensions', function () { }); }); -describe('output format', function () { - it('returns a 32-character hex xxh128 hash', function () { +describe('output format', function (): void { + it('returns a 32-character hex xxh128 hash', function (): void { $hash = ContentHash::ofContent('a.php', 'toMatch('/^[a-f0-9]{32}$/'); }); - it('returns a stable hash for empty content', function () { + it('returns a stable hash for empty content', function (): void { $a = ContentHash::ofContent('a.php', ''); $b = ContentHash::ofContent('a.php', ''); diff --git a/tests/Unit/Plugins/Tia/IsEnabledForRun.php b/tests/Unit/Plugins/Tia/IsEnabledForRun.php index cbcf6284..b65ab479 100644 --- a/tests/Unit/Plugins/Tia/IsEnabledForRun.php +++ b/tests/Unit/Plugins/Tia/IsEnabledForRun.php @@ -2,7 +2,7 @@ use Pest\Plugins\Tia; -test('does not throw when an integer --random-order-seed is passed as a separate argv element', function () { +test('does not throw when an integer --random-order-seed is passed as a separate argv element', function (): void { // Mirrors the parallel worker argv (see bin/worker.php), where // `--random-order-seed` and its value arrive as separate items and the // seed value is an int rather than a string. Regression test for the @@ -13,7 +13,7 @@ test('does not throw when an integer --random-order-seed is passed as a separate expect(Tia::isEnabledForRun($arguments))->toBeFalse(); }); -test('still detects --tia when an integer argument is present', function () { +test('still detects --tia when an integer argument is present', function (): void { $arguments = ['--tia', '--random-order-seed', 1782350398]; expect(Tia::isEnabledForRun($arguments))->toBeTrue(); diff --git a/tests/Unit/Plugins/Tia/Lockfiles/PackageLock.php b/tests/Unit/Plugins/Tia/Lockfiles/PackageLock.php new file mode 100644 index 00000000..f4700efc --- /dev/null +++ b/tests/Unit/Plugins/Tia/Lockfiles/PackageLock.php @@ -0,0 +1,121 @@ + json_encode([ + 'name' => $name ?? 'app', + 'lockfileVersion' => 3, + 'packages' => $packages, +])); + +it('applies only to package-lock.json', function (): void { + $handler = new PackageLock; + + expect($handler->applies('package-lock.json'))->toBeTrue() + ->and($handler->applies('pnpm-lock.yaml'))->toBeFalse() + ->and($handler->applies('yarn.lock'))->toBeFalse(); +}); + +it('returns null for contents that are not an npm lockfile', function (): void { + $handler = new PackageLock; + + expect($handler->fingerprint('not json'))->toBeNull() + ->and($handler->fingerprint('{"lockfileVersion":1}'))->toBeNull(); +}); + +it('is stable when the directory-derived top-level name changes', function () use ($lock): void { + $handler = new PackageLock; + $packages = ['node_modules/react' => ['version' => '19.0.0']]; + + expect($handler->fingerprint($lock($packages, 'app-a'))) + ->toBe($handler->fingerprint($lock($packages, 'app-b'))); +}); + +it('ignores platform-specific native binaries added or dropped per OS', function () use ($lock): void { + $handler = new PackageLock; + + $mac = $lock([ + 'node_modules/react' => ['version' => '19.0.0'], + 'node_modules/@rollup/rollup-darwin-arm64' => [ + 'version' => '4.9.5', 'os' => ['darwin'], 'cpu' => ['arm64'], 'optional' => true, + ], + ], 'app'); + + $linux = $lock([ + 'node_modules/react' => ['version' => '19.0.0'], + 'node_modules/@rollup/rollup-linux-x64-gnu' => [ + 'version' => '4.52.1', 'os' => ['linux'], 'cpu' => ['x64'], 'optional' => true, + ], + ], 'app'); + + expect($handler->fingerprint($mac))->toBe($handler->fingerprint($linux)); +}); + +it('ignores libc-constrained variants', function () use ($lock): void { + $handler = new PackageLock; + + $gnu = $lock([ + 'node_modules/lightningcss-linux-x64-gnu' => [ + 'version' => '1.32.0', 'os' => ['linux'], 'cpu' => ['x64'], 'libc' => ['glibc'], 'optional' => true, + ], + ]); + + expect($handler->fingerprint($gnu))->toBe($handler->fingerprint($lock([]))); +}); + +it('ignores runtime deps bundled beneath a platform-specific package', function () use ($lock): void { + $handler = new PackageLock; + + $withoutBundled = $lock([ + 'node_modules/react' => ['version' => '19.0.0'], + 'node_modules/@rolldown/binding-wasm32-wasi' => [ + 'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true, + ], + ]); + + $withBundled = $lock([ + 'node_modules/react' => ['version' => '19.0.0'], + 'node_modules/@rolldown/binding-wasm32-wasi' => [ + 'version' => '1.0.0', 'cpu' => ['wasm32'], 'optional' => true, + ], + 'node_modules/@rolldown/binding-wasm32-wasi/node_modules/@emnapi/core' => ['version' => '1.4.0'], + ]); + + expect($handler->fingerprint($withoutBundled))->toBe($handler->fingerprint($withBundled)); +}); + +it('detects a real dependency version change', function () use ($lock): void { + $handler = new PackageLock; + + $before = $lock(['node_modules/react' => ['version' => '19.0.0']]); + $after = $lock(['node_modules/react' => ['version' => '19.1.0']]); + + expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after)); +}); + +it('detects an added or removed non-platform dependency', function () use ($lock): void { + $handler = new PackageLock; + + $before = $lock(['node_modules/react' => ['version' => '19.0.0']]); + $after = $lock([ + 'node_modules/react' => ['version' => '19.0.0'], + 'node_modules/vue' => ['version' => '3.5.0'], + ]); + + expect($handler->fingerprint($before))->not->toBe($handler->fingerprint($after)); +}); + +it('is independent of package ordering', function () use ($lock): void { + $handler = new PackageLock; + + $a = $lock([ + 'node_modules/a' => ['version' => '1.0.0'], + 'node_modules/b' => ['version' => '2.0.0'], + ]); + $b = $lock([ + 'node_modules/b' => ['version' => '2.0.0'], + 'node_modules/a' => ['version' => '1.0.0'], + ]); + + expect($handler->fingerprint($a))->toBe($handler->fingerprint($b)); +}); diff --git a/tests/Unit/Plugins/Tia/ViteDepsHelper.php b/tests/Unit/Plugins/Tia/ViteDepsHelper.php index 8b02921f..b61f55c5 100644 --- a/tests/Unit/Plugins/Tia/ViteDepsHelper.php +++ b/tests/Unit/Plugins/Tia/ViteDepsHelper.php @@ -259,34 +259,34 @@ function tiaAliasResults(): array return $cache = ['roots' => $roots, 'aliases' => $aliases]; } -beforeEach(function () { +beforeEach(function (): void { if ((new ExecutableFinder)->find('node') === null) { $this->markTestSkipped('node is not available.'); } }); -it('strips JSONC down to something JSON.parse accepts', function (string $name) { +it('strips JSONC down to something JSON.parse accepts', function (string $name): void { $result = tiaStripResults()[$name]; [, $expected] = tiaStripFixtures()[$name]; expect($result['ok'])->toBeTrue( "[{$name}] did not parse after stripping: ".($result['error'] ?? 'unknown').PHP_EOL. 'stripped: '.$result['stripped'], - ); - expect($result['parsed'])->toEqual($expected); + ) + ->and($result['parsed'])->toEqual($expected); })->with(array_keys(tiaStripFixtures())); -it('never touches comment-looking sequences inside string values', function () { +it('never touches comment-looking sequences inside string values', function (): void { expect(tiaStripResults()['url-in-string']['stripped'])->toContain('https://example.com//x') ->and(tiaStripResults()['glob-in-string']['stripped'])->toContain('resources/js/**/*.ts') ->and(tiaStripResults()['block-both-in-string']['stripped'])->toContain('x/*y*/z'); }); -it('removes the comment body entirely', function () { +it('removes the comment body entirely', function (): void { expect(tiaStripResults()['block-secret']['stripped'])->not->toContain('SECRET'); }); -it('builds the expected alias map from a tsconfig', function (string $name) { +it('builds the expected alias map from a tsconfig', function (string $name): void { $results = tiaAliasResults(); [, $expectedRelative] = tiaAliasFixtures()[$name]; diff --git a/tests/Unit/Preset.php b/tests/Unit/Preset.php index bdf461a7..f027c0e8 100644 --- a/tests/Unit/Preset.php +++ b/tests/Unit/Preset.php @@ -1,12 +1,10 @@ presets()->custom('myFramework', function (array $userNamespaces) { - return [ - expect($userNamespaces)->toBe(['Pest']), - ]; -}); +pest()->presets()->custom('myFramework', fn (array $userNamespaces): array => [ + expect($userNamespaces)->toBe(['Pest']), +]); -test('preset invalid name', function () { +test('preset invalid name', function (): void { $this->preset()->myAnotherFramework(); })->throws(InvalidArgumentException::class, 'The preset [myAnotherFramework] does not exist. The available presets are [php, laravel, strict, security, relaxed, myFramework].'); diff --git a/tests/Unit/Support/Arr.php b/tests/Unit/Support/Arr.php index 6dc6f3bb..c4667a1c 100644 --- a/tests/Unit/Support/Arr.php +++ b/tests/Unit/Support/Arr.php @@ -1,49 +1,51 @@ toBeFalse(); }); - it('should return the last element for an array with a single element', function () { + it('should return the last element for an array with a single element', function (): void { expect(Arr::last([1]))->toBe(1); }); - it('should return the last element for an array without changing the internal pointer', function () { + it('should return the last element for an array without changing the internal pointer', function (): void { $array = [1, 2, 3]; - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(1); + expect(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(1); next($array); - expect(current($array))->toBe(2); - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(2); + expect(current($array))->toBe(2) + ->and(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(2); }); - it('should return the last element for an associative array without changing the internal pointer', function () { + it('should return the last element for an associative array without changing the internal pointer', function (): void { $array = ['first' => 1, 'second' => 2, 'third' => 3]; - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(1); + expect(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(1); next($array); - expect(current($array))->toBe(2); - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(2); + expect(current($array))->toBe(2) + ->and(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(2); }); - it('should return the last element for an mixed key array without changing the internal pointer', function () { + it('should return the last element for an mixed key array without changing the internal pointer', function (): void { $array = ['first' => 1, 2, 'third' => 3]; - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(1); + expect(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(1); next($array); - expect(current($array))->toBe(2); - expect(Arr::last($array))->toBe(3); - expect(current($array))->toBe(2); + expect(current($array))->toBe(2) + ->and(Arr::last($array))->toBe(3) + ->and(current($array))->toBe(2); }); }); diff --git a/tests/Unit/Support/Backtrace.php b/tests/Unit/Support/Backtrace.php index 6dba0ed5..0e04a678 100644 --- a/tests/Unit/Support/Backtrace.php +++ b/tests/Unit/Support/Backtrace.php @@ -2,10 +2,8 @@ use Pest\Support\Backtrace; -it('gets file name from called file', function () { - $a = function () { - return Backtrace::file(); - }; +it('gets file name from called file', function (): void { + $a = (fn (): string => Backtrace::file()); expect($a())->toBe(__FILE__); }); diff --git a/tests/Unit/Support/Container.php b/tests/Unit/Support/Container.php index 28b886a9..20880def 100644 --- a/tests/Unit/Support/Container.php +++ b/tests/Unit/Support/Container.php @@ -6,37 +6,37 @@ use Pest\TestSuite; pest()->group('container'); -beforeEach(function () { +beforeEach(function (): void { $this->container = new Container; }); it('exists') ->assertTrue(class_exists(Container::class)); -it('gets an instance', function () { +it('gets an instance', function (): void { $this->container->add(Container::class, $this->container); expect($this->container->get(Container::class))->toBe($this->container); }); -test('autowire', function () { +test('autowire', function (): void { expect($this->container->get(Container::class))->toBeInstanceOf(Container::class); }); -it('creates an instance and resolves parameters', function () { +it('creates an instance and resolves parameters', function (): void { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithDependency::class); expect($instance)->toBeInstanceOf(ClassWithDependency::class); }); -it('creates an instance and resolves also sub parameters', function () { +it('creates an instance and resolves also sub parameters', function (): void { $this->container->add(Container::class, $this->container); $instance = $this->container->get(ClassWithSubDependency::class); expect($instance)->toBeInstanceOf(ClassWithSubDependency::class); }); -it('can resolve builtin value types', function () { +it('can resolve builtin value types', function (): void { $this->container->add('rootPath', getcwd()); $this->container->add('testPath', 'tests'); @@ -44,7 +44,7 @@ it('can resolve builtin value types', function () { expect($instance)->toBeInstanceOf(TestSuite::class); }); -it('cannot resolve a parameter without type', function () { +it('cannot resolve a parameter without type', function (): void { $this->container->get(ClassWithoutTypeParameter::class); })->throws(ShouldNotHappen::class); diff --git a/tests/Unit/Support/DatasetInfo.php b/tests/Unit/Support/DatasetInfo.php index 4feb6121..4b67fa22 100644 --- a/tests/Unit/Support/DatasetInfo.php +++ b/tests/Unit/Support/DatasetInfo.php @@ -1,8 +1,10 @@ toBe($inside); })->with([ ['file' => '/var/www/Datasets/project/tests/Datasets/Nested/Numbers.php', 'inside' => true], @@ -17,7 +19,7 @@ it('can check if dataset is defined inside a Datasets directory', function (stri ['file' => '/var/www/project/tests/Features/Datasets.php', 'inside' => false], ]); -it('can check if dataset is defined inside a Datasets.php file', function (string $file, bool $inside) { +it('can check if dataset is defined inside a Datasets.php file', function (string $file, bool $inside): void { expect(DatasetInfo::isADatasetsFile($file))->toBe($inside); })->with([ ['file' => '/var/www/project/tests/Datasets/Numbers.php', 'inside' => false], @@ -27,7 +29,7 @@ it('can check if dataset is defined inside a Datasets.php file', function (strin ['file' => '/var/www/project/tests/Features/Datasets.php', 'inside' => true], ]); -it('computes the dataset scope', function (string $file, string $scope) { +it('computes the dataset scope', function (string $file, string $scope): void { expect(DatasetInfo::scope($file))->toBe($scope); })->with([ ['file' => '/var/www/Datasets/project/tests/Datasets/Nested/Numbers.php', 'scope' => '/var/www/Datasets/project/tests'], diff --git a/tests/Unit/Support/ExceptionTrace.php b/tests/Unit/Support/ExceptionTrace.php index 40464168..9622af16 100644 --- a/tests/Unit/Support/ExceptionTrace.php +++ b/tests/Unit/Support/ExceptionTrace.php @@ -2,8 +2,8 @@ use Pest\Support\ExceptionTrace; -it('ensures the given closures reports the correct class name', function () { - $closure = function () { +it('ensures the given closures reports the correct class name', function (): void { + $closure = function (): void { throw new Exception('Call to undefined method P\Tests\IntentionallyNotExisting::testBasic().'); }; @@ -13,7 +13,7 @@ it('ensures the given closures reports the correct class name', function () { 'Call to undefined method Tests\IntentionallyNotExisting::testBasic().', ); -it('ensures the given closures reports the correct class name and suggests the [pest()] function', function () { +it('ensures the given closures reports the correct class name and suggests the [pest()] function', function (): void { $this->get(); })->throws( Error::class, diff --git a/tests/Unit/Support/HigherOrderMessage.php b/tests/Unit/Support/HigherOrderMessage.php index 35e23078..cd480600 100644 --- a/tests/Unit/Support/HigherOrderMessage.php +++ b/tests/Unit/Support/HigherOrderMessage.php @@ -2,7 +2,7 @@ use Pest\Support\HigherOrderMessage; -test('undefined method exceptions', function () { +test('undefined method exceptions', function (): void { $message = new HigherOrderMessage( __FILE__, 1, @@ -10,7 +10,7 @@ test('undefined method exceptions', function () { [] ); - expect(fn () => $message->call($this))->toThrow(function (ReflectionException $exception) { + expect(fn () => $message->call($this))->toThrow(function (ReflectionException $exception): void { expect($exception) ->getMessage()->toBe('Call to undefined method PHPUnit\Framework\TestCase::foqwdqwd()') ->getLine()->toBe(1) diff --git a/tests/Unit/Support/Reflection.php b/tests/Unit/Support/Reflection.php index 7b976458..fa73e037 100644 --- a/tests/Unit/Support/Reflection.php +++ b/tests/Unit/Support/Reflection.php @@ -2,16 +2,16 @@ use Pest\Support\Reflection; -it('gets file name from closure', function () { - $fileName = Reflection::getFileNameFromClosure(function () {}); +it('gets file name from closure', function (): void { + $fileName = Reflection::getFileNameFromClosure(function (): void {}); expect($fileName)->toBe(__FILE__); }); -it('gets property values', function () { +it('gets property values', function (): void { $class = new class { - private $foo = 'bar'; + private string $foo = 'bar'; }; $value = Reflection::getPropertyValue($class, 'foo'); @@ -51,24 +51,24 @@ class Qwe extends Asd } } -it('gets properties from classes', function () { +it('gets properties from classes', function (): void { $reflectionClass = new ReflectionClass(Qwe::class); $properties = Reflection::getPropertiesFromReflectionClass($reflectionClass); - $properties = array_map(fn ($property) => $property->getName(), $properties); + $properties = array_map(fn (ReflectionProperty $property) => $property->getName(), $properties); expect($properties)->toBe([ 'bar', ]); }); -it('gets methods from classes', function () { +it('gets methods from classes', function (): void { $reflectionClass = new ReflectionClass(Qwe::class); $methods = Reflection::getMethodsFromReflectionClass($reflectionClass); - $methods = array_map(fn ($method) => $method->getName(), $methods); + $methods = array_map(fn (ReflectionMethod $method) => $method->getName(), $methods); expect($methods)->toBe([ 'getBar', diff --git a/tests/Unit/Support/Str.php b/tests/Unit/Support/Str.php index 4d865c86..bef9d15b 100644 --- a/tests/Unit/Support/Str.php +++ b/tests/Unit/Support/Str.php @@ -1,8 +1,10 @@ toBe($expected); diff --git a/tests/Unit/TestName.php b/tests/Unit/TestName.php index b65be16f..24a36020 100644 --- a/tests/Unit/TestName.php +++ b/tests/Unit/TestName.php @@ -1,6 +1,6 @@ toBe($toBePrinted); diff --git a/tests/Unit/TestSuite.php b/tests/Unit/TestSuite.php index 93c8a294..407ada1d 100644 --- a/tests/Unit/TestSuite.php +++ b/tests/Unit/TestSuite.php @@ -6,7 +6,7 @@ use Pest\Exceptions\TestClosureMustNotBeStatic; use Pest\Factories\TestCaseMethodFactory; use Pest\TestSuite; -it('does not allow to add the same test description twice', function () { +it('does not allow to add the same test description twice', function (): void { $testSuite = new TestSuite(getcwd(), 'tests'); $method = new TestCaseMethodFactory('foo', null); $method->description = 'bar'; @@ -18,10 +18,10 @@ it('does not allow to add the same test description twice', function () { sprintf('A test with the description `%s` already exists in the filename `%s`.', 'bar', 'foo'), ); -it('does not allow static closures', function () { +it('does not allow static closures', function (): void { $testSuite = new TestSuite(getcwd(), 'tests'); - $method = new TestCaseMethodFactory('foo', static function () {}); + $method = new TestCaseMethodFactory('foo', static function (): void {}); $method->description = 'bar'; $testSuite->tests->set($method); @@ -30,10 +30,10 @@ it('does not allow static closures', function () { 'Test closure must not be static. Please remove the [static] keyword from the [bar] method in [foo].', ); -it('alerts users about tests with arguments but no input', function () { +it('alerts users about tests with arguments but no input', function (): void { $testSuite = new TestSuite(getcwd(), 'tests'); - $method = new TestCaseMethodFactory('foo', function (int $arg) {}); + $method = new TestCaseMethodFactory('foo', function (int $arg): void {}); $method->description = 'bar'; @@ -43,7 +43,7 @@ it('alerts users about tests with arguments but no input', function () { sprintf('A test with the description [%s] has [%d] argument(s) ([%s]) and no dataset(s) provided in [%s]', 'bar', 1, 'int $arg', 'foo'), ); -it('can return an array of all test suite filenames', function () { +it('can return an array of all test suite filenames', function (): void { $testSuite = new TestSuite(getcwd(), 'tests'); $method = new TestCaseMethodFactory('a', null); diff --git a/tests/Visual/BeforeEachTestName.php b/tests/Visual/BeforeEachTestName.php index 7206ec8c..41de7914 100644 --- a/tests/Visual/BeforeEachTestName.php +++ b/tests/Visual/BeforeEachTestName.php @@ -1,14 +1,14 @@ description = $this->__description; $this->latestDescription = self::$__latestDescription; }); -test('description', function () { +test('description', function (): void { expect($this->description)->toBe('description'); }); -test('latest description', function () { +test('latest description', function (): void { expect($this->latestDescription)->toBe('latest description'); }); diff --git a/tests/Visual/Collision.php b/tests/Visual/Collision.php index 99870cac..3ab4c5aa 100644 --- a/tests/Visual/Collision.php +++ b/tests/Visual/Collision.php @@ -2,12 +2,12 @@ use Symfony\Component\Process\Process; -test('collision', function (array $arguments) { - $output = function () use ($arguments) { +test('collision', function (array $arguments): void { + $output = function () use ($arguments): ?string { $process = (new Process( array_merge(['php', 'bin/pest', 'tests/Fixtures/CollisionTest.php'], $arguments), null, - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'COLLISION_TEST' => true] + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'COLLISION_TEST' => true, 'PAO_DISABLE' => '1'] )); $process->run(); @@ -15,7 +15,7 @@ test('collision', function (array $arguments) { return removeAnsiEscapeSequences($process->getOutput()); }; - $outputContent = explode("\n", $output()); + $outputContent = explode("\n", (string) $output()); array_pop($outputContent); array_pop($outputContent); array_pop($outputContent); diff --git a/tests/Visual/Help.php b/tests/Visual/Help.php index 35b25989..15c84154 100644 --- a/tests/Visual/Help.php +++ b/tests/Visual/Help.php @@ -2,9 +2,9 @@ use Symfony\Component\Process\Process; -test('visual snapshot of help command output', function () { - $output = function () { - $process = (new Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'])); +test('visual snapshot of help command output', function (): void { + $output = function (): ?string { + $process = (new Process(['php', 'bin/pest', '--help'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'])); $process->run(); diff --git a/tests/Visual/JUnit.php b/tests/Visual/JUnit.php index 74cfe584..3da70804 100644 --- a/tests/Visual/JUnit.php +++ b/tests/Visual/JUnit.php @@ -8,7 +8,7 @@ $run = function () { $process = new Process( array_merge(['php', 'bin/pest', '--log-junit', $junitLogFile], func_get_args()), dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -26,11 +26,9 @@ $run = function () { } }; -$normalizedPath = function (string $path) { - return str_replace('/', DIRECTORY_SEPARATOR, $path); -}; +$normalizedPath = (fn (string $path): string => str_replace('/', DIRECTORY_SEPARATOR, $path)); -test('junit output', function () use ($normalizedPath, $run) { +test('junit output', function () use ($normalizedPath, $run): void { $result = $run('tests/.tests/SuccessOnly.php'); expect($result['testsuite']['@attributes']) @@ -40,21 +38,12 @@ test('junit output', function () use ($normalizedPath, $run) { ->assertions->toBe('4') ->errors->toBe('0') ->failures->toBe('0') - ->skipped->toBe('0'); - - expect($result['testsuite']['testcase']) - ->toHaveCount(2); - - expect($result['testsuite']['testcase'][0]['@attributes']) - ->name->toBe('it can pass with comparison') - ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) - ->class->toBe('Tests\tests\SuccessOnly') - ->classname->toBe('Tests.tests.SuccessOnly') - ->assertions->toBe('1') - ->time->toStartWith('0.0'); + ->skipped->toBe('0') + ->and($result['testsuite']['testcase'])->toHaveCount(2) + ->and($result['testsuite']['testcase'][0]['@attributes'])->name->toBe('it can pass with comparison')->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison'))->class->toBe('Tests\tests\SuccessOnly')->classname->toBe('Tests.tests.SuccessOnly')->assertions->toBe('1')->time->toStartWith('0.0'); }); -test('junit with parallel', function () use ($normalizedPath, $run) { +test('junit with parallel', function () use ($normalizedPath, $run): void { $result = $run('tests/.tests/SuccessOnly.php', '--parallel', '--processes=1', '--filter', 'can pass with comparison'); expect($result['testsuite']['@attributes']) @@ -64,13 +53,6 @@ test('junit with parallel', function () use ($normalizedPath, $run) { ->assertions->toBe('1') ->errors->toBe('0') ->failures->toBe('0') - ->skipped->toBe('0'); - - expect($result['testsuite']['testcase']['@attributes']) - ->name->toBe('it can pass with comparison') - ->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison')) - ->class->toBe('Tests\tests\SuccessOnly') - ->classname->toBe('Tests.tests.SuccessOnly') - ->assertions->toBe('1') - ->time->toStartWith('0.0'); + ->skipped->toBe('0') + ->and($result['testsuite']['testcase']['@attributes'])->name->toBe('it can pass with comparison')->file->toBe($normalizedPath('tests/.tests/SuccessOnly.php::it can pass with comparison'))->class->toBe('Tests\tests\SuccessOnly')->classname->toBe('Tests.tests.SuccessOnly')->assertions->toBe('1')->time->toStartWith('0.0'); }); diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index c5a76f60..e249974a 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -2,11 +2,11 @@ use Symfony\Component\Process\Process; -$run = function () { +$run = function (): ?string { $process = new Process( array_merge(['php', 'bin/pest', '--parallel', '--processes=3'], func_get_args()), dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -14,9 +14,9 @@ $run = function () { return removeAnsiEscapeSequences($process->getOutput()); }; -test('parallel', function () use ($run) { +test('parallel', function () use ($run): void { $output = $run('--exclude-group=integration'); - $output = implode("\n", array_slice(explode("\n", $output), -10)); + $output = implode("\n", array_slice(explode("\n", (string) $output), -10)); if (getenv('REBUILD_SNAPSHOTS')) { preg_match('/Tests:\s+(.+\(\d+ assertions\))/', $output, $matches); @@ -24,37 +24,37 @@ test('parallel', function () use ($run) { $file = file_get_contents(__FILE__); $file = preg_replace( '/\$expected = \'.*?\';/', - "\$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1435 passed (3156 assertions)';", + "\$expected = '1 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1445 passed (3167 assertions)';", $file, ); file_put_contents(__FILE__, $file); } - $expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1435 passed (3156 assertions)'; + $expected = '1 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 27 skipped, 1445 passed (3167 assertions)'; expect($output) ->toContain("Tests: {$expected}") ->toContain('Parallel: 3 processes'); })->skipOnWindows(); -test('a parallel test can extend another test with same name', function () use ($run) { +test('a parallel test can extend another test with same name', function () use ($run): void { expect($run('tests/Fixtures/Inheritance'))->toContain('Tests: 1 skipped, 1 passed (1 assertions)'); })->skipOnWindows(); -test('parallel reports invalid datasets as failures', function () use ($run) { +test('parallel reports invalid datasets as failures', function () use ($run): void { expect($run('tests/.tests/ParallelInvalidDataset')) ->toContain("A dataset with the name `missing.dataset` does not exist. You can create it using `dataset('missing.dataset', ['a', 'b']);`.") ->toContain('Tests: 1 failed, 1 passed (1 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows(); -test('parallel can have multiple exclude-groups', function () use ($run) { +test('parallel can have multiple exclude-groups', function () use ($run): void { $singleExclude = $run('--exclude-group=integration'); $doubleExclude = $run('--exclude-group=integration', '--exclude-group=container'); - preg_match('/(\d+) passed/', $singleExclude, $singleMatch); - preg_match('/(\d+) passed/', $doubleExclude, $doubleMatch); + preg_match('/(\d+) passed/', (string) $singleExclude, $singleMatch); + preg_match('/(\d+) passed/', (string) $doubleExclude, $doubleMatch); - expect((int) $doubleMatch[1])->toBeLessThan((int) $singleMatch[1]); - expect($doubleExclude)->toContain('Parallel: 3 processes'); + expect((int) $doubleMatch[1])->toBeLessThan((int) $singleMatch[1]) + ->and($doubleExclude)->toContain('Parallel: 3 processes'); })->skipOnWindows(); diff --git a/tests/Visual/ParallelNestedDatasets.php b/tests/Visual/ParallelNestedDatasets.php index 37052556..86c9ab52 100644 --- a/tests/Visual/ParallelNestedDatasets.php +++ b/tests/Visual/ParallelNestedDatasets.php @@ -16,7 +16,7 @@ $run = function (bool $parallel = false): array { } $process = new Process($command, dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -27,7 +27,7 @@ $run = function (bool $parallel = false): array { ]; }; -test('parallel loads nested datasets from nested directories', function () use ($run) { +test('parallel loads nested datasets from nested directories', function () use ($run): void { $serial = $run(); $parallel = $run(true); diff --git a/tests/Visual/SingleTestOrDirectory.php b/tests/Visual/SingleTestOrDirectory.php index 63e29490..e7aeecfa 100644 --- a/tests/Visual/SingleTestOrDirectory.php +++ b/tests/Visual/SingleTestOrDirectory.php @@ -2,9 +2,9 @@ use Symfony\Component\Process\Process; -$run = function (string $target, $decorated = false) { +$run = function (string $target, $decorated = false): ?string { $process = new Process(['php', 'bin/pest', $target, '--colors=always'], dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -12,7 +12,7 @@ $run = function (string $target, $decorated = false) { return $decorated ? $process->getOutput() : removeAnsiEscapeSequences($process->getOutput()); }; -$snapshot = function ($name) { +$snapshot = function ($name): string|false { $testsPath = dirname(__DIR__); return file_get_contents(implode(DIRECTORY_SEPARATOR, [ @@ -22,21 +22,21 @@ $snapshot = function ($name) { ])); }; -test('allows to run a single test', function () use ($run, $snapshot) { +test('allows to run a single test', function () use ($run, $snapshot): void { expect($run('tests/Fixtures/DirectoryWithTests/ExampleTest.php'))->toContain($snapshot('allows-to-run-a-single-test')); })->skipOnWindows(); -test('allows to run a directory', function () use ($run, $snapshot) { +test('allows to run a directory', function () use ($run, $snapshot): void { expect($run('tests/Fixtures'))->toContain($snapshot('allows-to-run-a-directory')); })->skipOnWindows(); -it('disable decorating printer when colors is set to never', function () use ($snapshot) { +it('disable decorating printer when colors is set to never', function () use ($snapshot): void { $process = new Process([ 'php', './bin/pest', '--colors=never', 'tests/Fixtures/DirectoryWithTests/ExampleTest.php', - ], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']); + ], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1']); $process->run(); $output = $process->getOutput(); expect($output)->toContain($snapshot('disable-decorating-printer')); diff --git a/tests/Visual/Success.php b/tests/Visual/Success.php index cae012d2..3eeb9ec4 100644 --- a/tests/Visual/Success.php +++ b/tests/Visual/Success.php @@ -2,7 +2,7 @@ use Symfony\Component\Process\Process; -test('visual snapshot of test suite on success', function () { +test('visual snapshot of test suite on success', function (): void { $testsPath = dirname(__DIR__); $snapshot = implode(DIRECTORY_SEPARATOR, [ $testsPath, @@ -10,11 +10,11 @@ test('visual snapshot of test suite on success', function () { 'success.txt', ]); - $output = function () use ($testsPath) { + $output = function () use ($testsPath): ?string { $process = (new Process( - ['php', '-d', 'memory_limit=256M', 'bin/pest'], + ['php', '-d', 'memory_limit=-1', 'bin/pest'], dirname($testsPath), - ['EXCLUDE' => 'integration', '--exclude-group' => 'integration', 'REBUILD_SNAPSHOTS' => false, 'PARATEST' => 0, 'COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['EXCLUDE' => 'integration', '--exclude-group' => 'integration', 'REBUILD_SNAPSHOTS' => false, 'PARATEST' => 0, 'COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], )); $process->run(); @@ -31,14 +31,14 @@ test('visual snapshot of test suite on success', function () { }; if (getenv('REBUILD_SNAPSHOTS')) { - $outputContent = explode("\n", $output()); + $outputContent = explode("\n", (string) $output()); array_pop($outputContent); array_pop($outputContent); array_pop($outputContent); file_put_contents($snapshot, implode("\n", $outputContent)); } elseif (! getenv('EXCLUDE')) { - $output = explode("\n", $output()); + $output = explode("\n", (string) $output()); array_pop($output); array_pop($output); diff --git a/tests/Visual/TeamCity.php b/tests/Visual/TeamCity.php index 926f3957..a3a0efb6 100644 --- a/tests/Visual/TeamCity.php +++ b/tests/Visual/TeamCity.php @@ -9,7 +9,7 @@ function normalize_windows_os_output(string $text): string return str_replace('\\', '/', $text); } -test('visual snapshot of team city', function (string $testFile) { +test('visual snapshot of team city', function (string $testFile): void { $testsPath = dirname(__DIR__)."/.tests/$testFile"; $snapshot = implode(DIRECTORY_SEPARATOR, [ @@ -18,7 +18,7 @@ test('visual snapshot of team city', function (string $testFile) { "$testFile.inc", ]); - $output = function () use ($testsPath) { + $output = function () use ($testsPath): string { $process = (new Process( ['php', 'bin/pest', '--teamcity', $testsPath], dirname(__DIR__, levels: 2), @@ -28,6 +28,7 @@ test('visual snapshot of team city', function (string $testFile) { 'PARATEST' => 0, 'COLLISION_IGNORE_DURATION' => 'true', 'FLOW_ID' => '1234', + 'PAO_DISABLE' => '1', ], )); diff --git a/tests/Visual/Todo.php b/tests/Visual/Todo.php index 21b8963d..c93f3991 100644 --- a/tests/Visual/Todo.php +++ b/tests/Visual/Todo.php @@ -2,9 +2,9 @@ use Symfony\Component\Process\Process; -$run = function (string $target, bool $parallel) { +$run = function (string $target, bool $parallel): ?string { $process = new Process(['php', 'bin/pest', $target, $parallel ? '--parallel' : ''], dirname(__DIR__, 2), - ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'], + ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'], ); $process->run(); @@ -13,21 +13,21 @@ $run = function (string $target, bool $parallel) { $output = $process->getOutput(); - return preg_replace('/Duration: \d+\.\d+s/', 'Duration: x.xxs', removeAnsiEscapeSequences($output)); + return preg_replace('/Duration: \d+\.\d+s/', 'Duration: x.xxs', (string) removeAnsiEscapeSequences($output)); }; -test('todos', function () use ($run) { +test('todos', function () use ($run): void { expect($run('--todos', false))->toMatchSnapshot(); })->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')); -test('todos in parallel', function () use ($run) { +test('todos in parallel', function () use ($run): void { expect($run('--todos', true))->toMatchSnapshot(); })->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')); -test('todo', function () use ($run) { +test('todo', function () use ($run): void { expect($run('--todo', false))->toMatchSnapshot(); })->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')); -test('todo in parallel', function () use ($run) { +test('todo in parallel', function () use ($run): void { expect($run('--todo', true))->toMatchSnapshot(); })->skipOnWindows()->skip(! getenv('REBUILD_SNAPSHOTS') && getenv('EXCLUDE')); diff --git a/tests/Visual/UnicodeFilename.php b/tests/Visual/UnicodeFilename.php index d12ed20f..4fcf4ee2 100644 --- a/tests/Visual/UnicodeFilename.php +++ b/tests/Visual/UnicodeFilename.php @@ -1,37 +1,39 @@ 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']); + ], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1']); $process->run(); $output = $process->getOutput(); - expect($output)->toContain('StraßenTest'); - expect($output)->toContain('tests unicode filename'); - expect($output)->toContain('1 passed'); + expect($output)->toContain('StraßenTest') + ->toContain('tests unicode filename') + ->toContain('1 passed'); })->skipOnWindows(); -test('filter with unicode regex matches unicode filename', function () { +test('filter with unicode regex matches unicode filename', function (): void { $process = new Process([ 'php', 'bin/pest', '--filter=.*Straß.*', 'tests/.tests/', '--colors=never', - ], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true']); + ], dirname(__DIR__, 2), ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1']); $process->run(); $output = $process->getOutput(); - expect($output)->toContain('StraßenTest'); - expect($output)->toContain('1 passed'); + expect($output)->toContain('StraßenTest') + ->toContain('1 passed'); })->skipOnWindows(); diff --git a/tests/Visual/Version.php b/tests/Visual/Version.php index 0ce85109..1f923452 100644 --- a/tests/Visual/Version.php +++ b/tests/Visual/Version.php @@ -2,9 +2,9 @@ use Symfony\Component\Process\Process; -test('visual snapshot of help command output', function () { - $output = function () { - $process = (new Process(['php', 'bin/pest', '--version'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true'])); +test('visual snapshot of help command output', function (): void { + $output = function (): ?string { + $process = (new Process(['php', 'bin/pest', '--version'], null, ['COLLISION_PRINTER' => 'DefaultPrinter', 'COLLISION_IGNORE_DURATION' => 'true', 'PAO_DISABLE' => '1'])); $process->run();