Skip to content

Commit 0dfbeb4

Browse files
committed
minor #38842 [Notifier] Add unit tests for NullMessage, NullTransport and NullTransportFactory (jschaedl)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Notifier] Add unit tests for NullMessage, NullTransport and NullTransportFactory | Q | A | ------------- | --- | Branch? | 5.x | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | - <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | - <!-- required for new features --> <!-- Replace this notice by a short README for your feature/bugfix. This will help people understand your PR and can be used as a start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - Never break backward compatibility (see https://symfony.com/bc). - Bug fixes must be submitted against the lowest maintained branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too.) - Features and deprecations must be submitted against branch 5.x. --> Commits ------- 8a78dc2 [Notifier] Add unit tests for NullMessage, NullTransport and NullTransportFactory
2 parents 6ddb93d + 8a78dc2 commit 0dfbeb4

9 files changed

+280
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Message;
13+
14+
use Symfony\Component\Notifier\Message\MessageInterface;
15+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
16+
17+
/**
18+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
19+
*/
20+
class DummyMessageWithTransport implements MessageInterface
21+
{
22+
public function getRecipientId(): ?string
23+
{
24+
return 'recipient_id';
25+
}
26+
27+
public function getSubject(): string
28+
{
29+
return 'subject';
30+
}
31+
32+
public function getOptions(): ?MessageOptionsInterface
33+
{
34+
return null;
35+
}
36+
37+
public function getTransport(): ?string
38+
{
39+
return 'transport';
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Message;
13+
14+
use Symfony\Component\Notifier\Message\MessageInterface;
15+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
16+
17+
/**
18+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
19+
*/
20+
class DummyMessageWithoutTransport implements MessageInterface
21+
{
22+
public function getRecipientId(): ?string
23+
{
24+
return 'recipient_id';
25+
}
26+
27+
public function getSubject(): string
28+
{
29+
return 'subject';
30+
}
31+
32+
public function getOptions(): ?MessageOptionsInterface
33+
{
34+
return null;
35+
}
36+
37+
public function getTransport(): ?string
38+
{
39+
return null;
40+
}
41+
}

src/Symfony/Component/Notifier/Tests/Message/EmailMessageTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Notifier\Tests\Message;
413

514
use PHPUnit\Framework\TestCase;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Message;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Message\MessageInterface;
16+
use Symfony\Component\Notifier\Message\NullMessage;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class NullMessageTest extends TestCase
22+
{
23+
/**
24+
* @dataProvider messageDataProvider
25+
*/
26+
public function testCanBeConstructed(MessageInterface $message)
27+
{
28+
$nullMessage = new NullMessage($message);
29+
30+
$this->assertSame($message->getSubject(), $nullMessage->getSubject());
31+
$this->assertSame($message->getRecipientId(), $nullMessage->getRecipientId());
32+
$this->assertSame($message->getOptions(), $nullMessage->getOptions());
33+
34+
(null === $message->getTransport())
35+
? $this->assertSame('null', $nullMessage->getTransport())
36+
: $this->assertSame($message->getTransport(), $nullMessage->getTransport());
37+
}
38+
39+
public function messageDataProvider(): \Generator
40+
{
41+
yield [new DummyMessageWithoutTransport()];
42+
yield [new DummyMessageWithTransport()];
43+
}
44+
}

src/Symfony/Component/Notifier/Tests/Message/SmsMessageTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Notifier\Tests\Message;
413

514
use PHPUnit\Framework\TestCase;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Transport;
13+
14+
use Symfony\Component\Notifier\Message\MessageInterface;
15+
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
16+
17+
/**
18+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
19+
*/
20+
class DummyMessage implements MessageInterface
21+
{
22+
public function getRecipientId(): ?string
23+
{
24+
return 'recipient_id';
25+
}
26+
27+
public function getSubject(): string
28+
{
29+
return 'subject';
30+
}
31+
32+
public function getOptions(): ?MessageOptionsInterface
33+
{
34+
return null;
35+
}
36+
37+
public function getTransport(): ?string
38+
{
39+
return null;
40+
}
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;
16+
use Symfony\Component\Notifier\Transport\Dsn;
17+
use Symfony\Component\Notifier\Transport\NullTransport;
18+
use Symfony\Component\Notifier\Transport\NullTransportFactory;
19+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
20+
use Symfony\Contracts\HttpClient\HttpClientInterface;
21+
22+
/**
23+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
24+
*/
25+
class NullTransportFactoryTest extends TestCase
26+
{
27+
/**
28+
* @var NullTransportFactory
29+
*/
30+
private $nullTransportFactory;
31+
32+
protected function setUp(): void
33+
{
34+
$this->nullTransportFactory = new NullTransportFactory(
35+
$this->createMock(EventDispatcherInterface::class),
36+
$this->createMock(HttpClientInterface::class)
37+
);
38+
}
39+
40+
public function testCreateThrowsUnsupportedSchemeException()
41+
{
42+
$this->expectException(UnsupportedSchemeException::class);
43+
44+
$this->nullTransportFactory->create(new Dsn('foo', ''));
45+
}
46+
47+
public function testCreate()
48+
{
49+
$this->assertInstanceOf(
50+
NullTransport::class,
51+
$this->nullTransportFactory->create(new Dsn('null', ''))
52+
);
53+
}
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Notifier\Tests\Transport;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Transport\NullTransport;
16+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class NullTransportTest extends TestCase
22+
{
23+
public function testToString()
24+
{
25+
$this->assertEquals('null', (string) (new NullTransport()));
26+
}
27+
28+
public function testSend()
29+
{
30+
$nullTransport = new NullTransport(
31+
$eventDispatcherMock = $this->createMock(EventDispatcherInterface::class)
32+
);
33+
34+
$eventDispatcherMock->expects($this->once())->method('dispatch');
35+
$nullTransport->send(new DummyMessage());
36+
}
37+
}

src/Symfony/Component/Notifier/composer.json

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"symfony/polyfill-php80": "^1.15",
2121
"psr/log": "~1.0"
2222
},
23+
"require-dev": {
24+
"symfony/event-dispatcher-contracts": "^2",
25+
"symfony/http-client-contracts": "^2"
26+
},
2327
"conflict": {
2428
"symfony/http-kernel": "<4.4",
2529
"symfony/firebase-notifier": "<5.2",

0 commit comments

Comments
 (0)