1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Email; |
4
|
|
|
|
5
|
|
|
use Email\EmailAddress; |
6
|
|
|
use PhpSpec\ObjectBehavior; |
7
|
|
|
|
8
|
|
|
class EmailAddressSpec extends ObjectBehavior |
9
|
|
|
{ |
10
|
|
|
public function it_is_initializable() |
11
|
|
|
{ |
12
|
|
|
$this->shouldHaveType('Email\EmailAddress'); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function let() |
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith("[email protected]"); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function it_should_throw_an_exception() |
21
|
|
|
{ |
22
|
|
|
$this |
23
|
|
|
->shouldThrow('Email\Exception\InvalidEmailAddressException') |
24
|
|
|
->during('__construct', ['foo@bar']); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function it_should_have_a_to_string() |
28
|
|
|
{ |
29
|
|
|
$this->__toString()->shouldReturn("[email protected]"); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function if_should_have_an_email() |
33
|
|
|
{ |
34
|
|
|
$this->getValue()->shouldReturn("[email protected]"); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function it_should_have_an_recipient() |
38
|
|
|
{ |
39
|
|
|
$this->getRecipient()->shouldReturn("recipient"); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function it_should_have_a_domain() |
43
|
|
|
{ |
44
|
|
|
$this->getDomain()->shouldReturn("domain"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function it_should_have_a_tld() |
48
|
|
|
{ |
49
|
|
|
$this->getTld()->shouldReturn("tld"); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function it_should_return_an_email_as_array() |
53
|
|
|
{ |
54
|
|
|
$this->getValueAsArray()->shouldBeArray(); |
55
|
|
|
$this->getValueAsArray()['domain']->shouldReturn("domain"); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function it_should_be_equal() |
59
|
|
|
{ |
60
|
|
|
$email = new EmailAddress("[email protected]"); |
61
|
|
|
$this->isEqualTo($email)->shouldReturn(true); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function it_should_explode_a_tld_with_two_dots() |
65
|
|
|
{ |
66
|
|
|
$this->beConstructedWith("[email protected]"); |
67
|
|
|
$this->getTld()->shouldReturn("co.uk"); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function it_should_not_works_with_unicode_because_of_validate_email() |
71
|
|
|
{ |
72
|
|
|
$this |
73
|
|
|
->shouldThrow('Email\Exception\InvalidEmailAddressException') |
74
|
|
|
->during('__construct', ['recipient@domain.中国']); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|