Skip to content

Commit 1472e01

Browse files
authored
Merge pull request #715 from FriendsOfCake/maintainance
Update deps and fix deprecations
2 parents 751919c + 99c1289 commit 1472e01

27 files changed

+330
-245
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": {

phpstan-baseline.neon

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
parameters:
22
ignoreErrors:
3+
-
4+
identifier: missingType.iterableValue
35
-
46
message: "#^Call to an undefined method Crud\\\\Action\\\\BaseAction\\:\\:findMethod\\(\\)\\.$#"
57
count: 2
@@ -19,8 +21,3 @@ parameters:
1921
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Crud\\.$#"
2022
count: 1
2123
path: src/Core/BaseObject.php
22-
23-
-
24-
message: "#^Call to an undefined method Cake\\\\Controller\\\\Controller\\:\\:setViewClasses\\(\\)\\.$#"
25-
count: 1
26-
path: src/Listener/ApiListener.php

phpstan.neon

-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ parameters:
55
level: 6
66
paths:
77
- src
8-
checkMissingIterableValueType: false
9-
checkGenericClassInNonGenericObjectType: false
108
excludePaths:
119
- */src/TestSuite/*
1210
universalObjectCratesClasses:
1311
- Crud\Event\Subject
14-
bootstrapFiles:
15-
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php

psalm-baseline.xml

-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<files psalm-version="4.x-dev@">
3-
<file src="src/Listener/ApiListener.php">
4-
<UndefinedMethod occurrences="1">
5-
<code>setViewClasses</code>
6-
</UndefinedMethod>
7-
</file>
83
<file src="src/Listener/ApiQueryLogListener.php">
94
<InternalMethod occurrences="1">
105
<code>new QueryLogger()</code>

src/Controller/ControllerTrait.php

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ 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
{

src/Core/BaseObject.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function implementedEvents(): array
6060
/**
6161
* Convenient method for Request::is
6262
*
63-
* @param array|string $method Method(s) to check for
63+
* @param list<string>|string $method Method(s) to check for
6464
* @return bool
6565
*/
6666
protected function _checkRequestType(array|string $method): bool

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

+52-27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Cake\Core\Configure;
88
use Cake\Routing\Router;
99
use Crud\TestSuite\IntegrationTestCase;
10+
use PHPUnit\Framework\Attributes\DataProvider;
1011

