11<?php
22
3+ declare (strict_types=1 );
4+
35namespace LaravelDoctrineTest \ORM \Feature \Auth ;
46
57use Doctrine \ORM \EntityManagerInterface ;
1012use LaravelDoctrineTest \ORM \Assets \Auth \AuthenticableWithNonEmptyConstructorMock ;
1113use LaravelDoctrineTest \ORM \TestCase ;
1214use Mockery as m ;
13- use Mockery \Mock ;
1415
1516class DoctrineUserProviderTest extends TestCase
1617{
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 ;
4127
4228 protected function setUp (): void
4329 {
4430 $ this ->hasher = m::mock (Hasher::class);
4531 $ this ->em = m::mock (EntityManagerInterface::class);
4632 $ this ->repo = m::mock (EntityRepository::class);
4733
48- $ this ->provider = new DoctrineUserProvider (
34+ $ this ->provider = new DoctrineUserProvider (
4935 $ this ->hasher ,
5036 $ this ->em ,
51- AuthenticableMock::class
37+ AuthenticableMock::class,
5238 );
5339 $ this ->providerNonEmpty = new DoctrineUserProvider (
5440 $ this ->hasher ,
5541 $ this ->em ,
56- AuthenticableWithNonEmptyConstructorMock::class
42+ AuthenticableWithNonEmptyConstructorMock::class,
5743 );
5844
5945 parent ::setUp ();
6046 }
6147
62- public function test_can_retrieve_by_id ()
48+ public function testCanRetrieveById (): void
6349 {
6450 $ this ->mockGetRepository ();
6551
66- $ user = new AuthenticableMock ;
52+ $ user = new AuthenticableMock () ;
6753 $ this ->repo ->shouldReceive ('find ' )
6854 ->once ()->with (1 )
6955 ->andReturn ($ user );
7056
7157 $ this ->assertEquals ($ user , $ this ->provider ->retrieveById (1 ));
7258 }
7359
74- public function test_can_retrieve_by_token ()
60+ public function testCanRetrieveByToken (): void
7561 {
7662 $ this ->mockGetRepository ();
7763
78- $ user = new AuthenticableMock ;
64+ $ user = new AuthenticableMock () ;
7965 $ this ->repo ->shouldReceive ('findOneBy ' )
8066 ->with ([
8167 'id ' => 1 ,
82- 'rememberToken ' => 'myToken '
68+ 'rememberToken ' => 'myToken ' ,
8369 ])
8470 ->once ()->andReturn ($ user );
8571
8672 $ this ->assertEquals ($ user , $ this ->provider ->retrieveByToken (1 , 'myToken ' ));
8773 }
8874
89- public function test_can_retrieve_by_token_with_non_empty_constructor ()
75+ public function testCanRetrieveByTokenWithNonEmptyConstructor (): void
9076 {
9177 $ this ->mockGetRepository (AuthenticableWithNonEmptyConstructorMock::class);
9278
9379 $ user = new AuthenticableWithNonEmptyConstructorMock (['myPassword ' ]);
9480 $ this ->repo ->shouldReceive ('findOneBy ' )
9581 ->with ([
9682 'id ' => 1 ,
97- 'rememberToken ' => 'myToken '
83+ 'rememberToken ' => 'myToken ' ,
9884 ])
9985 ->once ()->andReturn ($ user );
10086
10187 $ this ->assertEquals ($ user , $ this ->providerNonEmpty ->retrieveByToken (1 , 'myToken ' ));
10288 }
10389
104- public function test_can_update_remember_token ()
90+ public function testCanUpdateRememberToken (): void
10591 {
106- $ user = new AuthenticableMock ;
92+ $ user = new AuthenticableMock () ;
10793
10894 $ this ->em ->shouldReceive ('persist ' )->once ()->with ($ user );
10995 $ this ->em ->shouldReceive ('flush ' )->once ()->withNoArgs ();
@@ -113,40 +99,38 @@ public function test_can_update_remember_token()
11399 $ this ->assertEquals ('newToken ' , $ user ->getRememberToken ());
114100 }
115101
116- public function test_can_retrieve_by_credentials ()
102+ public function testCanRetrieveByCredentials (): void
117103 {
118104 $ this ->mockGetRepository ();
119105
120- $ user = new AuthenticableMock ;
106+ $ user = new AuthenticableMock () ;
121107 $ this ->repo ->shouldReceive ('findOneBy ' )
122- ->with ([
123- 'email ' => 'email ' ,
124- ])
108+ ->with (['email ' => 'email ' ])
125109 ->once ()->andReturn ($ user );
126110
127111 $ this ->assertEquals ($ user , $ this ->provider ->retrieveByCredentials ([
128112 'email ' => 'email ' ,
129- 'password ' => 'password '
113+ 'password ' => 'password ' ,
130114 ]));
131115 }
132116
133- public function test_can_validate_credentials ()
117+ public function testCanValidateCredentials (): void
134118 {
135- $ user = new AuthenticableMock ;
119+ $ user = new AuthenticableMock () ;
136120
137121 $ this ->hasher ->shouldReceive ('check ' )->once ()
138122 ->with ('myPassword ' , 'myPassword ' )
139123 ->andReturn (true );
140124
141125 $ this ->assertTrue ($ this ->provider ->validateCredentials (
142126 $ user ,
143- ['password ' => 'myPassword ' ]
127+ ['password ' => 'myPassword ' ],
144128 ));
145129 }
146130
147- public function test_rehash_password_if_required_rehash ()
131+ public function testRehashPasswordIfRequriredRehash (): void
148132 {
149- $ user = new AuthenticableMock ;
133+ $ user = new AuthenticableMock () ;
150134
151135 $ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (true );
152136 $ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
@@ -157,9 +141,9 @@ public function test_rehash_password_if_required_rehash()
157141 $ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
158142 }
159143
160- public function test_rehash_password_if_required_rehash_force ()
144+ public function testRehashPasswordIfRequiredRehashForce (): void
161145 {
162- $ user = new AuthenticableMock ;
146+ $ user = new AuthenticableMock () ;
163147
164148 $ this ->hasher ->shouldReceive ('needsRehash ' )->once ()->andReturn (false );
165149 $ this ->hasher ->shouldReceive ('make ' )->once ()->andReturn ('hashedPassword ' );
@@ -170,7 +154,7 @@ public function test_rehash_password_if_required_rehash_force()
170154 $ this ->assertEquals ('hashedPassword ' , $ user ->getPassword ());
171155 }
172156
173- public function test_rehash_password_if_required_rehash_norehash_needed ()
157+ public function testRehashPasswordIfRequiredRehashNorehashNeeded (): void
174158 {
175159 $ user = new AuthenticableMock ();
176160 $ user ->setPassword ('originalPassword ' );
@@ -181,7 +165,7 @@ public function test_rehash_password_if_required_rehash_norehash_needed()
181165 $ this ->assertEquals ('originalPassword ' , $ user ->getPassword ());
182166 }
183167
184- protected function mockGetRepository ($ class = AuthenticableMock::class)
168+ protected function mockGetRepository (string $ class = AuthenticableMock::class): void
185169 {
186170 $ this ->em ->shouldReceive ('getRepository ' )
187171 ->with ($ class )
0 commit comments