8000 Merge branch '6.3' into 6.4 · symfony/symfony@6b169e9 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6b169e9

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [TwigBridge] Change return type of Symfony\Bridge\Twig\AppVariable::getSession() [mailer] reset $code variable each iteration for prevent wrong codes to be used bug [mailer] fix EsmtpTransport variable $code definition UrlHelper: minor code style fix [Serializer] Looking for DiscriminatorMap on interfaces when the current object also extends from a class [DoctrineBridge][Security] Rename loadUserByUsername tests to loadUserByIdentifier
2 parents 75768f3 + 38747ae commit 6b169e9

File tree

11 files changed

+75
-12
lines changed

11 files changed

+75
-12
lines changed

src/Symfony/Bridge/Doctrine/Tests/Security/User/EntityUserProviderTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function testRefreshUserGetsUserByPrimaryKey()
4949
$this->assertSame($user1, $provider->refreshUser($user1));
5050
}
5151

52-
public function testLoadUserByUsername()
52+
public function testLoadUserByIdentifier()
5353
{
5454
$em = DoctrineTestHelper::createTestEntityManager();
5555
$this->createSchema($em);
@@ -64,7 +64,7 @@ public function testLoadUserByUsername()
6464
$this->assertSame($user, $provider->loadUserByIdentifier('user1'));
6565
}
6666

67-
public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty()
67+
public function testLoadUserByIdentifierWithUserLoaderRepositoryAndWithoutProperty()
6868
{
6969
$user = new User(1, 1, 'user1');
7070

@@ -86,7 +86,7 @@ public function testLoadUserByUsernameWithUserLoaderRepositoryAndWithoutProperty
8686
$this->assertSame($user, $provider->loadUserByIdentifier('user1'));
8787
}
8888

89-
public function testLoadUserByUsernameWithNonUserLoaderRepositoryAndWithoutProperty()
89+
public function testLoadUserByIdentifierWithNonUserLoaderRepositoryAndWithoutProperty()
9090
{
9191
$this->expectException(\InvalidArgumentException::class);
9292
$this->expectExceptionMessage('You must either make the "Symfony\Bridge\Doctrine\Tests\Fixtures\User" entity Doctrine Repository ("Doctrine\ORM\EntityRepository") implement "Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface" or set the "property" option in the corresponding entity provider configuration.');
@@ -150,7 +150,7 @@ public function testSupportProxy()
150150
$this->assertTrue($provider->supportsClass($user2::class));
151151
}
152152

