[Notifier] Add unit tests for NullMessage, NullTransport and NullTransportFactory

This commit is contained in:
Jan Schädlich 2020-10-27 13:28:18 +01:00 committed by Jérémy Derussé
parent 27341b5e60
commit 8a78dc2c97
No known key found for this signature in database
GPG Key ID: 2083FA5758C473D2
9 changed files with 280 additions and 0 deletions

View File

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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';
}
}

View File

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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;
}
}

View File

@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;

View File

@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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()];
}
}

View File

@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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;

View File

@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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;
}
}

View File

@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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', ''))
);
}
}

View File

@ -0,0 +1,37 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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 <jan.schaedlich@sensiolabs.de>
*/
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());
}
}

View File

@ -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",