Skip to content

Commit f45f246

Browse files
committed
[Notifier] Add recipient tests
1 parent 7df6936 commit f45f246

File tree

3 files changed

+140
-0
lines changed

3 files changed

+140
-0
lines changed
Lines changed: 44 additions & 0 deletions
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\Recipient;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
16+
use Symfony\Component\Notifier\Recipient\EmailRecipient;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class EmailRecipientTest extends TestCase
22+
{
23+
public function testCanBeConstructedWithValidEmail()
24+
{
25+
$this->assertSame('test@test.de', (new EmailRecipient('test@test.de'))->getEmail());
26+
}
27+
28+
/**
29+
* @dataProvider provideInvalidEmails
30+
*/
31+
public function testCannotBeConstructedWithInvalidEmail(string $email)
32+
{
33+
$this->expectException(InvalidArgumentException::class);
34+
35+
new EmailRecipient($email);
36+
}
37+
38+
public function provideInvalidEmails(): \Generator
39+
{
40+
yield [''];
41+
yield ['test'];
42+
yield ['test@'];
43+
}
44+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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\Recipient;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
16+
use Symfony\Component\Notifier\Recipient\Recipient;
17+
use Symfony\Component\Notifier\Recipient\SmsRecipient;
18+
19+
/**
20+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
21+
*/
22+
class RecipientTest extends TestCase
23+
{
24+
public function testCanBeConstructed()
25+
{
26+
$recipient = new Recipient('test@test.de', '+0815');
27+
28+
$this->assertSame('test@test.de', $recipient->getEmail());
29+
$this->assertSame('+0815', $recipient->getPhone());
30+
}
31+
32+
/**
33+
* @dataProvider provideInvalidData
34+
*/
35+
public function testCannotBeConstructedWithInvalidPhone(string $email, string $phone)
36+
{
37+
$this->expectException(InvalidArgumentException::class);
38+
39+
new Recipient($email, $phone);
40+
}
41+
42+
public function provideInvalidData(): \Generator
43+
{
44+
yield ['test@test.de', ''];
45+
yield ['test@test.de', '0815'];
46+
yield ['test@test.de', 'qwert'];
47+
48+
yield ['', '+0815'];
49+
yield ['test', '+0815'];
50+
yield ['test@', '+0815'];
51+
}
52+
}
Lines changed: 44 additions & 0 deletions
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\Recipient;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
16+
use Symfony\Component\Notifier\Recipient\SmsRecipient;
17+
18+
/**
19+
* @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
20+
*/
21+
class SmsRecipientTest extends TestCase
22+
{
23+
public function testCanBeConstructedWithValidEmail()
24+
{
25+
$this->assertSame('+0815', (new SmsRecipient('+0815'))->getPhone());
26+
}
27+
28+
/**
29+
* @dataProvider provideInvalidPhoneNumber
30+
*/
31+
public function testCannotBeConstructedWithInvalidPhone(string $phone)
32+
{
33+
$this->expectException(InvalidArgumentException::class);
34+
35+
new SmsRecipient($phone);
36+
}
37+
38+
public function provideInvalidPhoneNumber(): \Generator
39+
{
40+
yield [''];
41+
yield ['0815'];
42+
yield ['qwert'];
43+
}
44+
}

0 commit comments

Comments
 (0)