Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5namespace Tests\Phexium\Unit\Domain;
6
7use InvalidArgumentException;
8use Phexium\Domain\TypeGuard;
9use stdClass;
10use Throwable;
11
12test('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
20test('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
28test('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
36test('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});