|
15 | 15 |
|
16 | 16 | use phpDocumentor\Reflection\DocBlock as DocBlockDescriptor;
|
17 | 17 | use phpDocumentor\Reflection\DocBlockFactoryInterface;
|
| 18 | +use phpDocumentor\Reflection\Element; |
18 | 19 | use phpDocumentor\Reflection\Fqsen;
|
19 | 20 | use phpDocumentor\Reflection\Php\Class_ as ClassElement;
|
20 | 21 | use phpDocumentor\Reflection\Php\Constant as ConstantDescriptor;
|
| 22 | +use phpDocumentor\Reflection\Php\Enum_ as EnumElement; |
| 23 | +use phpDocumentor\Reflection\Php\Interface_ as InterfaceElement; |
21 | 24 | use phpDocumentor\Reflection\Php\ProjectFactoryStrategies;
|
| 25 | +use phpDocumentor\Reflection\Php\Trait_ as TraitElement; |
| 26 | +use phpDocumentor\Reflection\Types\Null_; |
22 | 27 | use PhpParser\Comment\Doc;
|
23 | 28 | use PhpParser\Node\Const_;
|
24 | 29 | use PhpParser\Node\Scalar\String_;
|
@@ -97,6 +102,42 @@ public function visibilityProvider(): array
|
97 | 102 | ];
|
98 | 103 | }
|
99 | 104 |
|
| 105 | + public function testCreateForInterface(): void |
| 106 | + { |
| 107 | + $interface = new InterfaceElement(new Fqsen('\myInterface')); |
| 108 | + $const = new Const_('\Space\MyInterface::MY_CONST1', new String_('a')); |
| 109 | + $const->setAttribute('fqsen', new Fqsen((string) $const->name)); |
| 110 | + $constantStub = new ClassConst([$const], ClassNode::MODIFIER_PUBLIC); |
| 111 | + |
| 112 | + $result = $this->performCreateWith($constantStub, $interface); |
| 113 | + |
| 114 | + self::assertInstanceOf(ConstantDescriptor::class, current($result->getConstants())); |
| 115 | + } |
| 116 | + |
| 117 | + public function testCreateForTrait(): void |
| 118 | + { |
| 119 | + $trait = new TraitElement(new Fqsen('\myTrait')); |
| 120 | + $const = new Const_('\Space\MyTrait::MY_CONST1', new String_('a')); |
| 121 | + $const->setAttribute('fqsen', new Fqsen((string) $const->name)); |
| 122 | + $constantStub = new ClassConst([$const], ClassNode::MODIFIER_PUBLIC); |
| 123 | + |
| 124 | + $result = $this->performCreateWith($constantStub, $trait); |
| 125 | + |
| 126 | + self::assertInstanceOf(ConstantDescriptor::class, current($result->getConstants())); |
| 127 | + } |
| 128 | + |
| 129 | + public function testCreateForEnum(): void |
| 130 | + { |
| 131 | + $enum = new EnumElement(new Fqsen('\myEnum'), new Null_()); |
| 132 | + $const = new Const_('\Space\MyEnum::MY_CONST1', new String_('a')); |
| 133 | + $const->setAttribute('fqsen', new Fqsen((string) $const->name)); |
| 134 | + $constantStub = new ClassConst([$const], ClassNode::MODIFIER_PUBLIC); |
| 135 | + |
| 136 | + $result = $this->performCreateWith($constantStub, $enum); |
| 137 | + |
| 138 | + self::assertInstanceOf(ConstantDescriptor::class, current($result->getConstants())); |
| 139 | + } |
| 140 | + |
100 | 141 | public function testCreateWithDocBlock(): void
|
101 | 142 | {
|
102 | 143 | $doc = new Doc('text');
|
@@ -132,10 +173,17 @@ private function assertConstant(ConstantDescriptor $constant, string $visibility
|
132 | 173 |
|
133 | 174 | private function performCreate(ClassConst $constantStub): ClassElement
|
134 | 175 | {
|
135 |
| - $factory = new ProjectFactoryStrategies([]); |
136 | 176 | $class = new ClassElement(new Fqsen('\myClass'));
|
137 |
| - $this->fixture->create(self::createContext(null)->push($class), $constantStub, $factory); |
| 177 | + $this->performCreateWith($constantStub, $class); |
138 | 178 |
|
139 | 179 | return $class;
|
140 | 180 | }
|
| 181 | + |
| 182 | + private function performCreateWith(ClassConst $constantStub, Element $parent): Element |
| 183 | + { |
| 184 | + $factory = new ProjectFactoryStrategies([]); |
| 185 | + $this->fixture->create(self::createContext(null)->push($parent), $constantStub, $factory); |
| 186 | + |
| 187 | + return $parent; |
| 188 | + } |
141 | 189 | }
|
0 commit comments