Skip to content

Commit d41adec

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: fix tests fix merge [VarDumper] Fix generator dump on PHP 8.4 keep boolean options when their value is false gracefully handle cases when no resolver is set
2 parents 9ca558e + b380b4a commit d41adec

File tree

10 files changed

+201
-4
lines changed

10 files changed

+201
-4
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Config\Exception;
13+
14+
class LogicException extends \LogicException
15+
{
16+
}

src/Symfony/Component/Config/Loader/Loader.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Config\Loader;
1313

1414
use Symfony\Component\Config\Exception\LoaderLoadException;
15+
use Symfony\Component\Config\Exception\LogicException;
1516

1617
/**
1718
* Loader is the abstract class used by all built-in loaders.
@@ -20,7 +21,7 @@
2021
*/
2122
abstract class Loader implements LoaderInterface
2223
{
23-
protected LoaderResolverInterface $resolver;
24+
protected ?LoaderResolverInterface $resolver = null;
2425

2526
public function __construct(
2627
protected ?string $env = null,
@@ -29,6 +30,10 @@ public function __construct(
2930

3031
public function getResolver(): LoaderResolverInterface
3132
{
33+
if (null === $this->resolver) {
34+
throw new LogicException('Cannot get a resolver if none was set.');
35+
}
36+
3237
return $this->resolver;
3338
}
3439

src/Symfony/Component/Config/Tests/Loader/LoaderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Config\Exception\LoaderLoadException;
16+
use Symfony\Component\Config\Exception\LogicException;
1617
use Symfony\Component\Config\Loader\Loader;
1718
use Symfony\Component\Config\Loader\LoaderInterface;
1819
use Symfony\Component\Config\Loader\LoaderResolverInterface;
@@ -29,6 +30,14 @@ public function testGetSetResolver()
2930
$this->assertSame($resolver, $loader->getResolver(), '->setResolver() sets the resolver loader');
3031
}
3132

33+
public function testGetResolverWithoutSetResolver()
34+
{
35+
$this->expectException(LogicException::class);
36+
37+
$loader = new ProjectLoader1();
38+
$loader->getResolver();
39+
}
40+
3241
public function testResolve()
3342
{
3443
$resolvedLoader = $this->createMock(LoaderInterface::class);
@@ -46,6 +55,14 @@ public function testResolve()
4655
$this->assertSame($resolvedLoader, $loader->resolve('foo.xml'), '->resolve() finds a loader');
4756
}
4857

58+
public function testResolveWithoutSetResolver()
59+
{
60+
$this->expectException(LoaderLoadException::class);
61+
62+
$loader = new ProjectLoader1();
63+
$loader->resolve('foo.xml');
64+
}
65+
4966
public function testResolveWhenResolverCannotFindLoader()
5067
{
5168
$resolver = $this->createMock(LoaderResolverInterface::class);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected function doSend(MessageInterface $message): SlackSentMessage
7878
}
7979

8080
$response = $this->client->request('POST', 'https://'.$this->getEndpoint().'/api/'.$apiMethod, [
81-
'json' => array_filter($options),
81+
'json' => array_filter($options, function ($value): bool { return !\in_array($value, ['', [], null], true); }),
8282
'auth_bearer' => $this->accessToken,
8383
'headers' => [
8484
'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';
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Exception;
13+
14+
class LogicException extends \LogicException
15+
{
16+
}

src/Symfony/Component/Routing/Loader/AttributeClassLoader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Config\Loader\LoaderResolverInterface;
1616
use Symfony\Component\Config\Resource\FileResource;
1717
use Symfony\Component\Routing\Attribute\Route as RouteAnnotation;
18+
use Symfony\Component\Routing\Exception\LogicException;
1819
use Symfony\Component\Routing\Route;
1920
use Symfony\Component\Routing\RouteCollection;
2021

@@ -226,6 +227,7 @@ public function setResolver(LoaderResolverInterface $resolver): void
226227

227228
public function getResolver(): LoaderResolverInterface
228229
{
230+
throw new LogicException(sprintf('The "%s()" method must not be called.', __METHOD__));
229231
}
230232

231233
/**

src/Symfony/Component/Routing/Tests/Loader/AttributeClassLoaderTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Routing\Alias;
16+
use Symfony\Component\Routing\Exception\LogicException;
1617
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\AbstractClassController;
1718
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\ActionPathController;
1819
use Symfony\Component\Routing\Tests\Fixtures\AttributeFixtures\BazClass;
@@ -54,6 +55,14 @@ protected function setUp(?string $env = null): void
5455
$this->loader = new TraceableAttributeClassLoader($env);
5556
}
5657

58+
public function testGetResolver()
59+
{
60+
$this->expectException(LogicException::class);
61+
62+
$loader = new TraceableAttributeClassLoader();
63+
$loader->getResolver();
64+
}
65+
5766
/**
5867
* @dataProvider provideTestSupportsChecksResource
5968
*/

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)