[Notifier] Fix return SentMessage then Messenger not used
This commit is contained in:
parent
2ad08d5a02
commit
1245114257
@ -51,9 +51,7 @@ final class Chatter implements ChatterInterface
|
|||||||
public function send(MessageInterface $message): ?SentMessage
|
public function send(MessageInterface $message): ?SentMessage
|
||||||
{
|
{
|
||||||
if (null === $this->bus) {
|
if (null === $this->bus) {
|
||||||
$this->transport->send($message);
|
return $this->transport->send($message);
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->dispatcher) {
|
if (null !== $this->dispatcher) {
|
||||||
|
63
src/Symfony/Component/Notifier/Tests/ChatterTest.php
Normal file
63
src/Symfony/Component/Notifier/Tests/ChatterTest.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Notifier\Tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Messenger\Envelope;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
use Symfony\Component\Notifier\Chatter;
|
||||||
|
use Symfony\Component\Notifier\Message\SentMessage;
|
||||||
|
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
|
||||||
|
use Symfony\Component\Notifier\Transport\TransportInterface;
|
||||||
|
|
||||||
|
class ChatterTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @var MockObject&TransportInterface */
|
||||||
|
private $transport;
|
||||||
|
|
||||||
|
/** @var MockObject&MessageBusInterface */
|
||||||
|
private $bus;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->transport = $this->createMock(TransportInterface::class);
|
||||||
|
$this->bus = $this->createMock(MessageBusInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendWithoutBus()
|
||||||
|
{
|
||||||
|
$message = new DummyMessage();
|
||||||
|
|
||||||
|
$sentMessage = new SentMessage($message, 'any');
|
||||||
|
|
||||||
|
$this->transport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('send')
|
||||||
|
->with($message)
|
||||||
|
->willReturn($sentMessage);
|
||||||
|
|
||||||
|
$chatter = new Chatter($this->transport);
|
||||||
|
$this->assertSame($sentMessage, $chatter->send($message));
|
||||||
|
$this->assertSame($message, $sentMessage->getOriginalMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendWithBus()
|
||||||
|
{
|
||||||
|
$message = new DummyMessage();
|
||||||
|
|
||||||
|
$this->transport
|
||||||
|
->expects($this->never())
|
||||||
|
->method('send')
|
||||||
|
->with($message);
|
||||||
|
|
||||||
|
$this->bus
|
||||||
|
->expects($this->once())
|
||||||
|
->method('dispatch')
|
||||||
|
->with($message)
|
||||||
|
->willReturn(new Envelope(new \stdClass()));
|
||||||
|
|
||||||
|
$chatter = new Chatter($this->transport, $this->bus);
|
||||||
|
$this->assertNull($chatter->send($message));
|
||||||
|
}
|
||||||
|
}
|
62
src/Symfony/Component/Notifier/Tests/TexterTest.php
Normal file
62
src/Symfony/Component/Notifier/Tests/TexterTest.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Symfony\Component\Notifier\Tests;
|
||||||
|
|
||||||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Symfony\Component\Messenger\Envelope;
|
||||||
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
|
use Symfony\Component\Notifier\Message\SentMessage;
|
||||||
|
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
|
||||||
|
use Symfony\Component\Notifier\Texter;
|
||||||
|
use Symfony\Component\Notifier\Transport\TransportInterface;
|
||||||
|
|
||||||
|
class TexterTest extends TestCase
|
||||||
|
{
|
||||||
|
/** @var MockObject&TransportInterface */
|
||||||
|
private $transport;
|
||||||
|
|
||||||
|
/** @var MockObject&MessageBusInterface */
|
||||||
|
private $bus;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
$this->transport = $this->createMock(TransportInterface::class);
|
||||||
|
$this->bus = $this->createMock(MessageBusInterface::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendWithoutBus()
|
||||||
|
{
|
||||||
|
$message = new DummyMessage();
|
||||||
|
$sentMessage = new SentMessage($message, 'any');
|
||||||
|
|
||||||
|
$this->transport
|
||||||
|
->expects($this->once())
|
||||||
|
->method('send')
|
||||||
|
->with($message)
|
||||||
|
->willReturn($sentMessage);
|
||||||
|
|
||||||
|
$texter = new Texter($this->transport);
|
||||||
|
$this->assertSame($sentMessage, $texter->send($message));
|
||||||
|
$this->assertSame($message, $sentMessage->getOriginalMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSendWithBus()
|
||||||
|
{
|
||||||
|
$message = new DummyMessage();
|
||||||
|
|
||||||
|
$this->transport
|
||||||
|
->expects($this->never())
|
||||||
|
->method('send')
|
||||||
|
->with($message);
|
||||||
|
|
||||||
|
$this->bus
|
||||||
|
->expects($this->once())
|
||||||
|
->method('dispatch')
|
||||||
|
->with($message)
|
||||||
|
->willReturn(new Envelope(new \stdClass()));
|
||||||
|
|
||||||
|
$texter = new Texter($this->transport, $this->bus);
|
||||||
|
$this->assertNull($texter->send($message));
|
||||||
|
}
|
||||||
|
}
|
@ -51,9 +51,7 @@ final class Texter implements TexterInterface
|
|||||||
public function send(MessageInterface $message): ?SentMessage
|
public function send(MessageInterface $message): ?SentMessage
|
||||||
{
|
{
|
||||||
if (null === $this->bus) {
|
if (null === $this->bus) {
|
||||||
$this->transport->send($message);
|
return $this->transport->send($message);
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null !== $this->dispatcher) {
|
if (null !== $this->dispatcher) {
|
||||||
|
@ -22,7 +22,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"symfony/event-dispatcher-contracts": "^2",
|
"symfony/event-dispatcher-contracts": "^2",
|
||||||
"symfony/http-client-contracts": "^2"
|
"symfony/http-client-contracts": "^2",
|
||||||
|
"symfony/messenger": "^4.4 || ^5.0"
|
||||||
},
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"symfony/http-kernel": "<4.4",
|
"symfony/http-kernel": "<4.4",
|
||||||
|
Reference in New Issue
Block a user