1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/value-object project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Tests\ValueObject; |
10
|
|
|
|
11
|
|
|
use Daikon\ValueObject\Email; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
final class EmailTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private const EMAIL = '[email protected]'; |
17
|
|
|
|
18
|
|
|
private Email $email; |
19
|
|
|
|
20
|
1 |
|
public function testToNative(): void |
21
|
|
|
{ |
22
|
1 |
|
$this->assertEquals(self::EMAIL, $this->email->toNative()); |
23
|
1 |
|
$this->assertEquals('', Email::fromNative(null)->toNative()); |
24
|
1 |
|
} |
25
|
|
|
|
26
|
1 |
|
public function testEquals(): void |
27
|
|
|
{ |
28
|
1 |
|
$sameEmail = Email::fromNative(self::EMAIL); |
29
|
1 |
|
$this->assertTrue($this->email->equals($sameEmail)); |
30
|
1 |
|
$differentEmail = Email::fromNative('[email protected]'); |
31
|
1 |
|
$this->assertFalse($this->email->equals($differentEmail)); |
32
|
1 |
|
} |
33
|
|
|
|
34
|
1 |
|
public function testToString(): void |
35
|
|
|
{ |
36
|
1 |
|
$this->assertEquals(self::EMAIL, (string)$this->email); |
37
|
1 |
|
} |
38
|
|
|
|
39
|
1 |
|
public function testGetLocalPart(): void |
40
|
|
|
{ |
41
|
1 |
|
$this->assertEquals('peter.parker', (string)$this->email->getLocalPart()); |
42
|
1 |
|
} |
43
|
|
|
|
44
|
1 |
|
public function testGetDomain(): void |
45
|
|
|
{ |
46
|
1 |
|
$this->assertEquals('example.com', (string)$this->email->getDomain()); |
47
|
1 |
|
} |
48
|
|
|
|
49
|
1 |
|
public function testMakeEmpty(): void |
50
|
|
|
{ |
51
|
1 |
|
$email = Email::makeEmpty(); |
52
|
1 |
|
$this->assertTrue($email->isEmpty()); |
53
|
1 |
|
$this->assertNull($email->toNative()); |
54
|
1 |
|
$this->assertEquals('', (string)$email); |
55
|
1 |
|
} |
56
|
|
|
|
57
|
6 |
|
protected function setUp(): void |
58
|
|
|
{ |
59
|
6 |
|
$this->email = Email::fromNative(self::EMAIL); |
60
|
6 |
|
} |
61
|
|
|
} |
62
|
|
|
|