1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace LaravelDoctrineTest \ORM \Feature \Auth ;
4
6
5
7
use Doctrine \ORM \EntityManagerInterface ;
10
12
use LaravelDoctrineTest \ORM \Assets \Auth \AuthenticableWithNonEmptyConstructorMock ;
11
13
use LaravelDoctrineTest \ORM \TestCase ;
12
14
use Mockery as m ;
13
- use Mockery \Mock ;
14
15
15
16
class DoctrineUserProviderTest extends TestCase
16
17
{
17
- /**
18
- * @var Mock
19
- */
20
- protected $ hasher ;
21
-
22
- /**
23
- * @var Mock
24
- */
25
- protected $ em ;
26
-
27
- /**
28
- * @var DoctrineUserProvider
29
- */
30
- protected $ provider ;
31
-
32
- /**
33
- * @var DoctrineUserProvider
34
- */
35
- protected $ providerNonEmpty ;
36
-
37
- /**
38
- * @var Mock
39
- */
40
- protected $ repo ;
18
+ protected Hasher $ hasher ;
19
+
20
+ protected EntityManagerInterface $ em ;
21
+
22
+ protected DoctrineUserProvider $ provider ;
23
+
24
+ protected DoctrineUserProvider $ providerNonEmpty ;
25
+
26
+ protected EntityRepository $ repo ;
41
27
42
28
protected function setUp (): void
43
29
{
44
30
$ this ->hasher = m::mock (Hasher::class);
45
31
$ this ->em = m::mock (EntityManagerInterface::class);
46
32
$ this ->repo = m::mock (EntityRepository::class);
47
33
48
- $ this ->provider = new DoctrineUserProvider (
34
+ $ this ->provider = new DoctrineUserProvider (
49
35
$ this ->hasher ,
50
36
$ this ->em ,
51
- AuthenticableMock::class
37
+ AuthenticableMock::class,
52
38
);
53
39
$ this ->providerNonEmpty = new DoctrineUserProvider (
54
40
$ this ->hasher ,
55
41
$ this ->em ,
56
- AuthenticableWithNonEmptyConstructorMock::class
42
+ AuthenticableWithNonEmptyConstructorMock::class,
57
43
);
58
44
59
45
parent ::setUp ();
60
46
}
61
47
62
- public function test_can_retrieve_by_id ()
48
+ public function testCanRetrieveById (): void
63
49
{
64
50
$ this ->mockGetRepository ();
65
51
66
- $ user = new AuthenticableMock ;
52
+ $ user = new AuthenticableMock () ;
67
53
$ this ->repo ->shouldReceive ('find ' )
68
54
->once ()->with (1 )
69
55
->andReturn ($ user );
70
56
71
57
$ this ->assertEquals ($ user , $ this ->provider ->retrieveById (1 ));
72
58
}
73
59
74
- public function test_can_retrieve_by_token ()
60
+ public function testCanRetrieveByToken (): void
75
61
{
76
62
$ this ->mockGetRepository ();
77
63
78
- $ user = new AuthenticableMock ;
64
+ $ user = new AuthenticableMock () ;
79
65
$ this ->repo ->shouldReceive ('findOneBy ' )
80
66
->with ([
81
67
'id ' => 1 ,
82
- 'rememberToken ' => 'myToken '
68
+ 'rememberToken ' => 'myToken ' ,
83
69
])
84
70
->once ()->andReturn ($ user );
85
71
86
72
$ this ->assertEquals ($ user , $ this ->provider ->retrieveByToken (1 , 'myToken ' ));
87
73
}
88
74
89
- public function test_can_retrieve_by_token_with_non_empty_constructor ()
75
+ public function testCanRetrieveByTokenWithNonEmptyConstructor (): void
90
76
{
91
77
$ this ->mockGetRepository (AuthenticableWithNonEmptyConstructorMock::class);
92
78
93
79
$ user = new AuthenticableWithNonEmptyConstructorMock (['myPassword ' ]);
94
80
$ this ->repo ->shouldReceive ('findOneBy ' )
95
81
->with ([
96
82
'id ' => 1 ,
97
- 'rememberToken ' => 'myToken '
83
+ 'rememberToken ' => 'myToken ' ,
98
84
])
99
85
->once ()->andReturn ($ user );
100
86
101
87
$ this ->assertEquals ($ user , $ this ->providerNonEmpty ->retrieveByToken (1 , 'myToken ' ));
102
88
}
103
89
104
- public function test_can_update_remember_token ()
90
+ public function testCanUpdateRememberToken (): void
105
91
{
106
- $ user = new AuthenticableMock ;
92
+ $ user = new AuthenticableMock () ;
107
93
108
94
$ this ->em ->shouldReceive ('persist ' )->once ()->with ($ user );
109
95
$ this ->em ->shouldReceive ('flush ' )->once ()->withNoArgs ();
@@ -113,40 +99,38 @@ public function test_can_update_remember_token()
113
99
$ this ->assertEquals ('newToken ' , $ user ->getRememberToken ());
114
100
}
115
101
116
- public function test_can_retrieve_by_credentials ()
102
+ public function testCanRetrieveByCredentials (): void
117
103
{
118
104
$ this ->mockGetRepository ();
119
105
120
- $ user = new AuthenticableMock ;
106
+ $ user = new AuthenticableMock () ;
121
107
$ this ->repo ->shouldReceive ('findOneBy ' )
122
- ->with ([
123
- 'email ' => 'email ' ,
124
- ])
108
+ ->with (['email ' => 'email ' ])
125
109
->once ()->andReturn ($ user );
126
110
127
111
$ this ->assertEquals ($ user , $ this ->provider ->retrieveByCredentials ([
128
112
'email ' => 'email ' ,
129
- 'password ' => 'password '
113
+ 'password ' => 'password ' ,
130
114
]));
131
115
}
132
116
133
- public function test_can_validate_credentials ()
117
+ public function testCanValidateCredentials (): void
134
118
{
135
- $ user = new AuthenticableMock ;
119
+ $ user = new AuthenticableMock () ;
136
120
137
121
$ this ->hasher ->shouldReceive ('check ' )->once ()
138
122
->with ('myPassword ' , 'myPassword ' )
139
123
->andReturn (true );
140
124
141
125
$ this ->assertTrue ($ this ->provider ->validateCredentials (
142
126
$ user ,
143
- ['password ' => 'myPassword ' ]
127
+ ['password ' => 'myPassword ' ],
144
128
));
145
129
}
146
130
147
- public function test_rehash_password_if_required_rehash ()
131
+ public function testRehashPasswordIfRequriredRehash (): void
148
132
{
149
- $ user = new AuthenticableMock ;
133
+ $ user = new AuthenticableMock () ;
150
134
151
135
$ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (true );
152
136
$ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
@@ -157,9 +141,9 @@ public function test_rehash_password_if_required_rehash()
157
141
$ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
158
142
}
159
143
160
- public function test_rehash_password_if_required_rehash_force ()
144
+ public function testRehashPasswordIfRequiredRehashForce (): void
161
145
{
162
- $ user = new AuthenticableMock ;
146
+ $ user = new AuthenticableMock () ;
163
147
164
148
$ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (false );
165
149
$ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
@@ -170,7 +154,7 @@ public function test_rehash_password_if_required_rehash_force()
170
154
$ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
171
155
}
172
156
173
- public function test_rehash_password_if_required_rehash_norehash_needed ()
157
+ public function testRehashPasswordIfRequiredRehashNorehashNeeded (): void
174
158
{
175
159
$ user = new AuthenticableMock ();
176
160
$ user ->setPassword ('originalPassword ' );
@@ -181,7 +165,7 @@ public function test_rehash_password_if_required_rehash_norehash_needed()
181
165
$ this ->assertEquals ('originalPassword ' , $ user ->getPassword ());
182
166
}
183
167
184
- protected function mockGetRepository ($ class = AuthenticableMock::class)
168
+ protected function mockGetRepository (string $ class = AuthenticableMock::class): void
185
169
{
186
170
$ this ->em ->shouldReceive ('getRepository ' )
187
171
->with ($ class )
0 commit comments