Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
24 / 24 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Tests\Phexium\Unit\Domain; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | use Phexium\Domain\TypeGuard; |
| 9 | use stdClass; |
| 10 | use Throwable; |
| 11 | |
| 12 | test('isInstanceOf passes with correct type', function (): void { |
| 13 | $object = new stdClass(); |
| 14 | |
| 15 | expect(fn () => TypeGuard::that($object)->isInstanceOf(stdClass::class)) |
| 16 | ->not->toThrow(Throwable::class) |
| 17 | ; |
| 18 | }); |
| 19 | |
| 20 | test('isInstanceOf throws InvalidArgumentException with wrong type', function (): void { |
| 21 | $object = new stdClass(); |
| 22 | |
| 23 | expect(fn () => TypeGuard::that($object)->isInstanceOf(InvalidArgumentException::class)) |
| 24 | ->toThrow(InvalidArgumentException::class) |
| 25 | ; |
| 26 | }); |
| 27 | |
| 28 | test('exception message contains expected and actual class names', function (): void { |
| 29 | $object = new stdClass(); |
| 30 | |
| 31 | expect(fn () => TypeGuard::that($object)->isInstanceOf(InvalidArgumentException::class)) |
| 32 | ->toThrow(InvalidArgumentException::class, 'Expected instance of InvalidArgumentException, got stdClass') |
| 33 | ; |
| 34 | }); |
| 35 | |
| 36 | test('isInstanceOf accepts interface implementations', function (): void { |
| 37 | $exception = new InvalidArgumentException('test'); |
| 38 | |
| 39 | expect(fn () => TypeGuard::that($exception)->isInstanceOf(Throwable::class)) |
| 40 | ->not->toThrow(Throwable::class) |
| 41 | ; |
| 42 | }); |