1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace User\Tests\Service; |
5
|
|
|
|
6
|
|
|
use Common\ChangeProtectedAttribute; |
7
|
|
|
use Doctrine\Common\Annotations\AnnotationReader; |
8
|
|
|
use Doctrine\ORM\Mapping\Driver\AnnotationDriver; |
9
|
|
|
use Doctrine\Tests\OrmTestCase; |
10
|
|
|
use User\Entity\User; |
11
|
|
|
use User\Entity\UserInterface; |
12
|
|
|
use User\Service\User as UserService; |
13
|
|
|
use User\Tests\Mock\Repository\User as CreateUserRepositoryMock; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* User service test case. |
17
|
|
|
* |
18
|
|
|
* @author Thiago Paes <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class UserTest extends OrmTestCase |
21
|
|
|
{ |
22
|
|
|
use ChangeProtectedAttribute; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var UserService |
26
|
|
|
*/ |
27
|
|
|
private $obj; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Boot |
31
|
|
|
*/ |
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
|
36
|
|
|
$reader = new AnnotationReader(); |
37
|
|
|
$metadataDriver = new AnnotationDriver($reader, User::class); |
38
|
|
|
|
39
|
|
|
$em = $this->_getTestEntityManager(); |
40
|
|
|
$em->getConfiguration()->setMetadataDriverImpl($metadataDriver); |
41
|
|
|
|
42
|
|
|
$this->obj = new UserService($em); |
43
|
|
|
|
44
|
|
|
$this->modifyAttribute($this->obj, 'users', CreateUserRepositoryMock::getMock()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Shutdown |
49
|
|
|
*/ |
50
|
|
|
public function tearDown() |
51
|
|
|
{ |
52
|
|
|
$this->obj = null; |
53
|
|
|
|
54
|
|
|
parent::tearDown(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @test |
59
|
|
|
* @covers \User\Service\User::save() |
60
|
|
|
*/ |
61
|
|
|
public function saveMustBeReturnSameObject() |
62
|
|
|
{ |
63
|
|
|
$userModel = new User(); |
64
|
|
|
|
65
|
|
|
$result = $this->obj->save($userModel); |
66
|
|
|
|
67
|
|
|
$this->assertSame($userModel, $result); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
* @covers \User\Service\User::delete() |
73
|
|
|
*/ |
74
|
|
|
public function deleteMustBeReturnSameObject() |
75
|
|
|
{ |
76
|
|
|
$userModel = new User(); |
77
|
|
|
|
78
|
|
|
$result = $this->obj->delete($userModel); |
79
|
|
|
|
80
|
|
|
$this->assertSame($userModel, $result); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
* @covers \User\Service\User::findByUserId() |
86
|
|
|
*/ |
87
|
|
|
public function findByUserIdMustBeReturnUserInterface() |
88
|
|
|
{ |
89
|
|
|
$result = $this->obj->findByUserId(1); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf(UserInterface::class, $result); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @test |
96
|
|
|
* @covers \User\Service\User::listAll() |
97
|
|
|
*/ |
98
|
|
|
public function listAllMustBeReturnArray() |
99
|
|
|
{ |
100
|
|
|
$result = $this->obj->listAll(); |
101
|
|
|
|
102
|
|
|
$this->assertTrue(is_array($result)); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @test |
107
|
|
|
*/ |
108
|
|
|
public function updateMustBeReturnSameObject() |
109
|
|
|
{ |
110
|
|
|
$user = new User(); |
111
|
|
|
|
112
|
|
|
$result = $this->obj->update($user, 'foo', '[email protected]'); |
113
|
|
|
|
114
|
|
|
$this->assertInstanceOf(UserInterface::class, $result); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
*/ |
120
|
|
|
public function createMustBeReturnUserObject() |
121
|
|
|
{ |
122
|
|
|
$result = $this->obj->create('Foo', '[email protected]'); |
123
|
|
|
|
124
|
|
|
$this->assertInstanceOf(UserInterface::class, $result); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|