153-
public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided()
153+
public function testLoadUserByIdentifierShouldLoadUserWhenProperInterfaceProvided()
154154
{
155155
$repository = $this->createMock(UserLoaderRepository::class);
156156
$repository->expects($this->once())
@@ -168,7 +168,7 @@ public function testLoadUserByUserNameShouldLoadUserWhenProperInterfaceProvided(
168168
$provider->loadUserByIdentifier('name');
169169
}
170170

171-
public function testLoadUserByUserNameShouldDeclineInvalidInterface()
171+
public function testLoadUserByIdentifierShouldDeclineInvalidInterface()
172172
{
173173
$this->expectException(\InvalidArgumentException::class);
174174
$repository = $this->createMock(ObjectRepository::class);

src/Symfony/Bridge/Twig/AppVariable.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\RequestStack;
16-
use Symfony\Component\HttpFoundation\Session\Session;
16+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1919
use Symfony\Component\Security\Core\User\UserInterface;
@@ -112,7 +112,7 @@ public function getRequest(): ?Request
112112
/**
113113
* Returns the current session.
114114
*/
115-
public function getSession(): ?Session
115+
public function getSession(): ?SessionInterface
116116
{
117117
if (!isset($this->requestStack)) {
118118
throw new \RuntimeException('The "app.session" variable is not available.');
@@ -171,6 +171,12 @@ public function getFlashes(string|array $types = null): array
171171
return [];
172172
}
173173

174+
// In 7.0 (when symfony/http-foundation: 6.4 is required) this can be updated to
175+
// check if the session is an instance of FlashBagAwareSessionInterface
176+
if (!method_exists($session, 'getFlashBag')) {
177+
return [];
178+
}
179+
174180
if (null === $types || '' === $types || [] === $types) {
175181
return $session->getFlashBag()->all();
176182
}

src/Symfony/Component/HttpFoundation/UrlHelper.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
*/
2222
final class UrlHelper
2323
{
24-
2524
public function __construct(
2625
private RequestStack $requestStack,
2726
private RequestContextAwareInterface|RequestContext|null $requestContext = null,

src/Symfony/Component/Mailer/Tests/Transport/Smtp/EsmtpTransportTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ public function testSetAuthenticators()
192192
$stream->getCommands()
193193
);
194194
}
195+
196+
public function testConstructorWithEmptyAuthenticator()
197+
{
198+
$stream = new DummyStream();
199+
$transport = new EsmtpTransport(stream: $stream);
200+
$transport->setUsername('testuser');
201+
$transport->setPassword('p4ssw0rd');
202+
$transport->setAuthenticators([]); // if no authenticators defined, then there needs to be a TransportException
203+
204+
$message = new Email();
205+
$message->from('sender@example.org');
206+
$message->addTo('recipient@example.org');
207+
$message->text('.');
208+
209+
try {
210+
$transport->send($message);
211+
$this->fail('Symfony\Component\Mailer\Exception\TransportException to be thrown');
212+
} catch (TransportException $e) {
213+
$this->assertStringStartsWith('Failed to find an authenticator supported by the SMTP server, which currently supports: "plain", "login", "cram-md5", "xoauth2".', $e->getMessage());
214+
$this->assertEquals(504, $e->getCode());
215+
}
216+
}
195217
}
196218

197219
class CustomEsmtpTransport extends EsmtpTransport

src/Symfony/Component/Mailer/Transport/Smtp/EsmtpTransport.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ private function handleAuth(array $modes): void
184184
return;
185185
}
186186

187+
$code = null;
187188
$authNames = [];
188189
$errors = [];
189190
$modes = array_map('strtolower', $modes);

src/Symfony/Component/Security/Core/Tests/User/ChainUserProviderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
class ChainUserProviderTest extends TestCase
2525
{
26-
public function testLoadUserByUsername()
26+
public function testLoadUserByIdentifier()
2727
{
2828
$provider1 = $this->createMock(InMemoryUserProvider::class);
2929
$provider1
@@ -45,7 +45,7 @@ public function testLoadUserByUsername()
4545
$this->assertSame($account, $provider->loadUserByIdentifier('foo'));
4646
}
4747

48-
public function testLoadUserByUsernameThrowsUserNotFoundException()
48+
public function testLoadUserByIdentifierThrowsUserNotFoundException()
4949
{
5050
$this->expectException(UserNotFoundException::class);
5151
$provider1 = $this->createMock(InMemoryUserProvider::class);

src/Symfony/Component/Security/Core/Tests/User/InMemoryUserProviderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testCreateUserAlreadyExist()
6868
$provider->createUser(new InMemoryUser('fabien', 'foo'));
6969
}
7070

71-
public function testLoadUserByUsernameDoesNotExist()
71+
public function testLoadUserByIdentifierDoesNotExist()
7272
{
7373
$this->expectException(UserNotFoundException::class);
7474
$provider = new InMemoryUserProvider();

src/Symfony/Component/Serializer/Mapping/ClassDiscriminatorFromClassMetadata.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ private function resolveMappingForMappedObject(object|string $object): ?ClassDis
6565
{
6666
$reflectionClass = new \ReflectionClass($object);
6767
if ($parentClass = $reflectionClass->getParentClass()) {
68-
return $this->getMappingForMappedObject($parentClass->getName());
68+
if (null !== ($parentMapping = $this->getMappingForMappedObject($parentClass->getName()))) {
69+
return $parentMapping;
70+
}
6971
}
7072

7173
foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {

src/Symfony/Component/Serializer/Tests/Fixtures/DummyMessageInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#[DiscriminatorMap(typeProperty: 'type', mapping: [
2020
'one' => DummyMessageNumberOne::class,
2121
'two' => DummyMessageNumberTwo::class,
22+
'three' => DummyMessageNumberThree::class,
2223
])]
2324
interface DummyMessageInterface
2425
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Serializer\Tests\Fixtures;
13+
14+
/**
15+
* @author Samuel Roze <samuel.roze@gmail.com>
16+
*/
17+
class DummyMessageNumberThree extends \stdClass implements DummyMessageInterface
18+
{
19+
}

src/Symfony/Component/Serializer/Tests/SerializerTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use Symfony\Component\Serializer\Tests\Fixtures\DummyFirstChildQuux;
5454
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageInterface;
5555
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberOne;
56+
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberThree;
5657
use Symfony\Component\Serializer\Tests\Fixtures\DummyMessageNumberTwo;
5758
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumConstructor;
5859
use Symfony\Component\Serializer\Tests\Fixtures\DummyObjectWithEnumProperty;
@@ -484,6 +485,18 @@ public function testDeserializeAndSerializeNestedInterfacedObjectsWithTheClassMe
484485
$this->assertEquals($example, $deserialized);
485486
}
486487

488+
public function testDeserializeAndSerializeNestedAbstractAndInterfacedObjectsWithTheClassMetadataDiscriminator()
489+
{
490+
$example = new DummyMessageNumberThree();
491+
492+
$serializer = $this->serializerWithClassDiscriminator();
493+
494+
$serialized = $serializer->serialize($example, 'json');
495+
$deserialized = $serializer->deserialize($serialized, DummyMessageInterface::class, 'json');
496+
497+
$this->assertEquals($example, $deserialized);
498+
}
499+
487500
public function testExceptionWhenTypeIsNotKnownInDiscriminator()
488501
{
489502
try {

0 commit comments

Comments
 (0)
0