@@ -326,6 +326,63 @@ public function constantProvider(): array
326326 ];
327327 }
328328
329+ public function typedConstantProvider (): array
330+ {
331+ $ typed = PHP_VERSION_ID >= 80300 ;
332+ $ docPart = "/** \n * @var %s \n */ \n" ;
333+
334+ return [
335+ [
336+ 'int ' , 1 , '@var int ' ,
337+ sprintf ($ docPart , 'int ' ) . ($ typed ? 'const int TEST = 1; ' : 'const TEST = 1; ' ),
338+ ],
339+ [
340+ 'string ' , 'Foo ' , '@var string ' ,
341+ sprintf ($ docPart , 'string ' ) . ($ typed ? "const string TEST = 'Foo'; " : "const TEST = 'Foo'; " ),
342+ ],
343+ [
344+ 'bool ' , 1 , '@var bool ' ,
345+ sprintf ($ docPart , 'bool ' ) . ($ typed ? 'const bool TEST = 1; ' : 'const TEST = 1; ' ),
346+ ],
347+ [
348+ 'string ' , 'bar ' , null , "const TEST = 'bar'; " ,
349+ ],
350+ ];
351+ }
352+
353+ /**
354+ * @dataProvider typedConstantProvider
355+ *
356+ * @throws \ReflectionException
357+ */
358+ public function testShouldBuildTypedConstant (string $ type , mixed $ value , ?string $ docBlock , string $ expected ): void
359+ {
360+ if (Os::isWindows ()) {
361+ $ this ->markTestSkipped ('Warning: Strings contain different line endings! ' );
362+ }
363+
364+ $ buildClass = $ this ->getMethod ('buildConstant ' );
365+
366+ $ classConstant = new Constant (
367+ 'TEST ' ,
368+ [
369+ 'type ' => $ type ,
370+ 'value ' => $ value ,
371+ ],
372+ $ docBlock
373+ );
374+
375+ $ actual = $ buildClass ->invokeArgs (
376+ $ this ->testClass ,
377+ [
378+ $ classConstant ,
379+ '' ,
380+ ]
381+ );
382+
383+ $ this ->assertSame ($ expected , $ actual );
384+ }
385+
329386 /**
330387 * @dataProvider constantProvider
331388 *
0 commit comments