Skip to content

Commit c4ff074

Browse files
committed
Merge branch '5.1'
* 5.1: [Validator] fix tests ensure that the validator is a mock object for backwards-compatibility [Messenger] Fix BC layer for stamps moved into separate packages
2 parents 779303a + b7d4a1c commit c4ff074

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/Symfony/Component/Messenger/Envelope.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function withoutAll(string $stampFqcn): self
7373
{
7474
$cloned = clone $this;
7575

76-
unset($cloned->stamps[$stampFqcn]);
76+
unset($cloned->stamps[$this->resolveAlias($stampFqcn)]);
7777

7878
return $cloned;
7979
}
@@ -84,6 +84,7 @@ public function withoutAll(string $stampFqcn): self
8484
public function withoutStampsOfType(string $type): self
8585
{
8686
$cloned = clone $this;
87+
$type = $this->resolveAlias($type);
8788

8889
foreach ($cloned->stamps as $class => $stamps) {
8990
if ($class === $type || is_subclass_of($class, $type)) {
@@ -96,7 +97,7 @@ public function withoutStampsOfType(string $type): self
9697

9798
public function last(string $stampFqcn): ?StampInterface
9899
{
99-
return isset($this->stamps[$stampFqcn]) ? end($this->stamps[$stampFqcn]) : null;
100+
return isset($this->stamps[$stampFqcn = $this->resolveAlias($stampFqcn)]) ? end($this->stamps[$stampFqcn]) : null;
100101
}
101102

102103
/**
@@ -105,7 +106,7 @@ public function last(string $stampFqcn): ?StampInterface
105106
public function all(string $stampFqcn = null): array
106107
{
107108
if (null !== $stampFqcn) {
108-
return $this->stamps[$stampFqcn] ?? [];
109+
return $this->stamps[$this->resolveAlias($stampFqcn)] ?? [];
109110
}
110111

111112
return $this->stamps;
@@ -118,4 +119,14 @@ public function getMessage(): object
118119
{
119120
return $this->message;
120121
}
122+
123+
/**
124+
* BC to be removed in 6.0.
125+
*/
126+
private function resolveAlias(string $fqcn): string
127+
{
128+
static $resolved;
129+
130+
return $resolved[$fqcn] ?? ($resolved[$fqcn] = (new \ReflectionClass($fqcn))->getName());
131+
}
121132
}

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@
1212
namespace Symfony\Component\Messenger\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineReceivedStamp;
16+
use Symfony\Component\Messenger\Bridge\Redis\Transport\RedisReceivedStamp;
1517
use Symfony\Component\Messenger\Envelope;
1618
use Symfony\Component\Messenger\Stamp\DelayStamp;
1719
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
1820
use Symfony\Component\Messenger\Stamp\StampInterface;
1921
use Symfony\Component\Messenger\Stamp\ValidationStamp;
2022
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
23+
use Symfony\Component\Messenger\Transport\Doctrine\DoctrineReceivedStamp as LegacyDoctrineReceivedStamp;
24+
use Symfony\Component\Messenger\Transport\RedisExt\RedisReceivedStamp as LegacyRedisReceivedStamp;
2125

2226
/**
2327
* @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
@@ -114,6 +118,40 @@ public function testWrapWithEnvelope()
114118
$this->assertCount(1, $envelope->all(DelayStamp::class));
115119
$this->assertCount(1, $envelope->all(ReceivedStamp::class));
116120
}
121+
122+
/**
123+
* To be removed in 6.0.
124+
*
125+
* @group legacy
126+
*/
127+
public function testWithAliases()
128+
{
129+
$envelope = new Envelope(new \stdClass(), [
130+
$s1 = new DoctrineReceivedStamp(1),
131+
$s2 = new RedisReceivedStamp(2),
132+
$s3 = new DoctrineReceivedStamp(3),
133+
]);
134+
135+
self::assertSame([
136+
DoctrineReceivedStamp::class => [$s1, $s3],
137+
RedisReceivedStamp::class => [$s2],
138+
], $envelope->all());
139+
140+
self::assertSame([$s1, $s3], $envelope->all(DoctrineReceivedStamp::class));
141+
self::assertSame([$s2], $envelope->all(RedisReceivedStamp::class));
142+
143+
self::assertSame([$s1, $s3], $envelope->all(LegacyDoctrineReceivedStamp::class));
144+
self::assertSame([$s2], $envelope->all(LegacyRedisReceivedStamp::class));
145+
146+
self::assertSame($s3, $envelope->last(LegacyDoctrineReceivedStamp::class));
147+
self::assertSame($s2, $envelope->last(LegacyRedisReceivedStamp::class));
148+
149+
self::assertSame([RedisReceivedStamp::class => [$s2]], $envelope->withoutAll(LegacyDoctrineReceivedStamp::class)->all());
150+
self::assertSame([DoctrineReceivedStamp::class => [$s1, $s3]], $envelope->withoutAll(LegacyRedisReceivedStamp::class)->all());
151+
152+
self::assertSame([RedisReceivedStamp::class => [$s2]], $envelope->withoutStampsOfType(LegacyDoctrineReceivedStamp::class)->all());
153+
self::assertSame([DoctrineReceivedStamp::class => [$s1, $s3]], $envelope->withoutStampsOfType(LegacyRedisReceivedStamp::class)->all());
154+
}
117155
}
118156

119157
interface DummyFooBarStampInterface extends StampInterface

src/Symfony/Component/Validator/Test/ConstraintValidatorTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function createContext()
115115
$validator->expects($this->any())
116116
->method('inContext')
117117
->with($context)
118-
->willReturn(new AssertingContextualValidator());
118+
->willReturn($this->getMockBuilder(AssertingContextualValidator::class)->setMethods(null)->getMock());
119119

120120
return $context;
121121
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy