Skip to content

Commit e0c9ecb

Browse files
committed
Merge branch '4.3'
* 4.3: (22 commits) [Messenger] Fix incorrect error when symfony/serializer is missing Allow WrappedListener to describe uncallable listeners. [HttpClient] fix handling exceptions thrown before first mock chunk [Filesystem] fix wrong method call casing [HttpClient] fix test [Translation] Fixed issue with new vs old TranslatorInterface in TranslationDataCollector Don't reference symfony/security [HttpClient] display proper error message on TransportException when curl is used [FrameworkBundle] fix named autowiring aliases for TagAwareCacheInterface [Cache] improve logged messages [FrameworkBundle] improve cs [Mime][HttpFoundation] Added mime type audio/x-hx-aac-adts bumped Symfony version to 4.3.0 updated VERSION for 4.3.0-BETA2 updated CHANGELOG for 4.3.0-BETA2 [HttpClient] Only use CURLMOPT_MAX_HOST_CONNECTIONS & CURL_VERSION_HTTP2 if defined [Security] fixed a fatal error when upgrading from 4.2 [HttpClient] Allow arrays as query parameters Throws UnrecoverableMessageHandlingException when passed invalid entity manager name for Doctrine middlewares [Messenger] Make redis Connection::get() non blocking by default ...
2 parents e9c7633 + 4fed3fe commit e0c9ecb

File tree

14 files changed

+143
-20
lines changed

14 files changed

+143
-20
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ CHANGELOG
44
4.3.0
55
-----
66

7+
* Added `NonSendableStampInterface` that a stamp can implement if
8+
it should not be sent to a transport. Transport serializers
9+
must now check for these stamps and not encode them.
710
* [BC BREAK] `SendersLocatorInterface` has an additional method:
811
`getSenderByAlias()`.
912
* Removed argument `?bool &$handle = false` from `SendersLocatorInterface::getSenders`

Envelope.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,22 @@ public function withoutAll(string $stampFqcn): self
8080
return $cloned;
8181
}
8282

83+
/**
84+
* Removes all stamps that implement the given type.
85+
*/
86+
public function withoutStampsOfType(string $type): self
87+
{
88+
$cloned = clone $this;
89+
90+
foreach ($cloned->stamps as $class => $stamps) {
91+
if ($class === $type || \is_subclass_of($class, $type)) {
92+
unset($cloned->stamps[$class]);
93+
}
94+
}
95+
96+
return $cloned;
97+
}
98+
8399
public function last(string $stampFqcn): ?StampInterface
84100
{
85101
return isset($this->stamps[$stampFqcn]) ? end($this->stamps[$stampFqcn]) : null;

Stamp/NonSendableStampInterface.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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\Messenger\Stamp;
13+
14+
/**
15+
* A stamp that should not be included with the Envelope if sent to a transport.
16+
*
17+
* @author Ryan Weaver <ryan@symfonycasts.com>
18+
*
19+
* @experimental in 4.3
20+
*/
21+
interface NonSendableStampInterface extends StampInterface
22+
{
23+
}

Tests/EnvelopeTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Messenger\Envelope;
1616
use Symfony\Component\Messenger\Stamp\DelayStamp;
1717
use Symfony\Component\Messenger\Stamp\ReceivedStamp;
18+
use Symfony\Component\Messenger\Stamp\StampInterface;
1819
use Symfony\Component\Messenger\Stamp\ValidationStamp;
1920
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
2021

@@ -50,6 +51,30 @@ public function testWithoutAll()
5051
$this->assertCount(1, $envelope->all(DelayStamp::class));
5152
}
5253

