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