diff --git a/src/Expectation.php b/src/Expectation.php index b54b9642..a410cf1d 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -32,6 +32,7 @@ use Pest\Support\ExpectationPipeline; use PHPUnit\Architecture\Elements\ObjectDescription; use PHPUnit\Framework\ExpectationFailedException; +use ReflectionEnum; /** * @template TValue @@ -890,9 +891,10 @@ private function toBeBackedEnum(string $backingType): ArchExpectation { return Targeted::make( $this, - fn (ObjectDescription $object): bool => (new \ReflectionEnum($object->name))->isBacked() - && (string)(new \ReflectionEnum($object->name))->getBackingType() === $backingType, - 'to be ' . $backingType . ' backed enum', + fn (ObjectDescription $object): bool => $object->reflectionClass->isEnum() + && (new ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line + && (string) (new ReflectionEnum($object->name))->getBackingType() === $backingType, // @phpstan-ignore-line + 'to be '.$backingType.' backed enum', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); } diff --git a/src/Expectations/OppositeExpectation.php b/src/Expectations/OppositeExpectation.php index 9a3399c2..57796f83 100644 --- a/src/Expectations/OppositeExpectation.php +++ b/src/Expectations/OppositeExpectation.php @@ -493,9 +493,10 @@ private function toBeBackedEnum(string $backingType): ArchExpectation { return Targeted::make( $this->original, - fn (ObjectDescription $object): bool => (new \ReflectionEnum($object->name))->isBacked() - && (string)(new \ReflectionEnum($object->name))->getBackingType() !== $backingType, - 'not to be ' . $backingType . ' backed enum', + fn (ObjectDescription $object): bool => ! $object->reflectionClass->isEnum() + || ! (new \ReflectionEnum($object->name))->isBacked() // @phpstan-ignore-line + || (string) (new \ReflectionEnum($object->name))->getBackingType() !== $backingType, // @phpstan-ignore-line + 'not to be '.$backingType.' backed enum', FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')), ); } diff --git a/tests/.snapshots/success.txt b/tests/.snapshots/success.txt index fbec75e2..b5298688 100644 --- a/tests/.snapshots/success.txt +++ b/tests/.snapshots/success.txt @@ -467,6 +467,10 @@ ✓ failures with custom message ✓ not failures + PASS Tests\Features\Expect\toBeIntBackedEnum + ✓ enum is backed by int + ✓ enum is not backed by int + PASS Tests\Features\Expect\toBeInvokable ✓ class is invokable ✓ opposite class is invokable @@ -575,6 +579,10 @@ ✓ failures with custom message ✓ not failures + PASS Tests\Features\Expect\toBeStringBackedEnum + ✓ enum is backed by string + ✓ enum is not backed by string + PASS Tests\Features\Expect\toBeStudlyCase ✓ pass ✓ failures @@ -1404,4 +1412,4 @@ WARN Tests\Visual\Version - visual snapshot of help command output - Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 995 passed (2391 assertions) \ No newline at end of file + Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 20 skipped, 1003 passed (2407 assertions) \ No newline at end of file diff --git a/tests/Visual/Parallel.php b/tests/Visual/Parallel.php index 9708303b..76a9ad3d 100644 --- a/tests/Visual/Parallel.php +++ b/tests/Visual/Parallel.php @@ -16,7 +16,7 @@ test('parallel', function () use ($run) { expect($run('--exclude-group=integration')) - ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 982 passed (2372 assertions)') + ->toContain('Tests: 1 deprecated, 4 warnings, 5 incomplete, 2 notices, 13 todos, 16 skipped, 990 passed (2388 assertions)') ->toContain('Parallel: 3 processes'); })->skipOnWindows();