54+
public function testWithoutStampsOfType()
55+
{
56+
$envelope = new Envelope(new DummyMessage('dummy'), [
57+
new ReceivedStamp('transport1'),
58+
new DelayStamp(5000),
59+
new DummyExtendsDelayStamp(5000),
60+
new DummyImplementsFooBarStampInterface(),
61+
]);
62+
63+
$envelope2 = $envelope->withoutStampsOfType(DummyNothingImplementsMeStampInterface::class);
64+
$this->assertEquals($envelope, $envelope2);
65+
66+
$envelope3 = $envelope2->withoutStampsOfType(ReceivedStamp::class);
67+
$this->assertEmpty($envelope3->all(ReceivedStamp::class));
68+
69+
$envelope4 = $envelope3->withoutStampsOfType(DelayStamp::class);
70+
$this->assertEmpty($envelope4->all(DelayStamp::class));
71+
$this->assertEmpty($envelope4->all(DummyExtendsDelayStamp::class));
72+
73+
$envelope5 = $envelope4->withoutStampsOfType(DummyFooBarStampInterface::class);
74+
$this->assertEmpty($envelope5->all(DummyImplementsFooBarStampInterface::class));
75+
$this->assertEmpty($envelope5->all());
76+
}
77+
5378
public function testLast()
5479
{
5580
$receivedStamp = new ReceivedStamp('transport');
@@ -92,3 +117,16 @@ public function testWrapWithEnvelope()
92117
$this->assertCount(1, $envelope->all(ReceivedStamp::class));
93118
}
94119
}
120+
121+
class DummyExtendsDelayStamp extends DelayStamp
122+
{
123+
}
124+
interface DummyFooBarStampInterface extends StampInterface
125+
{
126+
}
127+
interface DummyNothingImplementsMeStampInterface extends StampInterface
128+
{
129+
}
130+
class DummyImplementsFooBarStampInterface implements DummyFooBarStampInterface
131+
{
132+
}

Tests/Transport/RedisExt/ConnectionTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function testFromDsnWithOptions()
4646
'host' => 'localhost',
4747
'port' => 6379,
4848
], [
49-
'blocking_timeout' => 30,
49+
'serializer' => 2,
5050
]),
51-
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['blocking_timeout' => 30])
51+
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['serializer' => 2])
5252
);
5353
}
5454

@@ -59,9 +59,9 @@ public function testFromDsnWithQueryOptions()
5959
'host' => 'localhost',
6060
'port' => 6379,
6161
], [
62-
'blocking_timeout' => 30,
62+
'serializer' => 2,
6363
]),
64-
Connection::fromDsn('redis://localhost/queue/group1/consumer1?blocking_timeout=30')
64+
Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2')
6565
);
6666
}
6767

@@ -134,16 +134,20 @@ public function testGetAfterReject()
134134
$redis->del('messenger-rejectthenget');
135135
}
136136

137-
public function testBlockingTimeout()
137+
public function testGetNonBlocking()
138138
{
139139
$redis = new \Redis();
140-
$connection = Connection::fromDsn('redis://localhost/messenger-blockingtimeout', ['blocking_timeout' => 1], $redis);
140+
141+
$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', [], $redis);
141142
try {
142143
$connection->setup();
143144
} catch (TransportException $e) {
144145
}
145146

146-
$this->assertNull($connection->get());
147-
$redis->del('messenger-blockingtimeout');
147+
$this->assertNull($connection->get()); // no message, should return null immediately
148+
$connection->add('1', []);
149+
$this->assertNotEmpty($message = $connection->get());
150+
$connection->reject($message['id']);
151+
$redis->del('messenger-getnonblocking');
148152
}
149153
}

Tests/Transport/Serialization/PhpSerializerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Messenger\Envelope;
1616
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
17+
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
1718
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
1819
use Symfony\Component\Messenger\Transport\Serialization\PhpSerializer;
1920

@@ -63,4 +64,20 @@ public function testDecodingFailsWithBadClass()
6364
'body' => 'O:13:"ReceivedSt0mp":0:{}',
6465
]);
6566
}
67+
68+
public function testEncodedSkipsNonEncodeableStamps()
69+
{
70+
$serializer = new PhpSerializer();
71+
72+
$envelope = new Envelope(new DummyMessage('Hello'), [
73+
new DummyPhpSerializerNonSendableStamp(),
74+
]);
75+
76+
$encoded = $serializer->encode($envelope);
77+
$this->assertNotContains('DummyPhpSerializerNonSendableStamp', $encoded['body']);
78+
}
79+
}
80+
81+
class DummyPhpSerializerNonSendableStamp implements NonSendableStampInterface
82+
{
6683
}

