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

Skip to content

Commit c288bb7

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

File tree

4 files changed

+135
-6
lines changed

4 files changed

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

src/Symfony/Component/Notifier/Texter.php

Copy file name to clipboard
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