Skip to content

Commit

Permalink
Merge pull request #715 from FriendsOfCake/maintainance
Browse files Browse the repository at this point in the history
Update deps and fix deprecations
  • Loading branch information
ADmad authored Sep 17, 2024
2 parents 751919c + 99c1289 commit 1472e01
Show file tree
Hide file tree
Showing 27 changed files with 330 additions and 245 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"require-dev": {
"friendsofcake/cakephp-test-utilities": "^3.0",
"friendsofcake/search": "^7.0",
"phpunit/phpunit": "^10.1"
"phpunit/phpunit": "^10.5.5 || ^11.1.3"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 2 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
parameters:
ignoreErrors:
-
identifier: missingType.iterableValue
-
message: "#^Call to an undefined method Crud\\\\Action\\\\BaseAction\\:\\:findMethod\\(\\)\\.$#"
count: 2
Expand All @@ -19,8 +21,3 @@ parameters:
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Crud\\.$#"
count: 1
path: src/Core/BaseObject.php

-
message: "#^Call to an undefined method Cake\\\\Controller\\\\Controller\\:\\:setViewClasses\\(\\)\\.$#"
count: 1
path: src/Listener/ApiListener.php
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ parameters:
level: 6
paths:
- src
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
excludePaths:
- */src/TestSuite/*
universalObjectCratesClasses:
- Crud\Event\Subject
bootstrapFiles:
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
5 changes: 0 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.x-dev@">
<file src="src/Listener/ApiListener.php">
<UndefinedMethod occurrences="1">
<code>setViewClasses</code>
</UndefinedMethod>
</file>
<file src="src/Listener/ApiQueryLogListener.php">
<InternalMethod occurrences="1">
<code>new QueryLogger()</code>
Expand Down
1 change: 1 addition & 0 deletions src/Controller/ControllerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public function invokeAction(Closure $action, array $args): void
*
* @param array<string, class-string<\Cake\View\View>> $map View class map.
* @return void
* @deprecated 7.1.0 Use addViewClasses() instead.
*/
public function setViewClasses(array $map): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/BaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function implementedEvents(): array
/**
* Convenient method for Request::is
*
* @param array|string $method Method(s) to check for
* @param list<string>|string $method Method(s) to check for
* @return bool
*/
protected function _checkRequestType(array|string $method): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/ApiListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ protected function _expandPath(Subject $subject, string $path): string
*/
public function injectViewClasses(): void
{
$this->_controller()->setViewClasses($this->getConfig('viewClasses'));
$this->_controller()->addViewClasses($this->getConfig('viewClasses'));
}

/**
Expand Down
79 changes: 52 additions & 27 deletions tests/TestCase/Action/AddActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cake\Core\Configure;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
* Licensed under The MIT License
Expand Down Expand Up @@ -87,12 +88,12 @@ public function testActionPost()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -104,6 +105,8 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);
}
);
Expand Down Expand Up @@ -132,12 +135,12 @@ public function testActionPostWithAddRedirect()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -149,6 +152,8 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);
}
);
Expand Down Expand Up @@ -177,12 +182,12 @@ public function testActionPostWithEditRedirect()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -194,6 +199,8 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);
}
);
Expand Down Expand Up @@ -221,12 +228,12 @@ public function testActionPostErrorSave()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -238,6 +245,8 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

$blogs = $this->getMockForModel(
Expand All @@ -248,7 +257,7 @@ function ($event) {
$blogs
->expects($this->once())
->method('save')
->will($this->returnValue(false));
->willReturn(false);

$this->getTableLocator()->set('Blogs', $blogs);
}
Expand All @@ -275,12 +284,12 @@ public function testActionPostValidationErrors()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -292,6 +301,8 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

$this->_controller->Blogs
Expand Down Expand Up @@ -344,10 +355,10 @@ public static function apiGetHttpMethodProvider()
/**
* Test HTTP & DELETE verbs using API Listener
*
* @dataProvider apiGetHttpMethodProvider
* @param string $method
* @return void
*/
#[DataProvider('apiGetHttpMethodProvider')]
public function testApiGet($method)
{
Router::createRouteBuilder('/')
Expand Down Expand Up @@ -376,25 +387,27 @@ public static function apiUpdateHttpMethodProvider()
/**
* Test POST & PUT verbs using API Listener
*
* @dataProvider apiUpdateHttpMethodProvider
* @param string $method
* @return void
*/
#[DataProvider('apiUpdateHttpMethodProvider')]
public function testApiCreate($method)
{
$this->_eventManager->on(
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->never())
->method('set');

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

$this->_controller->Crud->addListener('api', 'Crud.Api');
Expand All @@ -417,10 +430,10 @@ function ($event) {
* Test POST & PUT verbs using API Listener
* with data validation error
*
* @dataProvider apiUpdateHttpMethodProvider
* @param string $method
* @return void
*/
#[DataProvider('apiUpdateHttpMethodProvider')]
public function testApiCreateError($method)
{
$this->_eventManager->on(
Expand All @@ -431,15 +444,17 @@ function ($event) {
return;
}

$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->never())
->method('set');

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

$this->_controller->Crud->addListener('api', 'Crud.Api');
Expand Down Expand Up @@ -469,10 +484,10 @@ function ($event) {
* Test POST & PUT verbs using API Listener
* with data validation errors
*
* @dataProvider apiUpdateHttpMethodProvider
* @param string $method
* @return void
*/
#[DataProvider('apiUpdateHttpMethodProvider')]
public function testApiCreateErrors($method)
{
$this->_eventManager->on(
Expand All @@ -483,15 +498,17 @@ function ($event) {
return;
}

$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->never())
->method('set');

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

$this->_controller->Crud->addListener('api', 'Crud.Api');
Expand Down Expand Up @@ -529,12 +546,12 @@ public function testStopAddWithDefaultSubjectSuccess()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -546,17 +563,21 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

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

$this->_controller->Blogs = $this->getMockForModel(
$model = $this->getMockForModel(
$this->tableClass,
[],
['alias' => 'Blogs', 'table' => 'blogs']
);

$this->getTableLocator()->set('Blogs', $model);
}
);

Expand All @@ -579,12 +600,12 @@ public function testStopAddWithManuallySetSubjectSuccess()
'Controller.initialize',
['priority' => 11],
function ($event) {
$this->_controller->Flash = $this->getMockBuilder(FlashComponent::class)
$component = $this->getMockBuilder(FlashComponent::class)
->onlyMethods(['set'])
->setConstructorArgs([$this->_controller->components()])
->getMock();

$this->_controller->Flash
$component
->expects($this->once())
->method('set')
->with(
Expand All @@ -596,18 +617,22 @@ function ($event) {
]
);

$this->_controller->components()->set('Flash', $component);

$this->_subscribeToEvents($this->_controller);

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

$this->_controller->Blogs = $this->getMockForModel(
$model = $this->getMockForModel(
$this->tableClass,
[],
['alias' => 'Blogs', 'table' => 'blogs']
);

$this->getTableLocator()->set('Blogs', $model);
}
);

Expand Down
Loading

0 comments on commit 1472e01

Please sign in to comment.