Skip to content

Commit 5db23d5

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: fix tests fix merge [VarDumper] Fix generator dump on PHP 8.4 keep boolean options when their value is false
2 parents 72b8322 + 6eea7da commit 5db23d5

File tree

4 files changed

+135
-3
lines changed

4 files changed

+135
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 50 additions & 0 deletions
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', 'channel' => 'C123456']));
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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ public static function castGenerator(\Generator $c, array $a, Stub $stub, bool $
8383
// Cannot create ReflectionGenerator based on a terminated Generator
8484
try {
8585
$reflectionGenerator = new \ReflectionGenerator($c);
86+
87+
return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
8688
} catch (\Exception) {
8789
$a[Caster::PREFIX_VIRTUAL.'closed'] = true;
8890

8991
return $a;
9092
}
91-
92-
return self::castReflectionGenerator($reflectionGenerator, $a, $stub, $isNested);
9393
}
9494

9595
public static function castType(\ReflectionType $c, array $a, Stub $stub, bool $isNested): array

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,84 @@ class: "Symfony\Component\VarDumper\Tests\Caster\ReflectionCasterTest"
460460
);
461461
}
462462

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

472550
$expectedDump = <<<'EODUMP'
473551
Generator {
552+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
474553
this: Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo { …}
475554
%s: {
476555
%sGeneratorDemo.php:14 {
@@ -479,6 +558,7 @@ public function testGenerator()
479558
› yield from bar();
480559
› }
481560
}
561+
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo->baz() {}
482562
%A}
483563
closed: false
484564
}
@@ -505,6 +585,7 @@ public function testGenerator()
505585
closed: false
506586
}
507587
1 => Generator {
588+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo"
508589
%s: {
509590
%s%eTests%eFixtures%eGeneratorDemo.php:%d {
510591
Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::foo()
@@ -526,6 +607,7 @@ public function testGenerator()
526607

527608
$expectedDump = <<<'EODUMP'
528609
Generator {
610+
function: "Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo::baz"
529611
closed: true
530612
}
531613
EODUMP;

0 commit comments

Comments
 (0)