Skip to content

Commit 8d9e2c5

Browse files
committed
Merge branch '5.4' into 6.4
* 5.4: [VarDumper] Fix generator dump on PHP 8.4 keep boolean options when their value is false
2 parents 8c277d9 + 3fa0149 commit 8d9e2c5

File tree

4 files changed

+136
-4
lines changed

4 files changed

+136
-4
lines changed

src/Symfony/Component/Notifier/Bridge/Slack/SlackTransport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ protected function doSend(MessageInterface $message): SlackSentMessage
8181
}
8282

8383
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/'.$apiMethod, [
84-
'json' => array_filter($options),
84+
'json' => array_filter($options, function ($value): bool { return !\in_array($value, ['', [], null], true); }),
8585
'auth_bearer' => $this->accessToken,
8686
'headers' => [
8787
'Content-Type' => 'application/json; charset=utf-8',

src/Symfony/Component/Notifier/Bridge/Slack/Tests/SlackTransportTest.php

+50
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,56 @@ public function testSendWithNotification()
167167
$this->assertSame('1503435956.000247', $sentMessage->getMessageId());
168168
}
169169

170+
/**
171+
* @testWith [true]
172+
* [false]
173+
*/
174+
public function testSendWithBooleanOptionValue(bool $value)
175+
{
176+
$channel = 'testChannel';
177+
$message = 'testMessage';
178+
179+
$response = $this->createMock(ResponseInterface::class);
180+
181+
$response->expects($this->exactly(2))
182+
->method('getStatusCode')
183+
->willReturn(200);
184+
185+
$response->expects($this->once())
186+
->method('getContent')
187+
->willReturn(json_encode(['ok' => true, 'ts' => '1503435956.000247']));
188+
189+
$options = new SlackOptions();
190+
$options->asUser($value);
191+
$options->linkNames($value);
192+
$options->mrkdwn($value);
193+
$options->unfurlLinks($value);
194+
$options->unfurlMedia($value);
195+
$notification = new Notification($message);
196+
$chatMessage = ChatMessage::fromNotification($notification);
197+
$chatMessage->options($options);
198+
199+
$expectedBody = json_encode([
200+
'as_user' => $value,
201+
'channel' => $channel,
202+
'link_names' => $value,
203+
'mrkdwn' => $value,
204+
'text' => $message,
205+
'unfurl_links' => $value,
206+
'unfurl_media' => $value,
207+
]);
208+
209+
$client = new MockHttpClient(function (string $method, string $url, array $options = []) use ($response, $expectedBody): ResponseInterface {
210+
$this->assertJsonStringEqualsJsonString($expectedBody, $options['body']);
211+
212+
return $response;
213+
});
214+
215+
$transport = self::createTransport($client, $channel);
216+
217+
$transport->send($chatMessage);
218+
}
219+
170220
public function testSendWith200ResponseButNotOk()
171221
{
172222
$channel = 'testChannel';

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $
8989
// Cannot create ReflectionGenerator based on a terminated Generator
9090
try {
9191
$reflectionGenerator = new \ReflectionGenerator($c);
92+
93+
return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
9294
} catch (\Exception) {
9395
$a[Caster::PREFIX_VIRTUAL.'closed'] = true;
9496

9597
return $a;
9698
}
97-
98-
return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
9999
}
100100

101101
/**

src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php

+83-1
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,84 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
463463
);
464464
}
465465

466+
/**
467+
* @requires PHP < 8.4
468+
*/
469+
public function testGeneratorPriorTo84()
470+
{
471+
if (\extension_loaded('xdebug')) {
472+
$this->markTestSkipped('xdebug is active');
473+
}
474+
475+
$generator = new GeneratorDemo();
476+
$generator = $generator->baz();
477+
478+
$expectedDump = <<<'EODUMP'
479+
Generator {
480+
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
481+
%s: {
482+
%sGeneratorDemo.php:14 {
483+
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz()
484+
› {
485+
› yield from bar();
486+
› }
487+
}
488+
%A}
489+
closed: false
490+
}
491+
EODUMP;
492+
493+
$this->assertDumpMatchesFormat($expectedDump, $generator);
494+
495+
foreach ($generator as $v) {
496+
break;
497+
}
498+
499+
$expectedDump = <<<'EODUMP'
500+
array:2 [
501+
0 => ReflectionGenerator {
502+
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
503+
%s: {
504+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
505+
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
506+
%A › yield 1;
507+
%A }
508+
%s%eTests%eFixtures%eGeneratorDemo.php:20 { …}
509+
%s%eTests%eFixtures%eGeneratorDemo.php:14 { …}
510+
%A }
511+
closed: false
512+
}
513+
1 => Generator {
514+
%s: {
515+
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
516+
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
517+
› yield 1;
518+
› }
519+
520+
}
521+
%A }
522+
closed: false
523+
}
524+
]
525+
EODUMP;
526+
527+
$r = new \ReflectionGenerator($generator);
528+
$this->assertDumpMatchesFormat($expectedDump, [$r, $r->getExecutingGenerator()]);
529+
530+
foreach ($generator as $v) {
531+
}
532+
533+
$expectedDump = <<<'EODUMP'
534+
Generator {
535+
closed: true
536+
}
537+
EODUMP;
538+
$this->assertDumpMatchesFormat($expectedDump, $generator);
539+
}
540+
541+
/**
542+
* @requires PHP 8.4
543+
*/
466544
public function testGenerator()
467545
{
468546
if (\extension_loaded('xdebug')) {
@@ -474,6 +552,7 @@ public function testGenerator()
474552

475553
$expectedDump = <<<'EODUMP'
476554
Generator {
555+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
477556
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
478557
%s: {
479558
%sGeneratorDemo.php:14 {
@@ -482,6 +561,7 @@ public function testGenerator()
482561
› yield from bar();
483562
› }
484563
}
564+
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
485565
%A}
486566
closed: false
487567
}
@@ -508,12 +588,13 @@ public function testGenerator()
508588
closed: false
509589
}
510590
1 => Generator {
591+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo"
511592
%s: {
512593
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
513594
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
514595
› yield 1;
515596
› }
516-
597+
517598
}
518599
%A }
519600
closed: false
@@ -529,6 +610,7 @@ public function testGenerator()
529610

530611
$expectedDump = <<<'EODUMP'
531612
Generator {
613+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
532614
closed: true
533615
}
534616
EODUMP;

0 commit comments

Comments
 (0)