diff --git a/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithTransport.php b/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithTransport.php new file mode 100644 index 0000000000..d46576f46b --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithTransport.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Message; + +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\MessageOptionsInterface; + +/** + * @author Jan Schädlich + */ +class DummyMessageWithTransport implements MessageInterface +{ + public function getRecipientId(): ?string + { + return 'recipient_id'; + } + + public function getSubject(): string + { + return 'subject'; + } + + public function getOptions(): ?MessageOptionsInterface + { + return null; + } + + public function getTransport(): ?string + { + return 'transport'; + } +} diff --git a/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithoutTransport.php b/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithoutTransport.php new file mode 100644 index 0000000000..98d8a98e75 --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Message/DummyMessageWithoutTransport.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Message; + +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\MessageOptionsInterface; + +/** + * @author Jan Schädlich + */ +class DummyMessageWithoutTransport implements MessageInterface +{ + public function getRecipientId(): ?string + { + return 'recipient_id'; + } + + public function getSubject(): string + { + return 'subject'; + } + + public function getOptions(): ?MessageOptionsInterface + { + return null; + } + + public function getTransport(): ?string + { + return null; + } +} diff --git a/src/Symfony/Component/Notifier/Tests/Message/EmailMessageTest.php b/src/Symfony/Component/Notifier/Tests/Message/EmailMessageTest.php index ae341bfc30..44a645aa3b 100644 --- a/src/Symfony/Component/Notifier/Tests/Message/EmailMessageTest.php +++ b/src/Symfony/Component/Notifier/Tests/Message/EmailMessageTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Notifier\Tests\Message; use PHPUnit\Framework\TestCase; diff --git a/src/Symfony/Component/Notifier/Tests/Message/NullMessageTest.php b/src/Symfony/Component/Notifier/Tests/Message/NullMessageTest.php new file mode 100644 index 0000000000..9213fde370 --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Message/NullMessageTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Message; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\NullMessage; + +/** + * @author Jan Schädlich + */ +class NullMessageTest extends TestCase +{ + /** + * @dataProvider messageDataProvider + */ + public function testCanBeConstructed(MessageInterface $message) + { + $nullMessage = new NullMessage($message); + + $this->assertSame($message->getSubject(), $nullMessage->getSubject()); + $this->assertSame($message->getRecipientId(), $nullMessage->getRecipientId()); + $this->assertSame($message->getOptions(), $nullMessage->getOptions()); + + (null === $message->getTransport()) + ? $this->assertSame('null', $nullMessage->getTransport()) + : $this->assertSame($message->getTransport(), $nullMessage->getTransport()); + } + + public function messageDataProvider(): \Generator + { + yield [new DummyMessageWithoutTransport()]; + yield [new DummyMessageWithTransport()]; + } +} diff --git a/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php b/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php index adc3e859ce..5dd0875a6f 100644 --- a/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php +++ b/src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php @@ -1,5 +1,14 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Symfony\Component\Notifier\Tests\Message; use PHPUnit\Framework\TestCase; diff --git a/src/Symfony/Component/Notifier/Tests/Transport/DummyMessage.php b/src/Symfony/Component/Notifier/Tests/Transport/DummyMessage.php new file mode 100644 index 0000000000..e07592d602 --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Transport/DummyMessage.php @@ -0,0 +1,41 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Transport; + +use Symfony\Component\Notifier\Message\MessageInterface; +use Symfony\Component\Notifier\Message\MessageOptionsInterface; + +/** + * @author Jan Schädlich + */ +class DummyMessage implements MessageInterface +{ + public function getRecipientId(): ?string + { + return 'recipient_id'; + } + + public function getSubject(): string + { + return 'subject'; + } + + public function getOptions(): ?MessageOptionsInterface + { + return null; + } + + public function getTransport(): ?string + { + return null; + } +} diff --git a/src/Symfony/Component/Notifier/Tests/Transport/NullTransportFactoryTest.php b/src/Symfony/Component/Notifier/Tests/Transport/NullTransportFactoryTest.php new file mode 100644 index 0000000000..a2682a7957 --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Transport/NullTransportFactoryTest.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Transport; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Notifier\Exception\UnsupportedSchemeException; +use Symfony\Component\Notifier\Transport\Dsn; +use Symfony\Component\Notifier\Transport\NullTransport; +use Symfony\Component\Notifier\Transport\NullTransportFactory; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; + +/** + * @author Jan Schädlich + */ +class NullTransportFactoryTest extends TestCase +{ + /** + * @var NullTransportFactory + */ + private $nullTransportFactory; + + protected function setUp(): void + { + $this->nullTransportFactory = new NullTransportFactory( + $this->createMock(EventDispatcherInterface::class), + $this->createMock(HttpClientInterface::class) + ); + } + + public function testCreateThrowsUnsupportedSchemeException() + { + $this->expectException(UnsupportedSchemeException::class); + + $this->nullTransportFactory->create(new Dsn('foo', '')); + } + + public function testCreate() + { + $this->assertInstanceOf( + NullTransport::class, + $this->nullTransportFactory->create(new Dsn('null', '')) + ); + } +} diff --git a/src/Symfony/Component/Notifier/Tests/Transport/NullTransportTest.php b/src/Symfony/Component/Notifier/Tests/Transport/NullTransportTest.php new file mode 100644 index 0000000000..a1481fb8df --- /dev/null +++ b/src/Symfony/Component/Notifier/Tests/Transport/NullTransportTest.php @@ -0,0 +1,37 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Notifier\Tests\Transport; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Notifier\Transport\NullTransport; +use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; + +/** + * @author Jan Schädlich + */ +class NullTransportTest extends TestCase +{ + public function testToString() + { + $this->assertEquals('null', (string) (new NullTransport())); + } + + public function testSend() + { + $nullTransport = new NullTransport( + $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class) + ); + + $eventDispatcherMock->expects($this->once())->method('dispatch'); + $nullTransport->send(new DummyMessage()); + } +} diff --git a/src/Symfony/Component/Notifier/composer.json b/src/Symfony/Component/Notifier/composer.json index c0cbbff019..b6e6150d06 100644 --- a/src/Symfony/Component/Notifier/composer.json +++ b/src/Symfony/Component/Notifier/composer.json @@ -20,6 +20,10 @@ "symfony/polyfill-php80": "^1.15", "psr/log": "~1.0" }, + "require-dev": { + "symfony/event-dispatcher-contracts": "^2", + "symfony/http-client-contracts": "^2" + }, "conflict": { "symfony/http-kernel": "<4.4", "symfony/firebase-notifier": "<5.2",