10000 Merge branch '5.2' into 5.3 · symfony/symfony@07ba79a · GitHub
[go: up one dir, main page]

Skip to content

Commit 07ba79a

Browse files
committed
Merge branch '5.2' into 5.3
* 5.2: Do not use static::class for final messages prevent reflection usages when classes do not exist [HttpFoundation] allow savePath of NativeFileSessionHandler to be null
2 parents 6b1f17f + 147713a commit 07ba79a

File tree

6 files changed

+82
-4
lines changed

6 files changed

+82
-4
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/Handler/SessionHandlerFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public static function createHandler($connection): AbstractSessionHandler
4848
case !\is_string($connection):
4949
throw new \InvalidArgumentException(sprintf('Unsupported Connection: "%s".', get_debug_type($connection)));
5050
case 0 === strpos($connection, 'file://'):
51-
return new StrictSessionHandler(new NativeFileSessionHandler(substr($connection, 7)));
51+
$savePath = substr($connection, 7);
52+
53+
return new StrictSessionHandler(new NativeFileSessionHandler('' === $savePath ? null : $savePath));
5254

5355
case 0 === strpos($connection, 'redis:'):
5456
case 0 === strpos($connection, 'rediss:'):
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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\HttpFoundation\Tests\Session\Storage\Handler;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\SessionHandlerFactory;
16+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
17+
18+
/**
19+
* Test class for SessionHandlerFactory.
20+
*
21+
* @author Simon <simon.chrzanowski@quentic.com>
22+
*
23+
* @runTestsInSeparateProcesses
24+
* @preserveGlobalState disabled
25+
*/
26+
class SessionHandlerFactoryTest extends TestCase
27+
{
28+
/**
29+
* @dataProvider provideConnectionDSN
30+
*/
31+
public function testCreateHandler(string $connectionDSN, string $expectedPath, string $expectedHandlerType)
32+
{
33+
$handler = SessionHandlerFactory::createHandler($connectionDSN);
34+
35+
$this->assertInstanceOf($expectedHandlerType, $handler);
36+
$this->assertEquals($expectedPath, ini_get('session.save_path'));
37+
}
38+
39+
public function provideConnectionDSN(): array
40+
{
41+
$base = sys_get_temp_dir();
42+
43+
return [
44+
'native file handler using save_path from php.ini' => ['connectionDSN' => 'file://', 'expectedPath' => ini_get('session.save_path'), 'expectedHandlerType' => StrictSessionHandler::class],
45+
'native file handler using provided save_path' => ['connectionDSN' => 'file://'.$base.'/session/storage', 'expectedPath' => $base.'/session/storage', 'expectedHandlerType' => StrictSessionHandler::class],
46+
];
47+
}
48+
}

src/Symfony/Component/Messenger/Envelope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ private function resolveAlias(string $fqcn): string
127127
{
128128
static $resolved;
129129

130-
return $resolved[$fqcn] ?? ($resolved[$fqcn] = (new \ReflectionClass($fqcn))->getName());
130+
return $resolved[$fqcn] ?? ($resolved[$fqcn] = class_exists($fqcn) ? (new \ReflectionClass($fqcn))->getName() : $fqcn);
131131
}
132132
}

src/Symfony/Component/Messenger/Tests/EnvelopeTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ public function testWithoutAll()
5555
$this->assertCount(1, $envelope->all(DelayStamp::class));
5656
}
5757

58+
public function testWithoutAllWithNonExistentStampClass()
59+
{
60+
$envelope = new Envelope(new DummyMessage('dummy'));
61+
62+
$this->assertInstanceOf(Envelope::class, $envelope->withoutAll(NonExistentStamp::class));
63+
}
64+
5865
public function testWithoutStampsOfType()
5966
{
6067
$envelope = new Envelope(new DummyMessage('dummy'), [
@@ -77,6 +84,13 @@ public function testWithoutStampsOfType()
7784
$this->assertEmpty($envelope5->all());
7885
}
7986

87+
public function testWithoutStampsOfTypeWithNonExistentStampClass()
88+
{
89+
$envelope = new Envelope(new DummyMessage('dummy'));
90+
91+
$this->assertInstanceOf(Envelope::class, $envelope->withoutStampsOfType(NonExistentStamp::class));
92+
}
93+
8094
public function testLast()
8195
{
8296
$receivedStamp = new ReceivedStamp('transport');
@@ -86,6 +100,13 @@ public function testLast()
86100
$this->assertNull($envelope->last(ValidationStamp::class));
87101
}
88102

103+
public function testLastWithNonExistentStampClass()
104+
{
105+
$envelope = new Envelope(new DummyMessage('dummy'));
106+
107+
$this->assertNull($envelope->last(NonExistentStamp::class));
108+
}
109+
89110
public function testAll()
90111
{
91112
$envelope = (new Envelope($dummy = new DummyMessage('dummy')))
@@ -100,6 +121,13 @@ public function testAll()
100121
$this->assertSame($validationStamp, $stamps[ValidationStamp::class][0]);
101122
}
102123

124+
public function testAllWithNonExistentStampClass()
125+
{
126+
$envelope = new Envelope(new DummyMessage('dummy'));
127+
128+
$this->assertSame([], $envelope->all(NonExistentStamp::class));
129+
}
130+
103131
public function testWrapWithMessage()
104132
{
105133
$message = new \stdClass();

src/Symfony/Component/Notifier/Message/EmailMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct(RawMessage $message, Envelope $envelope = null)
3737
public static function fromNotification(Notification $notification, EmailRecipientInterface $recipient): self
3838
{
3939
if ('' === $reci B6A6 pient->getEmail()) {
40-
throw new InvalidArgumentException(sprintf('"%s" needs an email, it cannot be empty.', static::class));
40+
throw new InvalidArgumentException(sprintf('"%s" needs an email, it cannot be empty.', __CLASS__));
4141
}
4242

4343
if (!class_exists(NotificationEmail::class)) {

src/Symfony/Component/Notifier/Message/SmsMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class SmsMessage implements MessageInterface
2727
public function __construct(string $phone, string $subject)
2828
{
2929
if ('' === $phone) {
30-
throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', static::class));
30+
throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', __CLASS__));
3131
}
3232

3333
$this->subject = $subject;

0 commit comments

Comments
 (0)
0