@@ -87,12 +87,12 @@ public function testActionPost()
87
87
'Controller.initialize ' ,
88
88
['priority ' => 11 ],
89
89
function ($ event ) {
90
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
90
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
91
91
->onlyMethods (['set ' ])
92
92
->setConstructorArgs ([$ this ->_controller ->components ()])
93
93
->getMock ();
94
94
95
- $ this -> _controller -> Flash
95
+ $ component
96
96
->expects ($ this ->once ())
97
97
->method ('set ' )
98
98
->with (
@@ -104,6 +104,8 @@ function ($event) {
104
104
]
105
105
);
106
106
107
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
108
+
107
109
$ this ->_subscribeToEvents ($ this ->_controller );
108
110
}
109
111
);
@@ -132,12 +134,12 @@ public function testActionPostWithAddRedirect()
132
134
'Controller.initialize ' ,
133
135
['priority ' => 11 ],
134
136
function ($ event ) {
135
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
137
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
136
138
->onlyMethods (['set ' ])
137
139
->setConstructorArgs ([$ this ->_controller ->components ()])
138
140
->getMock ();
139
141
140
- $ this -> _controller -> Flash
142
+ $ component
141
143
->expects ($ this ->once ())
142
144
->method ('set ' )
143
145
->with (
@@ -149,6 +151,8 @@ function ($event) {
149
151
]
150
152
);
151
153
154
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
155
+
152
156
$ this ->_subscribeToEvents ($ this ->_controller );
153
157
}
154
158
);
@@ -177,12 +181,12 @@ public function testActionPostWithEditRedirect()
177
181
'Controller.initialize ' ,
178
182
['priority ' => 11 ],
179
183
function ($ event ) {
180
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
184
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
181
185
->onlyMethods (['set ' ])
182
186
->setConstructorArgs ([$ this ->_controller ->components ()])
183
187
->getMock ();
184
188
185
- $ this -> _controller -> Flash
189
+ $ component
186
190
->expects ($ this ->once ())
187
191
->method ('set ' )
188
192
->with (
@@ -194,6 +198,8 @@ function ($event) {
194
198
]
195
199
);
196
200
201
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
202
+
197
203
$ this ->_subscribeToEvents ($ this ->_controller );
198
204
}
199
205
);
@@ -221,12 +227,12 @@ public function testActionPostErrorSave()
221
227
'Controller.initialize ' ,
222
228
['priority ' => 11 ],
223
229
function ($ event ) {
224
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
230
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
225
231
->onlyMethods (['set ' ])
226
232
->setConstructorArgs ([$ this ->_controller ->components ()])
227
233
->getMock ();
228
234
229
- $ this -> _controller -> Flash
235
+ $ component
230
236
->expects ($ this ->once ())
231
237
->method ('set ' )
232
238
->with (
@@ -238,6 +244,8 @@ function ($event) {
238
244
]
239
245
);
240
246
247
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
248
+
241
249
$ this ->_subscribeToEvents ($ this ->_controller );
242
250
243
251
$ blogs = $ this ->getMockForModel (
@@ -248,7 +256,7 @@ function ($event) {
248
256
$ blogs
249
257
->expects ($ this ->once ())
250
258
->method ('save ' )
251
- ->will ( $ this -> returnValue ( false ) );
259
+ ->willReturn ( false );
252
260
253
261
$ this ->getTableLocator ()->set ('Blogs ' , $ blogs );
254
262
}
@@ -275,12 +283,12 @@ public function testActionPostValidationErrors()
275
283
'Controller.initialize ' ,
276
284
['priority ' => 11 ],
277
285
function ($ event ) {
278
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
286
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
279
287
->onlyMethods (['set ' ])
280
288
->setConstructorArgs ([$ this ->_controller ->components ()])
281
289
->getMock ();
282
290
283
- $ this -> _controller -> Flash
291
+ $ component
284
292
->expects ($ this ->once ())
285
293
->method ('set ' )
286
294
->with (
@@ -292,6 +300,8 @@ function ($event) {
292
300
]
293
301
);
294
302
303
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
304
+
295
305
$ this ->_subscribeToEvents ($ this ->_controller );
296
306
297
307
$ this ->_controller ->Blogs
@@ -344,10 +354,10 @@ public static function apiGetHttpMethodProvider()
344
354
/**
345
355
* Test HTTP & DELETE verbs using API Listener
346
356
*
347
- * @dataProvider apiGetHttpMethodProvider
348
357
* @param string $method
349
358
* @return void
350
359
*/
360
+ #[\PHPUnit \Framework \Attributes \DataProvider('apiGetHttpMethodProvider ' )]
351
361
public function testApiGet ($ method )
352
362
{
353
363
Router::createRouteBuilder ('/ ' )
@@ -376,25 +386,27 @@ public static function apiUpdateHttpMethodProvider()
376
386
/**
377
387
* Test POST & PUT verbs using API Listener
378
388
*
379
- * @dataProvider apiUpdateHttpMethodProvider
380
389
* @param string $method
381
390
* @return void
382
391
*/
392
+ #[\PHPUnit \Framework \Attributes \DataProvider('apiUpdateHttpMethodProvider ' )]
383
393
public function testApiCreate ($ method )
384
394
{
385
395
$ this ->_eventManager ->on (
386
396
'Controller.initialize ' ,
387
397
['priority ' => 11 ],
388
398
function ($ event ) {
389
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
399
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
390
400
->onlyMethods (['set ' ])
391
401
->setConstructorArgs ([$ this ->_controller ->components ()])
392
402
->getMock ();
393
403
394
- $ this -> _controller -> Flash
404
+ $ component
395
405
->expects ($ this ->never ())
396
406
->method ('set ' );
397
407
408
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
409
+
398
410
$ this ->_subscribeToEvents ($ this ->_controller );
399
411
400
412
$ this ->_controller ->Crud ->addListener ('api ' , 'Crud.Api ' );
@@ -417,10 +429,10 @@ function ($event) {
417
429
* Test POST & PUT verbs using API Listener
418
430
* with data validation error
419
431
*
420
- * @dataProvider apiUpdateHttpMethodProvider
421
432
* @param string $method
422
433
* @return void
423
434
*/
435
+ #[\PHPUnit \Framework \Attributes \DataProvider('apiUpdateHttpMethodProvider ' )]
424
436
public function testApiCreateError ($ method )
425
437
{
426
438
$ this ->_eventManager ->on (
@@ -431,15 +443,17 @@ function ($event) {
431
443
return ;
432
444
}
433
445
434
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
446
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
435
447
->onlyMethods (['set ' ])
436
448
->setConstructorArgs ([$ this ->_controller ->components ()])
437
449
->getMock ();
438
450
439
- $ this -> _controller -> Flash
451
+ $ component
440
452
->expects ($ this ->never ())
441
453
->method ('set ' );
442
454
455
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
456
+
443
457
$ this ->_subscribeToEvents ($ this ->_controller );
444
458
445
459
$ this ->_controller ->Crud ->addListener ('api ' , 'Crud.Api ' );
@@ -469,10 +483,10 @@ function ($event) {
469
483
* Test POST & PUT verbs using API Listener
470
484
* with data validation errors
471
485
*
472
- * @dataProvider apiUpdateHttpMethodProvider
473
486
* @param string $method
474
487
* @return void
475
488
*/
489
+ #[\PHPUnit \Framework \Attributes \DataProvider('apiUpdateHttpMethodProvider ' )]
476
490
public function testApiCreateErrors ($ method )
477
491
{
478
492
$ this ->_eventManager ->on (
@@ -483,15 +497,17 @@ function ($event) {
483
497
return ;
484
498
}
485
499
486
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
500
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
487
501
->onlyMethods (['set ' ])
488
502
->setConstructorArgs ([$ this ->_controller ->components ()])
489
503
->getMock ();
490
504
491
- $ this -> _controller -> Flash
505
+ $ component
492
506
->expects ($ this ->never ())
493
507
->method ('set ' );
494
508
509
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
510
+
495
511
$ this ->_subscribeToEvents ($ this ->_controller );
496
512
497
513
$ this ->_controller ->Crud ->addListener ('api ' , 'Crud.Api ' );
@@ -529,12 +545,12 @@ public function testStopAddWithDefaultSubjectSuccess()
529
545
'Controller.initialize ' ,
530
546
['priority ' => 11 ],
531
547
function ($ event ) {
532
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
548
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
533
549
->onlyMethods (['set ' ])
534
550
->setConstructorArgs ([$ this ->_controller ->components ()])
535
551
->getMock ();
536
552
537
- $ this -> _controller -> Flash
553
+ $ component
538
554
->expects ($ this ->once ())
539
555
->method ('set ' )
540
556
->with (
@@ -546,17 +562,21 @@ function ($event) {
546
562
]
547
563
);
548
564
565
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
566
+
549
567
$ this ->_subscribeToEvents ($ this ->_controller );
550
568
551
569
$ this ->_controller ->Crud ->on ('beforeSave ' , function ($ event ) {
552
570
$ event ->stopPropagation ();
553
571
});
554
572
555
- $ this -> _controller -> Blogs = $ this ->getMockForModel (
573
+ $ model = $ this ->getMockForModel (
556
574
$ this ->tableClass ,
557
575
[],
558
576
['alias ' => 'Blogs ' , 'table ' => 'blogs ' ]
559
577
);
578
+
579
+ $ this ->getTableLocator ()->set ('Blogs ' , $ model );
560
580
}
561
581
);
562
582
@@ -579,12 +599,12 @@ public function testStopAddWithManuallySetSubjectSuccess()
579
599
'Controller.initialize ' ,
580
600
['priority ' => 11 ],
581
601
function ($ event ) {
582
- $ this -> _controller -> Flash = $ this ->getMockBuilder (FlashComponent::class)
602
+ $ component = $ this ->getMockBuilder (FlashComponent::class)
583
603
->onlyMethods (['set ' ])
584
604
->setConstructorArgs ([$ this ->_controller ->components ()])
585
605
->getMock ();
586
606
587
- $ this -> _controller -> Flash
607
+ $ component
588
608
->expects ($ this ->once ())
589
609
->method ('set ' )
590
610
->with (
@@ -596,18 +616,22 @@ function ($event) {
596
616
]
597
617
);
598
618
619
+ $ this ->_controller ->components ()->set ('Flash ' , $ component );
620
+
599
621
$ this ->_subscribeToEvents ($ this ->_controller );
600
622
601
623
$ this ->_controller ->Crud ->on ('beforeSave ' , function ($ event ) {
602
624
$ event ->stopPropagation ();
603
625
$ event ->getSubject ()->success = true ; // assert this
604
626
});
605
627
606
- $ this -> _controller -> Blogs = $ this ->getMockForModel (
628
+ $ model = $ this ->getMockForModel (
607
629
$ this ->tableClass ,
608
630
[],
609
631
['alias ' => 'Blogs ' , 'table ' => 'blogs ' ]
610
632
);
633
+
634
+ $ this ->getTableLocator ()->set ('Blogs ' , $ model );
611
635
}
612
636
);
613
637
0 commit comments