[Notifier] Add unit tests for NullMessage, NullTransport and NullTransportFactory
This commit is contained in:
parent
27341b5e60
commit
8a78dc2c97
@ -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';
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?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;
|
namespace Symfony\Component\Notifier\Tests\Message;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
@ -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()];
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,14 @@
|
|||||||
<?php
|
<?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;
|
namespace Symfony\Component\Notifier\Tests\Message;
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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', ''))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,10 @@
|
|||||||
"symfony/polyfill-php80": "^1.15",
|
"symfony/polyfill-php80": "^1.15",
|
||||||
"psr/log": "~1.0"
|
"psr/log": "~1.0"
|
||||||
},
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"symfony/event-dispatcher-contracts": "^2",
|
||||||
|
"symfony/http-client-contracts": "^2"
|
||||||
|
},
|
||||||
"conflict": {
|
"conflict": {
|
||||||
"symfony/http-kernel": "<4.4",
|
"symfony/http-kernel": "<4.4",
|
||||||
"symfony/firebase-notifier": "<5.2",
|
"symfony/firebase-notifier": "<5.2",
|
||||||
|
Reference in New Issue
Block a user