13
13
14
14
use PHPUnit \Framework \TestCase ;
15
15
use Symfony \Component \VarDumper \Caster \Caster ;
16
+ use Symfony \Component \VarDumper \Caster \ConstStub ;
17
+ use Symfony \Component \VarDumper \Caster \ReflectionCaster ;
18
+ use Symfony \Component \VarDumper \Cloner \Stub ;
16
19
use Symfony \Component \VarDumper \Test \VarDumperTestTrait ;
17
20
use Symfony \Component \VarDumper \Tests \Fixtures \ExtendsReflectionTypeFixture ;
18
21
use Symfony \Component \VarDumper \Tests \Fixtures \GeneratorDemo ;
@@ -85,7 +88,9 @@ public function testReflectionCaster()
85
88
public function testClosureCaster ()
86
89
{
87
90
$ a = $ b = 123 ;
91
+ // @codingStandardsIgnoreStart
88
92
$ var = function ($ x ) use ($ a , &$ b ) {};
93
+ // @codingStandardsIgnoreEnd
89
94
90
95
$ this ->assertDumpMatchesFormat (
91
96
<<<'EOTXT'
@@ -95,7 +100,7 @@ public function testClosureCaster()
95
100
$b: & 123
96
101
}
97
102
file: "%sReflectionCasterTest.php"
98
- line: "88 to 88 "
103
+ line: "91 to 91 "
99
104
}
100
105
EOTXT
101
106
, $ var
@@ -550,7 +555,7 @@ public function testGenerator()
550
555
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
551
556
› yield 1;
552
557
› }
553
- ›
558
+ ›
554
559
}
555
560
%A }
556
561
closed: false
@@ -701,6 +706,27 @@ public function testReflectionClassConstantWithAttribute()
701
706
, $ var );
702
707
}
703
708
709
+ public function testGlobalConstantAsDefaultValue ()
710
+ {
711
+ $ class = new class () {
712
+ /**
713
+ * @codingStandardsIgnore
714
+ */
715
+ public function foo (float $ value = M_PI )
716
+ {
717
+ // Dummy content
718
+ }
719
+ };
720
+ $ method = new \ReflectionMethod ($ class , 'foo ' );
721
+ $ parameter = $ method ->getParameters ()[0 ];
722
+ $ cast = ReflectionCaster::castParameter ($ parameter , [], new Stub (), false );
723
+ /** @var ConstStub $defaultStub */
724
+ $ defaultStub = $ cast ["\0~ \0default " ];
725
+
726
+ $ this ->assertInstanceOf (ConstStub::class, $ defaultStub );
727
+ $ this ->assertSame ('\\' .\M_PI ::class, $ defaultStub ->class );
728
+ }
729
+
704
730
/**
705
731
* @requires PHP 8
706
732
*/
0 commit comments