Skip to content

Commit 2366ac8

Browse files
Merge branch '5.3' into 5.4
* 5.3: [gha] swap the php versions we use in jobs [DoctrineBridge] fix calling get_class on non-object Update PR template [HttpClient] Fix handling error info in MockResponse
2 parents 89ab66e + d139af7 commit 2366ac8

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
@@ -144,7 +144,7 @@ public static function castReflectionGenerator(\ReflectionGenerator $c, array $a
144144
array_unshift($trace, [
145145
'function' => 'yield',
146146
'file' => $function->getExecutingFile(),
147-
'line' => $function->getExecutingLine() - 1,
147+
'line' => $function->getExecutingLine() - (int) (\PHP_VERSION_ID < 80100),
148148
]);
149149
$trace[] = $frame;
150150
$a[$prefix.'trace'] = new TraceStub($trace, false, 0, -1, -1);
@@ -289,15 +289,17 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
289289
unset($a[$prefix.'allowsNull']);
290290
}
291291

292-
try {
293-
$a[$prefix.'default'] = $v = $c->getDefaultValue();
294-
if ($c->isDefaultValueConstant()) {
295-
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
296-
}
297-
if (null === $v) {
298-
unset($a[$prefix.'allowsNull']);
292+
if ($c->isOptional()) {
293+
try {
294+
$a[$prefix.'default'] = $v = $c->getDefaultValue();
295+
if ($c->isDefaultValueConstant()) {
296+
$a[$prefix.'default'] = new ConstStub($c->getDefaultValueConstantName(), $v);
297+
}
298+
if (null === $v) {
299+
unset($a[$prefix.'allowsNull']);
300+
}
301+
} catch (\ReflectionException $e) {
299302
}
300-
} catch (\ReflectionException $e) {
301303
}
302304

303305
return $a;

Tests/Caster/ReflectionCasterTest.php

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

141-
if (\PHP_VERSION_ID < 80100) {
142-
$this->assertDumpMatchesFormat(
143-
<<<'EOTXT'
144-
ReflectionParameter {
145-
+name: "arg1"
146-
position: 0
147-
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
148-
default: null
149-
}
150-
EOTXT
151-
, $var
152-
);
153-
} else {
154-
$this->assertDumpMatchesFormat(
155-
<<<'EOTXT'
141+
$this->assertDumpMatchesFormat(
142+
<<<'EOTXT'
156143
ReflectionParameter {
157144
+name: "arg1"
158145
position: 0
@@ -161,8 +148,7 @@ public function testReflectionParameter()
161148
}
162149
EOTXT
163150
, $var
164-
);
165-
}
151+
);
166152
}
167153

168154
public function testReflectionParameterScalar()
@@ -484,108 +470,54 @@ public function testGenerator()
484470
$generator = new GeneratorDemo();
485471
$generator = $generator->baz();
486472

487-
if (\PHP_VERSION_ID < 80100) {
488-
$expectedDump = <<<'EODUMP'
473+
$expectedDump = <<<'EODUMP'
489474
Generator {
490475
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
491-
executing: {
476+
%s: {
492477
%sGeneratorDemo.php:14 {
493478
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
494479
› {
495480
› yield from bar();
496481
› }
497482
}
498-
}
483+
%A}
499484
closed: false
500485
}
501486
EODUMP;
502-
} else {
503-
$expectedDump = <<<'EODUMP'
504-
Generator {
505-
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
506-
trace: {
507-
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:13 {
508-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
509-
› public function baz()
510-
› {
511-
› yield from bar();
512-
}
513-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
514-
}
515-
closed: false
516-
}
517-
EODUMP;
518-
}
519487

520488
$this->assertDumpMatchesFormat($expectedDump, $generator);
521489

522490
foreach ($generator as $v) {
523491
break;
524492
}
525493

526-
if (\PHP_VERSION_ID < 80100) {
527-
$expectedDump = <<<'EODUMP'
494+
$expectedDump = <<<'EODUMP'
528495
array:2 [
529496
0 => ReflectionGenerator {
530497
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
531-
trace: {
532-
%s%eTests%eFixtures%eGeneratorDemo.php:9 {
498+
%s: {
499+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
533500
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
534-
› {
535-
› yield 1;
536-
› }
537-
}
501+
%A › yield 1;
502+
%A }
538503
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
539504
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
540-
}
505+
%A }
541506
closed: false
542507
}
543508
1 => Generator {
544-
executing: {
545-
%sGeneratorDemo.php:10 {
509+
%s: {
510+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
546511
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
547512
› yield 1;
548513
› }
549514
550515
}
551-
}
552-
closed: false
553-
}
554-
]
555-
EODUMP;
556-
} else {
557-
$expectedDump = <<<'EODUMP'
558-
array:2 [
559-
0 => ReflectionGenerator {
560-
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
561-
trace: {
562-
%s%eTests%eFixtures%eGeneratorDemo.php:9 {
563-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
564-
› {
565-
› yield 1;
566-
› }
567-
}
568-
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
569-
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
570-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
571-
}
572-
closed: false
573-
}
574-
1 => Generator {
575-
trace: {
576-
./src/Symfony/Component/VarDumper/Tests/Fixtures/GeneratorDemo.php:9 {
577-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
578-
› {
579-
› yield 1;
580-
› }
581-
}
582-
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo() {}
583-
}
516+
%A }
584517
closed: false
585518
}
586519
]
587520
EODUMP;
588-
}
589521

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

0 commit comments

Comments
 (0)