|
5 | 5 | namespace integration; |
6 | 6 |
|
7 | 7 | use EliasHaeussler\PHPUnitAttributes\Attribute\RequiresPackage; |
| 8 | +use phpDocumentor\Reflection\DocBlock; |
8 | 9 | use phpDocumentor\Reflection\File\LocalFile; |
| 10 | +use phpDocumentor\Reflection\Location; |
| 11 | +use phpDocumentor\Reflection\Php\Argument; |
| 12 | +use phpDocumentor\Reflection\Php\AsyncVisibility; |
| 13 | +use phpDocumentor\Reflection\Php\Attribute; |
9 | 14 | use phpDocumentor\Reflection\Php\ProjectFactory; |
| 15 | +use phpDocumentor\Reflection\Php\PropertyHook; |
| 16 | +use phpDocumentor\Reflection\Php\Visibility; |
| 17 | +use phpDocumentor\Reflection\Types\Compound; |
| 18 | +use phpDocumentor\Reflection\Types\Integer; |
| 19 | +use phpDocumentor\Reflection\Types\String_; |
| 20 | +use PHPUnit\Framework\Attributes\CoversNothing; |
10 | 21 | use PHPUnit\Framework\TestCase; |
11 | 22 |
|
12 | 23 | #[RequiresPackage('nikic/php-parser', '>= 5.2')] |
| 24 | +#[CoversNothing] |
13 | 25 | final class PropertyHookTest extends TestCase |
14 | 26 | { |
15 | | - public function testPropertyHook() |
| 27 | + public function testPropertyHookWithDocblocks() |
16 | 28 | { |
17 | 29 | $file = __DIR__ . '/data/PHP84/PropertyHook.php'; |
18 | 30 | $projectFactory = ProjectFactory::createInstance(); |
19 | 31 | $project = $projectFactory->create('My project', [new LocalFile($file)]); |
20 | 32 |
|
21 | 33 | $class = $project->getFiles()[$file]->getClasses()['\PropertyHook']; |
| 34 | + $hooks = $class->getProperties()['\PropertyHook::$example']->getHooks(); |
| 35 | + |
| 36 | + $this->assertCount(2, $hooks); |
| 37 | + $this->assertEquals('get', $hooks[0]->getName()); |
| 38 | + $this->assertEquals(new Visibility(Visibility::PUBLIC_), $hooks[0]->getVisibility()); |
| 39 | + $this->assertCount(1, $hooks[0]->getAttributes()); |
| 40 | + $this->assertCount(0, $hooks[0]->getArguments()); |
| 41 | + $this->assertSame('Not sure this works, but it gets', $hooks[0]->getDocBlock()->getSummary()); |
| 42 | + |
| 43 | + $this->assertEquals('set', $hooks[1]->getName()); |
| 44 | + $this->assertEquals(new Visibility(Visibility::PUBLIC_), $hooks[1]->getVisibility()); |
| 45 | + $this->assertCount(1, $hooks[1]->getAttributes()); |
| 46 | + $this->assertCount(1, $hooks[1]->getArguments()); |
| 47 | + $this->assertEquals(new Argument( |
| 48 | + 'value', |
| 49 | + new Compound( |
| 50 | + [ |
| 51 | + new String_(), |
| 52 | + new Integer() |
| 53 | + ] |
| 54 | + ), |
| 55 | + ), $hooks[1]->getArguments()[0]); |
| 56 | + $this->assertSame('Not sure this works, but it gets', $hooks[0]->getDocBlock()->getSummary()); |
| 57 | + } |
| 58 | + |
| 59 | + public function testPropertyHookAsync() |
| 60 | + { |
| 61 | + $file = __DIR__ . '/data/PHP84/PropertyHookAsync.php'; |
| 62 | + $projectFactory = ProjectFactory::createInstance(); |
| 63 | + $project = $projectFactory->create('My project', [new LocalFile($file)]); |
| 64 | + |
| 65 | + $class = $project->getFiles()[$file]->getClasses()['\PropertyHook']; |
| 66 | + $hooks = $class->getProperties()['\PropertyHook::$example']->getHooks(); |
| 67 | + |
| 68 | + |
| 69 | + $this->assertEquals( |
| 70 | + new AsyncVisibility( |
| 71 | + new Visibility(Visibility::PUBLIC_), |
| 72 | + new Visibility(Visibility::PRIVATE_) |
| 73 | + ), |
| 74 | + $class->getProperties()['\PropertyHook::$example']->getVisibility() |
| 75 | + ); |
| 76 | + $this->assertCount(2, $hooks); |
| 77 | + $this->assertEquals('get', $hooks[0]->getName()); |
| 78 | + $this->assertEquals(new Visibility(Visibility::PUBLIC_), $hooks[0]->getVisibility()); |
| 79 | + $this->assertCount(0, $hooks[0]->getArguments()); |
| 80 | + |
| 81 | + $this->assertEquals('set', $hooks[1]->getName()); |
| 82 | + $this->assertEquals(new Visibility(Visibility::PRIVATE_), $hooks[1]->getVisibility()); |
| 83 | + $this->assertCount(1, $hooks[1]->getArguments()); |
| 84 | + $this->assertEquals(new Argument( |
| 85 | + 'value', |
| 86 | + new Compound( |
| 87 | + [ |
| 88 | + new String_(), |
| 89 | + new Integer() |
| 90 | + ] |
| 91 | + ), |
| 92 | + ), $hooks[1]->getArguments()[0]); |
22 | 93 | } |
23 | 94 | } |
0 commit comments