Skip to content

Commit 544cfcc

Browse files
committed
Update deps and fix deprecations
1 parent 5ebd299 commit 544cfcc

23 files changed

+318
-246
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"require-dev": {
4545
"friendsofcake/cakephp-test-utilities": "^3.0",
4646
"friendsofcake/search": "^7.0",
47-
"phpunit/phpunit": "^10.1"
47+
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
4848
},
4949
"autoload": {
5050
"psr-4": {

src/Controller/ControllerTrait.php

+1-16
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,10 @@ public function invokeAction(Closure $action, array $args): void
7878
*
7979
* @param array<string, class-string<\Cake\View\View>> $map View class map.
8080
* @return void
81+
* @deprecated 7.1.0 Use addViewClasses() instead.
8182
*/
8283
public function setViewClasses(array $map): void
8384
{
8485
$this->viewClasses = $map;
8586
}
86-
87-
/**
88-
* Get the View classes this controller can perform content negotiation with.
89-
*
90-
* Each view class must implement the `getContentType()` hook method
91-
* to participate in negotiation.
92-
*
93-
* This overrides the Controller::viewClasses() of core.
94-
*
95-
* @see Cake\Http\ContentTypeNegotiation
96-
* @return array<string, class-string<\Cake\View\View>>
97-
*/
98-
public function viewClasses(): array
99-
{
100-
return $this->viewClasses;
101-
}
10287
}

src/Listener/ApiListener.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ protected function _expandPath(Subject $subject, string $path): string
336336
*/
337337
public function injectViewClasses(): void
338338
{
339-
$this->_controller()->setViewClasses($this->getConfig('viewClasses'));
339+
$this->_controller()->addViewClasses($this->getConfig('viewClasses'));
340340
}
341341

342342
/**

tests/TestCase/Action/AddActionTest.php

+51-27
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public function testActionPost()
8787
'Controller.initialize',
8888
['priority' => 11],
8989
function ($event) {
90-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
90+
$component = $this->getMockBuilder(FlashComponent::class)
9191
->onlyMethods(['set'])
9292
->setConstructorArgs([$this->_controller->components()])
9393
->getMock();
9494

95-
$this->_controller->Flash
95+
$component
9696
->expects($this->once())
9797
->method('set')
9898
->with(
@@ -104,6 +104,8 @@ function ($event) {
104104
]
105105
);
106106

107+
$this->_controller->components()->set('Flash', $component);
108+
107109
$this->_subscribeToEvents($this->_controller);
108110
}
109111
);
@@ -132,12 +134,12 @@ public function testActionPostWithAddRedirect()
132134
'Controller.initialize',
133135
['priority' => 11],
134136
function ($event) {
135-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
137+
$component = $this->getMockBuilder(FlashComponent::class)
136138
->onlyMethods(['set'])
137139
->setConstructorArgs([$this->_controller->components()])
138140
->getMock();
139141

140-
$this->_controller->Flash
142+
$component
141143
->expects($this->once())
142144
->method('set')
143145
->with(
@@ -149,6 +151,8 @@ function ($event) {
149151
]
150152
);
151153

154+
$this->_controller->components()->set('Flash', $component);
155+
152156
$this->_subscribeToEvents($this->_controller);
153157
}
154158
);
@@ -177,12 +181,12 @@ public function testActionPostWithEditRedirect()
177181
'Controller.initialize',
178182
['priority' => 11],
179183
function ($event) {
180-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
184+
$component = $this->getMockBuilder(FlashComponent::class)
181185
->onlyMethods(['set'])
182186
->setConstructorArgs([$this->_controller->components()])
183187
->getMock();
184188

185-
$this->_controller->Flash
189+
$component
186190
->expects($this->once())
187191
->method('set')
188192
->with(
@@ -194,6 +198,8 @@ function ($event) {
194198
]
195199
);
196200

201+
$this->_controller->components()->set('Flash', $component);
202+
197203
$this->_subscribeToEvents($this->_controller);
198204
}
199205
);
@@ -221,12 +227,12 @@ public function testActionPostErrorSave()
221227
'Controller.initialize',
222228
['priority' => 11],
223229
function ($event) {
224-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
230+
$component = $this->getMockBuilder(FlashComponent::class)
225231
->onlyMethods(['set'])
226232
->setConstructorArgs([$this->_controller->components()])
227233
->getMock();
228234

229-
$this->_controller->Flash
235+
$component
230236
->expects($this->once())
231237
->method('set')
232238
->with(
@@ -238,6 +244,8 @@ function ($event) {
238244
]
239245
);
240246

247+
$this->_controller->components()->set('Flash', $component);
248+
241249
$this->_subscribeToEvents($this->_controller);
242250

243251
$blogs = $this->getMockForModel(
@@ -248,7 +256,7 @@ function ($event) {
248256
$blogs
249257
->expects($this->once())
250258
->method('save')
251-
->will($this->returnValue(false));
259+
->willReturn(false);
252260

253261
$this->getTableLocator()->set('Blogs', $blogs);
254262
}
@@ -275,12 +283,12 @@ public function testActionPostValidationErrors()
275283
'Controller.initialize',
276284
['priority' => 11],
277285
function ($event) {
278-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
286+
$component = $this->getMockBuilder(FlashComponent::class)
279287
->onlyMethods(['set'])
280288
->setConstructorArgs([$this->_controller->components()])
281289
->getMock();
282290

283-
$this->_controller->Flash
291+
$component
284292
->expects($this->once())
285293
->method('set')
286294
->with(
@@ -292,6 +300,8 @@ function ($event) {
292300
]
293301
);
294302

303+
$this->_controller->components()->set('Flash', $component);
304+
295305
$this->_subscribeToEvents($this->_controller);
296306

297307
$this->_controller->Blogs
@@ -344,10 +354,10 @@ public static function apiGetHttpMethodProvider()
344354
/**
345355
* Test HTTP & DELETE verbs using API Listener
346356
*
347-
* @dataProvider apiGetHttpMethodProvider
348357
* @param string $method
349358
* @return void
350359
*/
360+
#[\PHPUnit\Framework\Attributes\DataProvider('apiGetHttpMethodProvider')]
351361
public function testApiGet($method)
352362
{
353363
Router::createRouteBuilder('/')
@@ -376,25 +386,27 @@ public static function apiUpdateHttpMethodProvider()
376386
/**
377387
* Test POST & PUT verbs using API Listener
378388
*
379-
* @dataProvider apiUpdateHttpMethodProvider
380389
* @param string $method
381390
* @return void
382391
*/
392+
#[\PHPUnit\Framework\Attributes\DataProvider('apiUpdateHttpMethodProvider')]
383393
public function testApiCreate($method)
384394
{
385395
$this->_eventManager->on(
386396
'Controller.initialize',
387397
['priority' => 11],
388398
function ($event) {
389-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
399+
$component = $this->getMockBuilder(FlashComponent::class)
390400
->onlyMethods(['set'])
391401
->setConstructorArgs([$this->_controller->components()])
392402
->getMock();
393403

394-
$this->_controller->Flash
404+
$component
395405
->expects($this->never())
396406
->method('set');
397407

408+
$this->_controller->components()->set('Flash', $component);
409+
398410
$this->_subscribeToEvents($this->_controller);
399411

400412
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -417,10 +429,10 @@ function ($event) {
417429
* Test POST & PUT verbs using API Listener
418430
* with data validation error
419431
*
420-
* @dataProvider apiUpdateHttpMethodProvider
421432
* @param string $method
422433
* @return void
423434
*/
435+
#[\PHPUnit\Framework\Attributes\DataProvider('apiUpdateHttpMethodProvider')]
424436
public function testApiCreateError($method)
425437
{
426438
$this->_eventManager->on(
@@ -431,15 +443,17 @@ function ($event) {
431443
return;
432444
}
433445

434-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
446+
$component = $this->getMockBuilder(FlashComponent::class)
435447
->onlyMethods(['set'])
436448
->setConstructorArgs([$this->_controller->components()])
437449
->getMock();
438450

439-
$this->_controller->Flash
451+
$component
440452
->expects($this->never())
441453
->method('set');
442454

455+
$this->_controller->components()->set('Flash', $component);
456+
443457
$this->_subscribeToEvents($this->_controller);
444458

445459
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -469,10 +483,10 @@ function ($event) {
469483
* Test POST & PUT verbs using API Listener
470484
* with data validation errors
471485
*
472-
* @dataProvider apiUpdateHttpMethodProvider
473486
* @param string $method
474487
* @return void
475488
*/
489+
#[\PHPUnit\Framework\Attributes\DataProvider('apiUpdateHttpMethodProvider')]
476490
public function testApiCreateErrors($method)
477491
{
478492
$this->_eventManager->on(
@@ -483,15 +497,17 @@ function ($event) {
483497
return;
484498
}
485499

486-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
500+
$component = $this->getMockBuilder(FlashComponent::class)
487501
->onlyMethods(['set'])
488502
->setConstructorArgs([$this->_controller->components()])
489503
->getMock();
490504

491-
$this->_controller->Flash
505+
$component
492506
->expects($this->never())
493507
->method('set');
494508

509+
$this->_controller->components()->set('Flash', $component);
510+
495511
$this->_subscribeToEvents($this->_controller);
496512

497513
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -529,12 +545,12 @@ public function testStopAddWithDefaultSubjectSuccess()
529545
'Controller.initialize',
530546
['priority' => 11],
531547
function ($event) {
532-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
548+
$component = $this->getMockBuilder(FlashComponent::class)
533549
->onlyMethods(['set'])
534550
->setConstructorArgs([$this->_controller->components()])
535551
->getMock();
536552

537-
$this->_controller->Flash
553+
$component
538554
->expects($this->once())
539555
->method('set')
540556
->with(
@@ -546,17 +562,21 @@ function ($event) {
546562
]
547563
);
548564

565+
$this->_controller->components()->set('Flash', $component);
566+
549567
$this->_subscribeToEvents($this->_controller);
550568

551569
$this->_controller->Crud->on('beforeSave', function ($event) {
552570
$event->stopPropagation();
553571
});
554572

555-
$this->_controller->Blogs = $this->getMockForModel(
573+
$model = $this->getMockForModel(
556574
$this->tableClass,
557575
[],
558576
['alias' => 'Blogs', 'table' => 'blogs']
559577
);
578+
579+
$this->getTableLocator()->set('Blogs', $model);
560580
}
561581
);
562582

@@ -579,12 +599,12 @@ public function testStopAddWithManuallySetSubjectSuccess()
579599
'Controller.initialize',
580600
['priority' => 11],
581601
function ($event) {
582-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
602+
$component = $this->getMockBuilder(FlashComponent::class)
583603
->onlyMethods(['set'])
584604
->setConstructorArgs([$this->_controller->components()])
585605
->getMock();
586606

587-
$this->_controller->Flash
607+
$component
588608
->expects($this->once())
589609
->method('set')
590610
->with(
@@ -596,18 +616,22 @@ function ($event) {
596616
]
597617
);
598618

619+
$this->_controller->components()->set('Flash', $component);
620+
599621
$this->_subscribeToEvents($this->_controller);
600622

601623
$this->_controller->Crud->on('beforeSave', function ($event) {
602624
$event->stopPropagation();
603625
$event->getSubject()->success = true; // assert this
604626
});
605627

606-
$this->_controller->Blogs = $this->getMockForModel(
628+
$model = $this->getMockForModel(
607629
$this->tableClass,
608630
[],
609631
['alias' => 'Blogs', 'table' => 'blogs']
610632
);
633+
634+
$this->getTableLocator()->set('Blogs', $model);
611635
}
612636
);
613637

0 commit comments

Comments
 (0)