|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace User\Tests\Entity; |
|
5
|
|
|
|
|
6
|
|
|
use DateTime; |
|
7
|
|
|
use Common\ChangeProtectedAttribute; |
|
8
|
|
|
use User\Entity\User; |
|
9
|
|
|
use PHPUnit_Framework_TestCase; |
|
10
|
|
|
use stdClass; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* User test case. |
|
14
|
|
|
* |
|
15
|
|
|
* @author Thiago Paes <[email protected]> |
|
16
|
|
|
* @author Romeu Mattos <[email protected]> |
|
17
|
|
|
*/ |
|
18
|
|
|
class UserTest extends PHPUnit_Framework_TestCase |
|
19
|
|
|
{ |
|
20
|
|
|
use ChangeProtectedAttribute; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @return multitype:multitype:number |
|
|
|
|
|
|
24
|
|
|
*/ |
|
25
|
|
View Code Duplication |
public function validObjects() |
|
|
|
|
|
|
26
|
|
|
{ |
|
27
|
|
|
$obj = new stdClass(); |
|
28
|
|
|
$obj->id = 1; |
|
29
|
|
|
$obj->created = (new DateTime()); |
|
30
|
|
|
$obj->updated = (new DateTime())->modify('+1 day'); |
|
31
|
|
|
$obj->name = 'Teste'; |
|
32
|
|
|
$obj->email = '[email protected]'; |
|
33
|
|
|
|
|
34
|
|
|
return [ |
|
35
|
|
|
[ |
|
36
|
|
|
$obj |
|
37
|
|
|
] |
|
38
|
|
|
]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @return multitype:multitype:number |
|
|
|
|
|
|
43
|
|
|
*/ |
|
44
|
|
View Code Duplication |
public function invalidObjects() |
|
|
|
|
|
|
45
|
|
|
{ |
|
46
|
|
|
$obj = new stdClass(); |
|
47
|
|
|
$obj->id = 'SS'; |
|
48
|
|
|
$obj->created = (new DateTime())->modify('+3 day'); |
|
49
|
|
|
$obj->updated = (new DateTime())->modify('-10 day'); |
|
50
|
|
|
$obj->name = ''; |
|
51
|
|
|
$obj->email = 'lalala'; |
|
52
|
|
|
|
|
53
|
|
|
return [ |
|
54
|
|
|
[ |
|
55
|
|
|
$obj |
|
56
|
|
|
] |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @test |
|
62
|
|
|
* @dataProvider validObjects |
|
63
|
|
|
* @covers \User\Entity\User::setName |
|
64
|
|
|
*/ |
|
65
|
|
|
public function setNameReturnEmptyOnSuccess($obj) |
|
66
|
|
|
{ |
|
67
|
|
|
$user = new User(); |
|
68
|
|
|
|
|
69
|
|
|
$result = $user->setName($obj->name); |
|
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
$this->assertEmpty($result); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @test |
|
76
|
|
|
* @dataProvider invalidObjects |
|
77
|
|
|
* @covers \User\Entity\User::setName |
|
78
|
|
|
* @expectedException \InvalidArgumentException |
|
79
|
|
|
*/ |
|
80
|
|
|
public function setNameThrowsExceptionWhenEmpty($obj) |
|
81
|
|
|
{ |
|
82
|
|
|
$user = new User(); |
|
83
|
|
|
$user->setName($obj->name); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @test |
|
88
|
|
|
* @dataProvider validObjects |
|
89
|
|
|
* @covers \User\Entity\User::getName |
|
90
|
|
|
*/ |
|
91
|
|
|
public function getNameReturnNameAttribute($obj) |
|
92
|
|
|
{ |
|
93
|
|
|
$user = new User(); |
|
94
|
|
|
|
|
95
|
|
|
$this->modifyAttribute($user, 'name', $obj->name); |
|
96
|
|
|
|
|
97
|
|
|
$this->assertEquals($user->getName(), $obj->name); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @test |
|
102
|
|
|
* @dataProvider validObjects |
|
103
|
|
|
* @covers \User\Entity\User::getEmail |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getEmailReturnEmailAttribute($obj) |
|
106
|
|
|
{ |
|
107
|
|
|
$user = new User(); |
|
108
|
|
|
|
|
109
|
|
|
$this->modifyAttribute($user, 'email', $obj->email); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertEquals($user->getEmail(), $obj->email); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @test |
|
116
|
|
|
* @dataProvider validObjects |
|
117
|
|
|
* @covers \User\Entity\User::setEmail |
|
118
|
|
|
*/ |
|
119
|
|
|
public function setEmailReturnEmptyOnSuccess($obj) |
|
120
|
|
|
{ |
|
121
|
|
|
$user = new User(); |
|
122
|
|
|
|
|
123
|
|
|
$result = $user->setEmail($obj->email); |
|
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
$this->assertEmpty($result); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @test |
|
130
|
|
|
* @dataProvider invalidObjects |
|
131
|
|
|
* @covers \User\Entity\User::setEmail |
|
132
|
|
|
* @expectedException \InvalidArgumentException |
|
133
|
|
|
*/ |
|
134
|
|
|
public function setEmailThrowsInvalidArgumentExceptoinWhenInvalid($obj) |
|
135
|
|
|
{ |
|
136
|
|
|
$user = new User(); |
|
137
|
|
|
$user->setEmail($obj->email); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.