Skip to content

Commit f2c45f0

Browse files
[gha] swap the php versions we use in jobs
1 parent 2d0c056 commit f2c45f0

File tree

2 files changed

+26
-92
lines changed

2 files changed

+26
-92
lines changed

Caster/ReflectionCaster.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public static function castReflectionGenerator(\ReflectionGenerator $c, array $a
134134
array_unshift($trace, [
135135
'function' => 'yield',
136136
'file' => $function->getExecutingFile(),
137-
'line' => $function->getExecutingLine() - 1,
137+
'line' => $function->getExecutingLine() - (int) (\PHP_VERSION_ID < 80100),
138138
]);
139139
$trace[] = $frame;
140140
$a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1);
@@ -263,15 +263,17 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
263263
unset($a[$prefix.'allowsNull']);
264264
}
265265

266-
try {
267-
$a[$prefix.'default'] = $v = $c->getDefaultValue();
268-
if ($c->isDefaultValueConstant()) {
269-
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
270-
}
271-
if (null === $v) {
272-
unset($a[$prefix.'allowsNull']);
266+
if ($c->isOptional()) {
267+
try {
268+
$a[$prefix.'default'] = $v = $c->getDefaultValue();
269+
if ($c->isDefaultValueConstant()) {
270+
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
271+
}
272+
if (null === $v) {
273+
unset($a[$prefix.'allowsNull']);
274+
}
275+
} catch (\ReflectionException $e) {
273276
}
274-
} catch (\ReflectionException $e) {
275277
}
276278

277279
return $a;

Tests/Caster/ReflectionCasterTest.php

Lines changed: 15 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,8 @@ public function testReflectionParameter()
122122
{
123123
$var = new \ReflectionParameter(reflectionParameterFixture::class, 0);
124124

125-
if (\PHP_VERSION_ID < 80100) {
126-
$this->assertDumpMatchesFormat(
127-
<<<'EOTXT'
128-
ReflectionParameter {
129-
+name: "arg1"
130-
position: 0
131-
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
132-
default: null
133-
}
134-
EOTXT
135-
, $var
136-
);
137-
} else {
138-
$this->assertDumpMatchesFormat(
139-
<<<'EOTXT'
125+
$this->assertDumpMatchesFormat(
126+
<<<'EOTXT'
140127
ReflectionParameter {
141128
+name: "arg1"
142129
position: 0
@@ -145,8 +132,7 @@ public function testReflectionParameter()
145132
}
146133
EOTXT
147134
, $var
148-
);
149-
}
135+
);
150136
}
151137

152138
public function testReflectionParameterScalar()
@@ -468,108 +454,54 @@ public function testGenerator()
468454
$generator = new GeneratorDemo();
469455
$generator = $generator->baz();
470456

471-
if (\PHP_VERSION_ID < 80100) {
472-
$expectedDump = <<<'EODUMP'
457+
$expectedDump = <<<'EODUMP'
473458
Generator {
474459
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
475-
executing: {
460+
%s: {
476461
%sGeneratorDemo.php:14 {
477462
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
478463
› {
479464
› yield from bar();
480465
› }
481466
}
482-
}
467+
%A}
483468
closed: false
484469
}
485470
EODUMP;
486-
} else {
487-
$expectedDump = <<<'EODUMP'
488-
Generator {
489-
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
490-
trace: {
491-
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:13 {
492-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
493-
› public function baz()
494-
› {
495-
› yield from bar();
496-
}
497-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
498-
}
499-
closed: false
500-
}
501-
EODUMP;
502-
}
503471

504472
$this->assertDumpMatchesFormat($expectedDump, $generator);
505473

506474
foreach ($generator as $v) {
507475
break;
508476
}
509477

510-
if (\PHP_VERSION_ID < 80100) {
511-
$expectedDump = <<<'EODUMP'
478+
$expectedDump = <<<'EODUMP'
512479
array:2 [
513480
0 => ReflectionGenerator {
514481
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
515-
trace: {
516-
%s%eTests%eFixtures%eGeneratorDemo.php:9 {
482+
%s: {
483+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
517484
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
518-
› {
519-
› yield 1;
520-
› }
521-
}
485+
%A › yield 1;
486+
%A }
522487
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
523488
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
524-
}
489+
%A }
525490
closed: false
526491
}
527492
1 => Generator {
528-
executing: {
529-
%sGeneratorDemo.php:10 {
493+
%s: {
494+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
530495
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
531496
› yield 1;
532497
› }
533498
534499
}
535-
}
536-
closed: false
537-
}
538-
]
539-
EODUMP;
540-
} else {
541-
$expectedDump = <<<'EODUMP'
542-
array:2 [
543-
0 => ReflectionGenerator {
544-
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
545-
trace: {
546-
%s%eTests%eFixtures%eGeneratorDemo.php:9 {
547-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
548-
› {
549-
› yield 1;
550-
› }
551-
}
552-
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
553-
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
554-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
555-
}
556-
closed: false
557-
}
558-
1 => Generator {
559-
trace: {
560-
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:9 {
561-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
562-
› {
563-
› yield 1;
564-
› }
565-
}
566-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() {}
567-
}
500+
%A }
568501
closed: false
569502
}
570503
]
571504
EODUMP;
572-
}
573505

574506
$r = new \ReflectionGenerator($generator);
575507
$this->assertDumpMatchesFormat($expectedDump, [$r, $r->getExecutingGenerator()]);

0 commit comments

Comments
 (0)