1112
/**
1213
* Licensed under The MIT License
@@ -87,12 +88,12 @@ public function testActionPost()
8788
'Controller.initialize',
8889
['priority' => 11],
8990
function ($event) {
90-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
91+
$component = $this->getMockBuilder(FlashComponent::class)
9192
->onlyMethods(['set'])
9293
->setConstructorArgs([$this->_controller->components()])
9394
->getMock();
9495

95-
$this->_controller->Flash
96+
$component
9697
->expects($this->once())
9798
->method('set')
9899
->with(
@@ -104,6 +105,8 @@ function ($event) {
104105
]
105106
);
106107

108+
$this->_controller->components()->set('Flash', $component);
109+
107110
$this->_subscribeToEvents($this->_controller);
108111
}
109112
);
@@ -132,12 +135,12 @@ public function testActionPostWithAddRedirect()
132135
'Controller.initialize',
133136
['priority' => 11],
134137
function ($event) {
135-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
138+
$component = $this->getMockBuilder(FlashComponent::class)
136139
->onlyMethods(['set'])
137140
->setConstructorArgs([$this->_controller->components()])
138141
->getMock();
139142

140-
$this->_controller->Flash
143+
$component
141144
->expects($this->once())
142145
->method('set')
143146
->with(
@@ -149,6 +152,8 @@ function ($event) {
149152
]
150153
);
151154

155+
$this->_controller->components()->set('Flash', $component);
156+
152157
$this->_subscribeToEvents($this->_controller);
153158
}
154159
);
@@ -177,12 +182,12 @@ public function testActionPostWithEditRedirect()
177182
'Controller.initialize',
178183
['priority' => 11],
179184
function ($event) {
180-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
185+
$component = $this->getMockBuilder(FlashComponent::class)
181186
->onlyMethods(['set'])
182187
->setConstructorArgs([$this->_controller->components()])
183188
->getMock();
184189

185-
$this->_controller->Flash
190+
$component
186191
->expects($this->once())
187192
->method('set')
188193
->with(
@@ -194,6 +199,8 @@ function ($event) {
194199
]
195200
);
196201

202+
$this->_controller->components()->set('Flash', $component);
203+
197204
$this->_subscribeToEvents($this->_controller);
198205
}
199206
);
@@ -221,12 +228,12 @@ public function testActionPostErrorSave()
221228
'Controller.initialize',
222229
['priority' => 11],
223230
function ($event) {
224-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
231+
$component = $this->getMockBuilder(FlashComponent::class)
225232
->onlyMethods(['set'])
226233
->setConstructorArgs([$this->_controller->components()])
227234
->getMock();
228235

229-
$this->_controller->Flash
236+
$component
230237
->expects($this->once())
231238
->method('set')
232239
->with(
@@ -238,6 +245,8 @@ function ($event) {
238245
]
239246
);
240247

248+
$this->_controller->components()->set('Flash', $component);
249+
241250
$this->_subscribeToEvents($this->_controller);
242251

243252
$blogs = $this->getMockForModel(
@@ -248,7 +257,7 @@ function ($event) {
248257
$blogs
249258
->expects($this->once())
250259
->method('save')
251-
->will($this->returnValue(false));
260+
->willReturn(false);
252261

253262
$this->getTableLocator()->set('Blogs', $blogs);
254263
}
@@ -275,12 +284,12 @@ public function testActionPostValidationErrors()
275284
'Controller.initialize',
276285
['priority' => 11],
277286
function ($event) {
278-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
287+
$component = $this->getMockBuilder(FlashComponent::class)
279288
->onlyMethods(['set'])
280289
->setConstructorArgs([$this->_controller->components()])
281290
->getMock();
282291

283-
$this->_controller->Flash
292+
$component
284293
->expects($this->once())
285294
->method('set')
286295
->with(
@@ -292,6 +301,8 @@ function ($event) {
292301
]
293302
);
294303

304+
$this->_controller->components()->set('Flash', $component);
305+
295306
$this->_subscribeToEvents($this->_controller);
296307

297308
$this->_controller->Blogs
@@ -344,10 +355,10 @@ public static function apiGetHttpMethodProvider()
344355
/**
345356
* Test HTTP & DELETE verbs using API Listener
346357
*
347-
* @dataProvider apiGetHttpMethodProvider
348358
* @param string $method
349359
* @return void
350360
*/
361+
#[DataProvider('apiGetHttpMethodProvider')]
351362
public function testApiGet($method)
352363
{
353364
Router::createRouteBuilder('/')
@@ -376,25 +387,27 @@ public static function apiUpdateHttpMethodProvider()
376387
/**
377388
* Test POST & PUT verbs using API Listener
378389
*
379-
* @dataProvider apiUpdateHttpMethodProvider
380390
* @param string $method
381391
* @return void
382392
*/
393+
#[DataProvider('apiUpdateHttpMethodProvider')]
383394
public function testApiCreate($method)
384395
{
385396
$this->_eventManager->on(
386397
'Controller.initialize',
387398
['priority' => 11],
388399
function ($event) {
389-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
400+
$component = $this->getMockBuilder(FlashComponent::class)
390401
->onlyMethods(['set'])
391402
->setConstructorArgs([$this->_controller->components()])
392403
->getMock();
393404

394-
$this->_controller->Flash
405+
$component
395406
->expects($this->never())
396407
->method('set');
397408

409+
$this->_controller->components()->set('Flash', $component);
410+
398411
$this->_subscribeToEvents($this->_controller);
399412

400413
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -417,10 +430,10 @@ function ($event) {
417430
* Test POST & PUT verbs using API Listener
418431
* with data validation error
419432
*
420-
* @dataProvider apiUpdateHttpMethodProvider
421433
* @param string $method
422434
* @return void
423435
*/
436+
#[DataProvider('apiUpdateHttpMethodProvider')]
424437
public function testApiCreateError($method)
425438
{
426439
$this->_eventManager->on(
@@ -431,15 +444,17 @@ function ($event) {
431444
return;
432445
}
433446

434-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
447+
$component = $this->getMockBuilder(FlashComponent::class)
435448
->onlyMethods(['set'])
436449
->setConstructorArgs([$this->_controller->components()])
437450
->getMock();
438451

439-
$this->_controller->Flash
452+
$component
440453
->expects($this->never())
441454
->method('set');
442455

456+
$this->_controller->components()->set('Flash', $component);
457+
443458
$this->_subscribeToEvents($this->_controller);
444459

445460
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -469,10 +484,10 @@ function ($event) {
469484
* Test POST & PUT verbs using API Listener
470485
* with data validation errors
471486
*
472-
* @dataProvider apiUpdateHttpMethodProvider
473487
* @param string $method
474488
* @return void
475489
*/
490+
#[DataProvider('apiUpdateHttpMethodProvider')]
476491
public function testApiCreateErrors($method)
477492
{
478493
$this->_eventManager->on(
@@ -483,15 +498,17 @@ function ($event) {
483498
return;
484499
}
485500

486-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
501+
$component = $this->getMockBuilder(FlashComponent::class)
487502
->onlyMethods(['set'])
488503
->setConstructorArgs([$this->_controller->components()])
489504
->getMock();
490505

491-
$this->_controller->Flash
506+
$component
492507
->expects($this->never())
493508
->method('set');
494509

510+
$this->_controller->components()->set('Flash', $component);
511+
495512
$this->_subscribeToEvents($this->_controller);
496513

497514
$this->_controller->Crud->addListener('api', 'Crud.Api');
@@ -529,12 +546,12 @@ public function testStopAddWithDefaultSubjectSuccess()
529546
'Controller.initialize',
530547
['priority' => 11],
531548
function ($event) {
532-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
549+
$component = $this->getMockBuilder(FlashComponent::class)
533550
->onlyMethods(['set'])
534551
->setConstructorArgs([$this->_controller->components()])
535552
->getMock();
536553

537-
$this->_controller->Flash
554+
$component
538555
->expects($this->once())
539556
->method('set')
540557
->with(
@@ -546,17 +563,21 @@ function ($event) {
546563
]
547564
);
548565

566+
$this->_controller->components()->set('Flash', $component);
567+
549568
$this->_subscribeToEvents($this->_controller);
550569

551570
$this->_controller->Crud->on('beforeSave', function ($event) {
552571
$event->stopPropagation();
553572
});
554573

555-
$this->_controller->Blogs = $this->getMockForModel(
574+
$model = $this->getMockForModel(
556575
$this->tableClass,
557576
[],
558577
['alias' => 'Blogs', 'table' => 'blogs']
559578
);
579+
580+
$this->getTableLocator()->set('Blogs', $model);
560581
}
561582
);
562583

@@ -579,12 +600,12 @@ public function testStopAddWithManuallySetSubjectSuccess()
579600
'Controller.initialize',
580601
['priority' => 11],
581602
function ($event) {
582-
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
603+
$component = $this->getMockBuilder(FlashComponent::class)
583604
->onlyMethods(['set'])
584605
->setConstructorArgs([$this->_controller->components()])
585606
->getMock();
586607

587-
$this->_controller->Flash
608+
$component
588609
->expects($this->once())
589610
->method('set')
590611
->with(
@@ -596,18 +617,22 @@ function ($event) {
596617
]
597618
);
598619

620+
$this->_controller->components()->set('Flash', $component);
621+
599622
$this->_subscribeToEvents($this->_controller);
600623

601624
$this->_controller->Crud->on('beforeSave', function ($event) {
602625
$event->stopPropagation();
603626
$event->getSubject()->success = true; // assert this
604627
});
605628

606-
$this->_controller->Blogs = $this->getMockForModel(
629+
$model = $this->getMockForModel(
607630
$this->tableClass,
608631
[],
609632
['alias' => 'Blogs', 'table' => 'blogs']
610633
);
634+
635+
$this->getTableLocator()->set('Blogs', $model);
611636
}
612637
);
613638

0 commit comments

Comments
 (0)