1 | <?php |
||
2 | declare(strict_types = 1); |
||
3 | |||
4 | namespace Tests\Innmind\Reflection\Visitor; |
||
5 | |||
6 | use Innmind\Reflection\{ |
||
7 | Visitor\AccessProperty, |
||
8 | Exception\PropertyNotFound, |
||
9 | }; |
||
10 | use Fixtures\Innmind\Reflection\Foo; |
||
11 | use PHPUnit\Framework\TestCase; |
||
12 | |||
13 | class AccessPropertyTest extends TestCase |
||
14 | { |
||
15 | /** |
||
16 | * @dataProvider cases |
||
17 | */ |
||
18 | public function testAccessProperty($object, string $property) |
||
19 | { |
||
20 | $this->assertInstanceOf( |
||
21 | \ReflectionProperty::class, |
||
22 | (new AccessProperty)($object, $property) |
||
23 | ); |
||
24 | } |
||
25 | |||
26 | public function testThrowWhenPropertyNotFound() |
||
27 | { |
||
28 | $this->expectException(PropertyNotFound::class); |
||
29 | $this->expectExceptionMessage('foo'); |
||
30 | |||
31 | (new AccessProperty)(new \stdClass, 'foo'); |
||
32 | } |
||
33 | |||
34 | public function cases(): array |
||
35 | { |
||
36 | return [ |
||
37 | [ |
||
38 | new class { |
||
39 | public $foo; |
||
40 | }, |
||
41 | 'foo', |
||
42 | ], |
||
43 | [ |
||
44 | new class { |
||
45 | protected $foo; |
||
46 | }, |
||
47 | 'foo', |
||
48 | ], |
||
49 | [ |
||
50 | new class { |
||
51 | private $foo; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
52 | }, |
||
53 | 'foo', |
||
54 | ], |
||
55 | [ |
||
56 | new class extends Foo {}, |
||
57 | 'someProperty', |
||
58 | ], |
||
59 | [ |
||
60 | new class extends Foo {}, |
||
61 | 'inheritProtected', |
||
62 | ], |
||
63 | ]; |
||
64 | } |
||
65 | } |
||
66 |