Skip to content

Commit 0e13d25

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

File tree

4 files changed

+125
-6
lines changed

4 files changed

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

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) {

0 commit comments

Comments
 (0)