@@ -41,9 +41,6 @@ class ClientControllerTest extends TestCase
4141 protected MockObject $ helpersMock ;
4242 protected MockObject $ loggerMock ;
4343 protected MockObject $ clientEntityMock ;
44- protected MockObject $ requestMock ;
45- protected MockObject $ queryInputBagMock ;
46- protected MockObject $ requestInputBagMock ;
4744 protected MockObject $ clientFormMock ;
4845
4946 protected array $ sampleFormData = [
@@ -105,11 +102,8 @@ protected function setUp(): void
105102
106103 $ this ->clientEntityMock = $ this ->createMock (ClientEntityInterface::class);
107104
108- $ this ->requestMock = $ this ->createMock (Request::class);
109105 $ this ->queryInputBagMock = $ this ->createMock (ParameterBag::class);
110- $ this ->requestMock ->query = $ this ->queryInputBagMock ;
111106 $ this ->requestInputBagMock = $ this ->createMock (ParameterBag::class);
112- $ this ->requestMock ->request = $ this ->requestInputBagMock ;
113107
114108 $ this ->clientFormMock = $ this ->createMock (ClientForm::class);
115109 $ this ->formFactoryMock ->method ('build ' )->willReturn ($ this ->clientFormMock );
@@ -163,10 +157,12 @@ public function testCanCreateInstance(): void
163157
164158 public function testIndex (): void
165159 {
166- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getInt ' )->with ('page ' )
167- ->willReturn (1 );
168- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->with ('q ' )
169- ->willReturn ('abc ' );
160+ $ request = Request::create (
161+ '/ ' ,
162+ 'GET ' ,
163+ ['page ' => '1 ' , 'q ' => 'abc ' ],
164+ );
165+
170166 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findPaginated ' )
171167 ->with (1 , 'abc ' , null )->willReturn ([
172168 'items ' => [$ this ->clientEntityMock ],
@@ -177,90 +173,113 @@ public function testIndex(): void
177173 $ this ->templateFactoryMock ->expects ($ this ->once ())->method ('build ' )
178174 ->with ('oidc:clients.twig ' );
179175
180- $ this ->sut ()->index ($ this -> requestMock );
176+ $ this ->sut ()->index ($ request );
181177 }
182178
183179 public function testShow (): void
184180 {
185- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
181+ $ request = Request::create (
182+ '/ ' ,
183+ 'GET ' ,
184+ ['client_id ' => 'clientId ' ],
185+ );
186+
186187 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('getIdentifier ' )->willReturn ('clientId ' );
187188 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
188189 ->willReturn ($ this ->clientEntityMock );
189190 $ this ->templateFactoryMock ->expects ($ this ->once ())->method ('build ' )
190191 ->with ('oidc:clients/show.twig ' );
191192
192- $ this ->sut ()->show ($ this -> requestMock );
193+ $ this ->sut ()->show ($ request );
193194 }
194195
195196 public function testShowThrowsIfClientIdNotProvided (): void
196197 {
198+ $ request = Request::create (
199+ '/ ' ,
200+ 'GET ' ,
201+ [],
202+ );
203+
197204 $ this ->expectException (OidcException::class);
198205 $ this ->expectExceptionMessage ('Client ID ' );
199206
200- $ this ->sut ()->show ($ this -> requestMock );
207+ $ this ->sut ()->show ($ request );
201208 }
202209
203210 public function testCanResetSecret (): void
204211 {
205- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
212+ $ request = Request::create (
213+ '/resetSecret?client_id=clientId ' ,
214+ 'POST ' ,
215+ ['client_id ' => 'clientId ' , 'secret ' => '123 ' ],
216+ );
217+
206218 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('getSecret ' )->willReturn ('123 ' );
207219 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
208220 ->willReturn ($ this ->clientEntityMock );
209- $ this ->requestInputBagMock ->expects ($ this ->once ())->method ('getString ' )
210- ->with ('secret ' )->willReturn ('123 ' );
211221 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('restoreSecret ' );
212222 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('update ' )
213223 ->with ($ this ->clientEntityMock );
214224 $ this ->sessionMessagesServiceMock ->expects ($ this ->once ())->method ('addMessage ' )
215225 ->with ($ this ->stringContains ('secret ' ));
216226
217- $ this ->sut ()->resetSecret ($ this -> requestMock );
227+ $ this ->sut ()->resetSecret ($ request );
218228 }
219229
220230 public function testResetSecretThrowsIfCurrentSecretNotValid (): void
221231 {
222- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
232+ $ request = Request::create (
233+ '/resetSecret?client_id=clientId ' ,
234+ 'POST ' ,
235+ ['client_id ' => 'clientId ' , 'secret ' => '321 ' ],
236+ );
237+
223238 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('getSecret ' )->willReturn ('123 ' );
224239 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
225240 ->willReturn ($ this ->clientEntityMock );
226- $ this ->requestInputBagMock ->expects ($ this ->once ())->method ('getString ' )
227- ->with ('secret ' )->willReturn ('321 ' );
228241
229242 $ this ->expectException (OidcException::class);
230243 $ this ->expectExceptionMessage ('Client secret ' );
231244
232- $ this ->sut ()->resetSecret ($ this -> requestMock );
245+ $ this ->sut ()->resetSecret ($ request );
233246 }
234247
235248 public function testCanDelete (): void
236249 {
237- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
250+ $ request = Request::create (
251+ '/delete?client_id=clientId ' ,
252+ 'POST ' ,
253+ ['client_id ' => 'clientId ' , 'secret ' => '123 ' ],
254+ );
255+
238256 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('getSecret ' )->willReturn ('123 ' );
239257 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
240258 ->willReturn ($ this ->clientEntityMock );
241- $ this ->requestInputBagMock ->expects ($ this ->once ())->method ('getString ' )
242- ->with ('secret ' )->willReturn ('123 ' );
243259 $ this ->sessionMessagesServiceMock ->expects ($ this ->once ())->method ('addMessage ' )
244260 ->with ($ this ->stringContains ('deleted ' ));
245261 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('delete ' )
246262 ->with ($ this ->clientEntityMock );
247263
248- $ this ->sut ()->delete ($ this -> requestMock );
264+ $ this ->sut ()->delete ($ request );
249265 }
250266
251267 public function testDeleteThrowsIfCurrentSecretNotValid (): void
252268 {
253- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
269+ $ request = Request::create (
270+ '/resetSecret?client_id=clientId ' ,
271+ 'POST ' ,
272+ ['client_id ' => 'clientId ' , 'secret ' => '321 ' ],
273+ );
274+
254275 $ this ->clientEntityMock ->expects ($ this ->once ())->method ('getSecret ' )->willReturn ('123 ' );
255276 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
256277 ->willReturn ($ this ->clientEntityMock );
257- $ this ->requestInputBagMock ->expects ($ this ->once ())->method ('getString ' )
258- ->with ('secret ' )->willReturn ('321 ' );
259278
260279 $ this ->expectException (OidcException::class);
261280 $ this ->expectExceptionMessage ('Client secret ' );
262281
263- $ this ->sut ()->delete ($ this -> requestMock );
282+ $ this ->sut ()->delete ($ request );
264283 }
265284
266285 public function testCanAdd (): void
@@ -348,10 +367,15 @@ public function testThrowsForInvalidClientData(): void
348367
349368 public function testCanEdit (): void
350369 {
370+ $ request = Request::create (
371+ '/edit?client_id=clientId ' ,
372+ 'GET ' ,
373+ ['client_id ' => 'clientId ' , 'secret ' => '123 ' ],
374+ );
375+
351376 // Original client.
352377 // Enum can't be doubled :/.
353378 $ this ->clientEntityMock ->method ('getRegistrationType ' )->willReturn (RegistrationTypeEnum::Manual);
354- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
355379 $ this ->clientEntityMock ->method ('getIdentifier ' )->willReturn ('clientId ' );
356380 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
357381 ->willReturn ($ this ->clientEntityMock );
@@ -373,15 +397,20 @@ public function testCanEdit(): void
373397 $ this ->allowedOriginRepositoryMock ->expects ($ this ->once ())->method ('set ' )
374398 ->with ('clientId ' );
375399
376- $ this ->sut ()->edit ($ this -> requestMock );
400+ $ this ->sut ()->edit ($ request );
377401 }
378402
379403 public function testWontEditIfClientEntityIdentifierExists (): void
380404 {
405+ $ request = Request::create (
406+ '/edit?client_id=clientId ' ,
407+ 'GET ' ,
408+ ['client_id ' => 'clientId ' , 'secret ' => '123 ' ],
409+ );
410+
381411 // Original client.
382412 // Enum can't be doubled :/.
383413 $ this ->clientEntityMock ->method ('getRegistrationType ' )->willReturn (RegistrationTypeEnum::Manual);
384- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
385414 $ this ->clientEntityMock ->method ('getIdentifier ' )->willReturn ('clientId ' );
386415 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
387416 ->willReturn ($ this ->clientEntityMock );
@@ -408,12 +437,17 @@ public function testWontEditIfClientEntityIdentifierExists(): void
408437 $ this ->sessionMessagesServiceMock ->expects ($ this ->once ())->method ('addMessage ' )
409438 ->with ($ this ->stringContains ('exists ' ));
410439
411- $ this ->sut ()->edit ($ this -> requestMock );
440+ $ this ->sut ()->edit ($ request );
412441 }
413442
414443 public function testCanShowEditForm (): void
415444 {
416- $ this ->queryInputBagMock ->expects ($ this ->once ())->method ('getString ' )->willReturn ('clientId ' );
445+ $ request = Request::create (
446+ '/edit?client_id=clientId ' ,
447+ 'GET ' ,
448+ ['client_id ' => 'clientId ' , 'secret ' => '123 ' ],
449+ );
450+
417451 $ this ->clientEntityMock ->method ('getIdentifier ' )->willReturn ('clientId ' );
418452 $ this ->clientRepositoryMock ->expects ($ this ->once ())->method ('findById ' )->with ('clientId ' )
419453 ->willReturn ($ this ->clientEntityMock );
@@ -423,6 +457,6 @@ public function testCanShowEditForm(): void
423457 $ this ->templateFactoryMock ->expects ($ this ->once ())->method ('build ' )
424458 ->with ('oidc:clients/edit.twig ' );
425459
426- $ this ->sut ()->edit ($ this -> requestMock );
460+ $ this ->sut ()->edit ($ request );
427461 }
428462}
0 commit comments