|
13 | 13 | namespace ScaleUpStack\Metadata\Tests\PhpUnit\Metadata; |
14 | 14 |
|
15 | 15 | use ScaleUpStack\Annotations\Annotations; |
| 16 | +use ScaleUpStack\Metadata\Generator\FeatureAnalyzer; |
16 | 17 | use ScaleUpStack\Metadata\Metadata\ClassMetadata; |
17 | 18 | use ScaleUpStack\Metadata\Tests\Resources\ClassForTesting; |
18 | 19 | use ScaleUpStack\Metadata\Tests\Resources\TestCase; |
@@ -140,6 +141,9 @@ public function provides_short_and_fully_qualified_data_type_specifications() : |
140 | 141 | ['ClassMetadata[]', 'ScaleUpStack\Metadata\ClassMetadata[]'], |
141 | 142 |
|
142 | 143 | ['int[]|\DateTime', 'int[]|DateTime'], |
| 144 | + |
| 145 | + ['self', 'self'], |
| 146 | + ['$this', '$this'], |
143 | 147 | ]; |
144 | 148 | } |
145 | 149 |
|
@@ -170,5 +174,46 @@ public function it_transforms_a_data_type_specification_into_a_fully_qualified_s |
170 | 174 | // then the specification was transformed to a fully qualified data type specification |
171 | 175 | $this->assertSame($expectedLongSpecification, $longSpecification); |
172 | 176 | } |
173 | | -} |
174 | 177 |
|
| 178 | + public function provides_data_type_specifications_and_if_they_are_an_object() : array |
| 179 | + { |
| 180 | + return [ |
| 181 | + ['bool', false], |
| 182 | + ['int[]', false], |
| 183 | + [\DateTime::class, true], |
| 184 | + [\DateTime::class . '[]', true], |
| 185 | + [\DateTime::class . '|int', false], // union types are not supported; TODO: is this ok? |
| 186 | + ['ClassMetadata', true], |
| 187 | + [null, false], |
| 188 | + ['', false], |
| 189 | + ['self', true], |
| 190 | + ['$this', true], |
| 191 | + [\DateTimeInterface::class, false], // interfaces are not supported |
| 192 | + [FeatureAnalyzer::class, false], |
| 193 | + ]; |
| 194 | + } |
| 195 | + |
| 196 | + /** |
| 197 | + * @test |
| 198 | + * @dataProvider provides_data_type_specifications_and_if_they_are_an_object |
| 199 | + * @covers ::isDataTypeSpecificationAnObject() |
| 200 | + */ |
| 201 | + public function it_checks_if_a_data_type_specification_is_an_object(?string $specification, bool $expectedIsObject) |
| 202 | + { |
| 203 | + // given some ClassMetadata |
| 204 | + $classMetadata = new ClassMetadata( |
| 205 | + ClassForTesting::class, |
| 206 | + [ |
| 207 | + 'ScaleUpStack\Metadata\Metadata\ClassMetadata', |
| 208 | + ], |
| 209 | + new Annotations() |
| 210 | + ); |
| 211 | + // and a data type specification as provided by the test's parameter |
| 212 | + |
| 213 | + // when checking if the data type specification is an object |
| 214 | + $isObject = $classMetadata->isDataTypeSpecificationAnObject($specification); |
| 215 | + |
| 216 | + // then the result is as expected as provided by the test's parameter |
| 217 | + $this->assertSame($expectedIsObject, $isObject); |
| 218 | + } |
| 219 | +} |
0 commit comments