8000 [Notifier] Fix return SentMessage then Messenger not used · symfony/symfony@4197af2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4197af2

Browse files
committed
[Notifier] Fix return SentMessage then Messenger not used
1 parent 2ad08d5 commit 4197af2

File tree

5 files changed

+133
-7
lines changed

5 files changed

+133
-7
lines changed

src/Symfony/Component/Notifier/Chatter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public function supports(MessageInterface $message): bool
5151
public function send(MessageInterface $message): ?SentMessage
5252
{
5353
if (null === $this->bus) {
54-
$this->transport->send($message);
55-
56-
return null;
54+
return $this->transport->send($message);
5755
}
5856

5957
if (null !== $this->dispatcher) {
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace Symfony\Component\Notifier\Tests;
4+
5+
use PHPUnit\Framework\MockObject\MockObject;
6+
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\Messenger\Envelope;
8+
use Symfony\Component\Messenger\MessageBusInterface;
9+
use Symfony\Component\Notifier\Chatter;
10+
use Symfony\Component\Notifier\Message\SentMessage;
11+
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
12+
use Symfony\Component\Notifier\Transport\TransportInterface;
13+
14+
class ChatterTest extends TestCase
15+
{
16+
/** @var MockObject&TransportInterface */
17+
private $transport;
18+
/** @var MockObject&MessageBusInterface */
19+
private $bus;
20+
21+
protected function setUp(): void
22+
{
23+
$this->transport = $this->createMock(TransportInterface::class);
24+
$this->bus = $this->createMock(MessageBusInterface::class);
25+
}
26+
27+
public function testSendWithoutBus()
28+
{
29+
$chatter = new Chatter($this->transport);
30+
31+
$message = new DummyMessage();
32+
33+
$sentMessage = new SentMessage($message, 'any');
34+
35+
$this->transport
36+
->expects($this->once())
37+
->method('send')
38+
->with($message)
39+
->willReturn($sentMessage);
40+
41+
$this->assertSame($sentMessage, $chatter->send($message));
42+
$this->assertSame($message, $sentMessage->getOriginalMessage());
43+
}
44+
45+
public function testSendWithBus()
46+
{
47+
$chatter = new Chatter($this->transport, $this->bus);
48+
49+
$message = new DummyMessage();
50+
51+
$this->transport
52+
->expects($this->never())
53+
->method('send')
54+
->with($message);
55+
56+
$this->bus
57+
->expects($this->once())
58+
->method('dispatch')
59+
->with($message)
60+
->willReturn(new Envelope(new \stdClass()));
61+
;
62+
63+
$this->assertNull($chatter->send($message));
64+
}
65+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
namespace Symfony\Component\Notifier\Tests;
4+
5+
use PHPUnit\Framework\MockObject\MockObject;
6+
use PHPUnit\Framework\TestCase;
7+
use Symfony\Component\Messenger\Envelope;
8+
use Symfony\Component\Messenger\MessageBusInterface;
9+
use Symfony\Component\Notifier\Message\SentMessage;
10+
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
11+
use Symfony\Component\Notifier\Texter;
12+
use Symfony\Component\Notifier\Transport\TransportInterface;
13+
14+
class TexterTest extends TestCase
15+
{
16+
/** @var MockObject&TransportInterface */
17+
private $transport;
18+
/** @var MockObject&MessageBusInterface */
19+
private $bus;
20+
21+
protected function setUp(): void
22+
{
23+
$this->transport = $this->createMock(TransportInterface::class);
24+
$this->bus = $this->createMock(MessageBusInterface::class);
25+
}
26+
27+
public function testSendWithoutBus()
28+
{
29+
$texter = new Texter($this->transport);
30+
31+
$message = new DummyMessage();
32+
$sentMessage = new SentMessage($message, 'any');
33+
34+
$this->transport
35+
->expects($this->once())
36+
->method('send')
37+
->with($message)
38+
->willReturn($sentMessage);
39+
40+
$this->assertSame($sentMessage, $texter->send($message));
41+
$this->assertSame($message, $sentMessage->getOriginalMessage());
42+
}
43+
44+
public function testSendWithBus()
45+
{
46+
$texter = new Texter($this->transport, $this->bus);
47+
48+
$message = new DummyMessage();
49+
50+
$this->transport
51+
->expects($this->never())
52+
->method('send')
53+
->with($message);
54+
55+
$this->bus
56+
->expects($this->once())
57+
->method('dispatch')
58+
->with($message)
59+
->willReturn(new Envelope(new \stdClass()));
60+
;
61+
62+
$this->assertNull($texter->send($message));
63+
}
64+
}

src/Symfony/Component/Notifier/Texter.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ public function supports(MessageInterface $message): bool
5151
public function send(MessageInterface $message): ?SentMessage
5252
{
5353
if (null === $this->bus) {
54-
$this->transport->send($message);
55-
56-
return null;
54+
return $this->transport->send($message);
5755
}
5856

5957
if (null !== $this->dispatcher) {

src/Symfony/Component/Notifier/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
},
2323
"require-dev": {
2424
"symfony/event-dispatcher-contracts": "^2",
25-
"symfony/http-client-contracts": "^2"
25+
"symfony/http-client-contracts": "^2",
26+
"symfony/messenger": "^4.4 || ^5.0"
2627
},
2728
"conflict": {
2829
"symfony/http-kernel": "<4.4",

0 commit comments

Comments
 (0)
0