@@ -216,4 +216,80 @@ public function it_checks_if_a_data_type_specification_is_an_object(?string $spe
216216 // then the result is as expected as provided by the test's parameter
217217 $ this ->assertSame ($ expectedIsObject , $ isObject );
218218 }
219+
220+ public function provides_data_type_specification_and_expected_class_name () : array
221+ {
222+ return [
223+ [\DateTime::class, \DateTime::class],
224+ ['ClassMetadata ' , ClassMetadata::class],
225+ ['self ' , ClassForTesting::class],
226+ ['$this ' , ClassForTesting::class],
227+ ];
228+ }
229+
230+ /**
231+ * @test
232+ * @dataProvider provides_data_type_specification_and_expected_class_name
233+ * @covers ::fullyQualifiedClassNameOfDataTypeSpecification()
234+ */
235+ public function it_resolves_a_data_type_specification_to_a_fully_qualified_class_name (
236+ string $ dataTypeSpecification ,
237+ string $ expectedClassName
238+ )
239+ {
240+ // given some ClassMetadata
241+ $ classMetadata = new ClassMetadata (
242+ ClassForTesting::class,
243+ [
244+ 'ScaleUpStack\Metadata\Metadata\ClassMetadata ' ,
245+ ],
246+ new Annotations ()
247+ );
248+ // and a data type specification as provided by the test's parameter
249+
250+ // when resolving the specification to a fully qualified class name
251+ $ className = $ classMetadata ->fullyQualifiedClassNameOfDataTypeSpecification ($ dataTypeSpecification );
252+
253+ // then the result is the expected class name as provided by the test's parameter
254+ $ this ->assertSame ($ className , $ expectedClassName );
255+ }
256+
257+ public function provides_non_object_data_type_specifications () : array
258+ {
259+ return [
260+ [\DateTimeInterface::class], // interfaces are not supported
261+ ['int ' ],
262+ [\DateTime::class . '| ' . \Exception::class], // union types are not supported
263+ ];
264+ }
265+
266+ /**
267+ * @test
268+ * @dataProvider provides_non_object_data_type_specifications
269+ * @covers ::fullyQualifiedClassNameOfDataTypeSpecification()
270+ */
271+ public function it_throws_an_exception_if_data_type_specification_is_no_object (string $ specification )
272+ {
273+ // given some ClassMetadata
274+ $ classMetadata = new ClassMetadata (
275+ ClassForTesting::class,
276+ [
277+ 'ScaleUpStack\Metadata\Metadata\ClassMetadata ' ,
278+ ],
279+ new Annotations ()
280+ );
281+ // and a data type specification that is not object as provided by the test's parameter
282+
283+ // when resolving the specification to a fully qualified class name
284+ // then an exception is thrown
285+ $ this ->expectException (\RuntimeException::class);
286+ $ this ->expectExceptionMessage (
287+ sprintf (
288+ "Data type specification '%s' is not an object. (Interfaces and union types are not supported.) " ,
289+ $ specification
290+ )
291+ );
292+
293+ $ classMetadata ->fullyQualifiedClassNameOfDataTypeSpecification ($ specification );
294+ }
219295}
0 commit comments