10000 [Notifier] Fix return SentMessage then Messenger not used by WaylandAce · Pull Request #40982 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Notifier] Fix return SentMessage then Messenger not used #40982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Notifier] Fix return SentMessage then Messenger not used
  • Loading branch information
WaylandAce committed May 7, 2021
commit 12451142576e7c3bd7c97e9ac93bbb1c07b90420
4 changes: 1 addition & 3 deletions src/Symfony/Component/Notifier/Chatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public function supports(MessageInterface $message): bool
public function send(MessageInterface $message): ?SentMessage
{
if (null === $this->bus) {
$this->transport->send($message);

return null;
return $this->transport->send($message);
}

if (null !== $this->dispatcher) {
Expand Down
63 changes: 63 additions & 0 deletions src/Symfony/Component/Notifier/Tests/ChatterTest.php
Original file line number Diff line number Diff line change
@@ -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 changes: 62 additions & 0 deletions src/Symfony/Component/Notifier/Tests/TexterTest.php
Original file line number Diff line number Diff line change
@@ -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));
}
}
4 changes: 1 addition & 3 deletions src/Symfony/Component/Notifier/Texter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ public function supports(MessageInterface $message): bool
public function send(MessageInterface $message): ?SentMessage
{
if (null === $this->bus) {
$this->transport->send($message);

return null;
return $this->transport->send($message);
}

if (null !== $this->dispatcher) {
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Component/Notifier/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
},
"require-dev": {
"symfony/event-dispatcher-contracts": "^2",
"symfony/http-client-contracts": "^2"
"symfony/http-client-contracts": "^2",
"symfony/messenger": "^4.4 || ^5.0"
},
"conflict": {
"symfony/http-kernel": "<4.4",
Expand Down
0