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

Skip to content

Commit 9a2526d

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

File tree

4 files changed

+126
-6
lines changed

4 files changed

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

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