1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Test case for IsBizMail class |
4
|
|
|
* |
5
|
|
|
* @category PHPUnit |
6
|
|
|
* @package IsBizMail |
7
|
|
|
* @author Zhmayev Yaroslav <[email protected]> |
8
|
|
|
* @license MIT https://opensource.org/licenses/MIT |
9
|
|
|
* @link https://github.com/salaros/free-mailchecker |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Salaros\Email; |
13
|
|
|
|
14
|
|
|
use Salaros\Email\IsBizMail; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for IsBizMail class |
19
|
|
|
* @coversDefaultClass \Salaros\Email\IsBizMail |
20
|
|
|
*/ |
21
|
|
|
final class IsBizMailTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
private static $emailSamples; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Check if any free domain is defined |
27
|
|
|
* @covers ::getFreeDomains |
28
|
|
|
* @test |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function hasFreeDomainsListPopulated() |
33
|
|
|
{ |
34
|
|
|
$this->assertNotEmpty((new IsBizMail())->getFreeDomains()); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Check if any domain pattern is defined |
39
|
|
|
* @covers ::getFreeDomainPatterns |
40
|
|
|
* @test |
41
|
|
|
* |
42
|
|
|
* @return void |
43
|
|
|
*/ |
44
|
|
|
public function hasFreeDomainsPatternsPopulated() |
45
|
|
|
{ |
46
|
|
|
$this->assertNotEmpty((new IsBizMail())->getFreeDomainPatterns()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Tests IsBizMail->isFreeMailAddress() against some free emails |
51
|
|
|
* |
52
|
|
|
* @param string $freeEmail A free email address |
53
|
|
|
* |
54
|
|
|
* @dataProvider getFreeMailDomainSamples |
55
|
|
|
* @covers ::isFreeMailAddress |
56
|
|
|
* @test |
57
|
|
|
* |
58
|
|
|
* @return void |
59
|
|
|
*/ |
60
|
|
|
public function emailAddressIsOnFreeDomain($freeEmail) |
61
|
|
|
{ |
62
|
|
|
$this->assertSame(true, (new IsBizMail())->isFreeMailAddress($freeEmail)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Tests IsBizMail->isFreeMailAddress() against some business emails |
67
|
|
|
* |
68
|
|
|
* @param string $businessEmail A business email address |
69
|
|
|
* |
70
|
|
|
* @dataProvider getBusinessMailDomainSamples |
71
|
|
|
* @covers ::isFreeMailAddress |
72
|
|
|
* @test |
73
|
|
|
* |
74
|
|
|
* @return void |
75
|
|
|
*/ |
76
|
|
|
public function emailAddressIsOnBusinessDomain($businessEmail) |
77
|
|
|
{ |
78
|
|
|
$this->assertSame(false, (new IsBizMail())->isFreeMailAddress($businessEmail)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Tests IsBizMail->isFreeMailAddress() against some domain patterns |
83
|
|
|
* |
84
|
|
|
* @param string $freeEmail A free email address |
85
|
|
|
* |
86
|
|
|
* @dataProvider getDomainPatternSamples |
87
|
|
|
* @covers ::isFreeMailAddress |
88
|
|
|
* @test |
89
|
|
|
* |
90
|
|
|
* @return void |
91
|
|
|
*/ |
92
|
|
|
public function emailMatchesDomainPattern($freeEmail) |
93
|
|
|
{ |
94
|
|
|
$this->assertSame(true, (new IsBizMail())->isFreeMailAddress($freeEmail)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Tests IsBizMail->isValid() against some business emails |
99
|
|
|
* |
100
|
|
|
* @param string $businessEmail A business email address |
101
|
|
|
* |
102
|
|
|
* @depends emailAddressIsOnBusinessDomain |
103
|
|
|
* @dataProvider getBusinessMailDomainSamples |
104
|
|
|
* @covers ::isValid |
105
|
|
|
* @test |
106
|
|
|
* |
107
|
|
|
* @return void |
108
|
|
|
*/ |
109
|
|
|
public function emailAddressIsValid($businessEmail) |
110
|
|
|
{ |
111
|
|
|
$this->assertSame(true, (new IsBizMail())->isValid($businessEmail)); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Provides a list of free email addresses |
116
|
|
|
* @doesNotPerformAssertions |
117
|
|
|
* @coversNothing |
118
|
|
|
* |
119
|
|
|
* @return array |
120
|
|
|
*/ |
121
|
|
|
public function getFreeMailDomainSamples() |
122
|
|
|
{ |
123
|
|
|
return array_map(function ($freeEmail) { |
124
|
|
|
return array($freeEmail); |
125
|
|
|
}, self::getEmailSamples()->free); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Provides a list of business email addresses |
130
|
|
|
* @doesNotPerformAssertions |
131
|
|
|
* @coversNothing |
132
|
|
|
* |
133
|
|
|
* @return array |
134
|
|
|
*/ |
135
|
|
|
public function getBusinessMailDomainSamples() |
136
|
|
|
{ |
137
|
|
|
return array_map(function ($businessEmail) { |
138
|
|
|
return array($businessEmail); |
139
|
|
|
}, self::getEmailSamples()->business); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Provides a list of business email addresses |
144
|
|
|
* @doesNotPerformAssertions |
145
|
|
|
* @coversNothing |
146
|
|
|
* |
147
|
|
|
* @return array |
148
|
|
|
*/ |
149
|
|
|
public function getDomainPatternSamples() |
150
|
|
|
{ |
151
|
|
|
return array_map(function ($patternDomains) { |
152
|
|
|
return array($patternDomains); |
153
|
|
|
}, self::getEmailSamples()->pattern); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Provides an object containing lists of sample free, business etc domains |
158
|
|
|
* @doesNotPerformAssertions |
159
|
|
|
* @coversNothing |
160
|
|
|
* |
161
|
|
|
* @return object |
162
|
|
|
*/ |
163
|
|
|
public static function getEmailSamples() |
164
|
|
|
{ |
165
|
|
|
if (is_null(self::$emailSamples)) { |
166
|
|
|
self::$emailSamples = json_decode( |
167
|
|
|
file_get_contents(sprintf("%s/assets/emailSamples.json", dirname(__DIR__))), |
168
|
|
|
false |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
return self::$emailSamples; |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|