1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Cubiche/Web component. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) Cubiche |
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 Cubiche\Domain\Web\Tests\Units; |
13
|
|
|
|
14
|
|
|
use Cubiche\Domain\System\StringLiteral; |
15
|
|
|
use Cubiche\Domain\System\Tests\Units\StringLiteralTests; |
16
|
|
|
use Cubiche\Domain\Web\EmailAddress; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* EmailAddressTests class. |
20
|
|
|
* |
21
|
|
|
* Generated by TestGenerator on 2017-03-15 at 11:36:08. |
22
|
|
|
*/ |
23
|
|
|
class EmailAddressTests extends StringLiteralTests |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
protected function randomNativeValue() |
29
|
|
|
{ |
30
|
|
|
return $this->faker->email; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritdoc} |
35
|
|
|
*/ |
36
|
|
|
protected function invalidNativeValue() |
37
|
|
|
{ |
38
|
|
|
return 'wrongemail@address'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
protected function uniqueNativeValue() |
45
|
|
|
{ |
46
|
|
|
return $this->faker->unique()->email; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
protected function fromNative($value) |
53
|
|
|
{ |
54
|
|
|
return EmailAddress::fromNative($value); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Test isEmpty method. |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function testIsEmpty() |
|
|
|
|
61
|
|
|
{ |
62
|
|
|
$this |
63
|
|
|
->given($email = EmailAddress::fromNative($this->randomNativeValue())) |
64
|
|
|
->then() |
65
|
|
|
->boolean($email->isEmpty()) |
66
|
|
|
->isFalse() |
67
|
|
|
->exception(function () { |
68
|
|
|
EmailAddress::fromNative(''); |
69
|
|
|
})->isInstanceOf(\InvalidArgumentException::class) |
70
|
|
|
; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Test IsValid method. |
75
|
|
|
*/ |
76
|
|
|
public function testIsValid() |
77
|
|
|
{ |
78
|
|
|
$this |
79
|
|
|
->boolean(EmailAddress::isValid($this->randomNativeValue())) |
80
|
|
|
->isTrue() |
81
|
|
|
->boolean(EmailAddress::isValid($this->invalidNativeValue())) |
82
|
|
|
->isFalse() |
83
|
|
|
; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Test User method. |
88
|
|
|
*/ |
89
|
|
|
public function testUser() |
90
|
|
|
{ |
91
|
|
|
$this |
92
|
|
|
->given($email = EmailAddress::fromNative('[email protected]')) |
93
|
|
|
->then() |
94
|
|
|
->object($email->user()) |
95
|
|
|
->isEqualTo(StringLiteral::fromNative('ivannis.suarez')) |
96
|
|
|
; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Test Domain method. |
101
|
|
|
*/ |
102
|
|
|
public function testDomain() |
103
|
|
|
{ |
104
|
|
|
$this |
105
|
|
|
->given($email = EmailAddress::fromNative('[email protected]')) |
106
|
|
|
->then() |
107
|
|
|
->object($email->domain()) |
108
|
|
|
->isEqualTo(StringLiteral::fromNative('gmail.com')) |
109
|
|
|
; |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.