|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace integration; |
| 6 | + |
| 7 | +use EliasHaeussler\PHPUnitAttributes\Attribute\RequiresPackage; |
| 8 | +use phpDocumentor\Reflection\File\LocalFile; |
| 9 | +use phpDocumentor\Reflection\Php\ProjectFactory; |
| 10 | +use phpDocumentor\Reflection\Php\Visibility; |
| 11 | +use phpDocumentor\Reflection\Types\Integer; |
| 12 | +use phpDocumentor\Reflection\Types\String_; |
| 13 | +use PHPUnit\Framework\Attributes\CoversNothing; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | + |
| 16 | +#[RequiresPackage('nikic/php-parser', '>= 5.2')] |
| 17 | +#[CoversNothing] |
| 18 | +final class InterfacePropertyTest extends TestCase |
| 19 | +{ |
| 20 | + public function testInterfacePropertiesAreParsed(): void |
| 21 | + { |
| 22 | + $file = __DIR__ . '/data/PHP84/InterfaceProperties.php'; |
| 23 | + $projectFactory = ProjectFactory::createInstance(); |
| 24 | + $project = $projectFactory->create('My project', [new LocalFile($file)]); |
| 25 | + |
| 26 | + $interfaces = $project->getFiles()[$file]->getInterfaces(); |
| 27 | + |
| 28 | + $hasId = $interfaces['\PHP84\HasId']; |
| 29 | + $properties = $hasId->getProperties(); |
| 30 | + $this->assertCount(1, $properties); |
| 31 | + $idProperty = $properties['\PHP84\HasId::$id']; |
| 32 | + $this->assertEquals(new Integer(), $idProperty->getType()); |
| 33 | + $this->assertEquals(new Visibility(Visibility::PUBLIC_), $idProperty->getVisibility()); |
| 34 | + $this->assertCount(1, $idProperty->getHooks()); |
| 35 | + $this->assertEquals('get', $idProperty->getHooks()[0]->getName()); |
| 36 | + |
| 37 | + $hasName = $interfaces['\PHP84\HasName']; |
| 38 | + $properties = $hasName->getProperties(); |
| 39 | + $this->assertCount(1, $properties); |
| 40 | + $nameProperty = $properties['\PHP84\HasName::$name']; |
| 41 | + $this->assertEquals(new String_(), $nameProperty->getType()); |
| 42 | + $this->assertCount(2, $nameProperty->getHooks()); |
| 43 | + } |
| 44 | +} |
0 commit comments