Tests/Transport/Serialization/SerializerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\Messenger\Envelope;
1616
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
17+
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
1718
use Symfony\Component\Messenger\Stamp\SerializerStamp;
1819
use Symfony\Component\Messenger\Stamp\ValidationStamp;
1920
use Symfony\Component\Messenger\Tests\Fixtures\DummyMessage;
@@ -193,4 +194,19 @@ public function testDecodingFailsWithBadClass()
193194
'headers' => ['type' => 'NonExistentClass'],
194195
]);
195196
}
197+
198+
public function testEncodedSkipsNonEncodeableStamps()
199+
{
200+
$serializer = new Serializer();
201+
202+
$envelope = new Envelope(new DummyMessage('Hello'), [
203+
new DummySymfonySerializerNonSendableStamp(),
204+
]);
205+
206+
$encoded = $serializer->encode($envelope);
207+
$this->assertNotContains('DummySymfonySerializerNonSendableStamp', print_r($encoded['headers'], true));
208+
}
209+
}
210+
class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface
211+
{
196212
}

Transport/AmqpExt/AmqpReceivedStamp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Messenger\Transport\AmqpExt;
1313

14-
use Symfony\Component\Messenger\Stamp\StampInterface;
14+
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
1515

1616
/**
1717
* Stamp applied when a message is received from Amqp.
1818
*
1919
* @experimental in 4.3
2020
*/
21-
class AmqpReceivedStamp implements StampInterface
21+
class AmqpReceivedStamp implements NonSendableStampInterface
2222
{
2323
private $amqpEnvelope;
2424
private $queueName;

Transport/Doctrine/DoctrineReceivedStamp.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
namespace Symfony\Component\Messenger\Transport\Doctrine;
1313

14-
use Symfony\Component\Messenger\Stamp\StampInterface;
14+
use Symfony\Component\Messenger\Stamp\NonSendableStampInterface;
1515

1616
/**
1717
* @author Vincent Touzet <vincent.touzet@gmail.com>
1818
*
1919
* @experimental in 4.3
2020
*/
21-
class DoctrineReceivedStamp implements StampInterface
21+
class DoctrineReceivedStamp implements NonSendableStampInterface
2222
{
2323
private $id;
2424

Transport/RedisExt/Connection.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class Connection
3131
private $stream;
3232
private $group;
3333
private $consumer;
34-
private $blockingTimeout;
3534
private $couldHavePendingMessages = true;
3635

3736
public function __construct(array $configuration, array $connectionCredentials = [], array $redisOptions = [], \Redis $redis = null)
@@ -42,7 +41,6 @@ public function __construct(array $configuration, array $connectionCredentials =
4241
$this->stream = $configuration['stream'] ?? '' ?: 'messages';
4342
$this->group = $configuration['group'] ?? '' ?: 'symfony';
4443
$this->consumer = $configuration['consumer'] ?? '' ?: 'consumer';
45-
$this->blockingTimeout = $redisOptions['blocking_timeout'] ?? null;
4644
}
4745

4846
public static function fromDsn(string $dsn, array $redisOptions = [], \Redis $redis = null): self
@@ -83,8 +81,7 @@ public function get(): ?array
8381
$this->group,
8482
$this->consumer,
8583
[$this->stream => $messageId],
86-
1,
87-
$this->blockingTimeout
84+
1
8885
);
8986
} catch (\RedisException $e) {
9087
}
@@ -142,7 +139,7 @@ public function reject(string $id): void
142139
}
143140
}
144141

145-
public function add(string $body, array $headers)
142+
public function add(string $body, array $headers): void
146143
{
147144
$e = null;
148145
try {

0 commit comments

Comments
 (0)