From 6f025425944b2e4378e116a20bec63920bf7db99 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 28 Jan 2026 19:23:59 +0100 Subject: [PATCH 1/3] Fix CakePHP 5.3 deprecation warnings in tests - Replace _execute() with process() in test form class - Use getBehavior('Search')->searchManager() instead of table proxy - Use getBehavior('Search')->isSearch() instead of table proxy --- tests/TestApp/Model/Table/CommentsTable.php | 2 +- tests/TestApp/Model/Table/SectionsTable.php | 2 +- .../Controller/Component/SearchComponentTest.php | 2 +- tests/TestCase/Model/Behavior/SearchBehaviorTest.php | 12 ++++++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/TestApp/Model/Table/CommentsTable.php b/tests/TestApp/Model/Table/CommentsTable.php index f41cd15b..6f5a2529 100644 --- a/tests/TestApp/Model/Table/CommentsTable.php +++ b/tests/TestApp/Model/Table/CommentsTable.php @@ -14,7 +14,7 @@ public function initialize(array $config): void { $this->addBehavior('Search.Search'); - $this->searchManager() + $this->getBehavior('Search')->searchManager() ->value('Comments.foo') ->like('Comments.search', ['filterEmpty' => true, 'multiValue' => true]) ->value('Comments.baz') diff --git a/tests/TestApp/Model/Table/SectionsTable.php b/tests/TestApp/Model/Table/SectionsTable.php index c94649e9..64133339 100644 --- a/tests/TestApp/Model/Table/SectionsTable.php +++ b/tests/TestApp/Model/Table/SectionsTable.php @@ -14,7 +14,7 @@ public function initialize(array $config): void { $this->addBehavior('Search.Search'); - $this->searchManager() + $this->getBehavior('Search')->searchManager() ->useCollection('frontend') ->value('title') ->useCollection('backend') diff --git a/tests/TestCase/Controller/Component/SearchComponentTest.php b/tests/TestCase/Controller/Component/SearchComponentTest.php index 91382c70..cefcd87a 100644 --- a/tests/TestCase/Controller/Component/SearchComponentTest.php +++ b/tests/TestCase/Controller/Component/SearchComponentTest.php @@ -418,7 +418,7 @@ public function testPostFormValidationSuccess(): void { public static $called = false; - protected function _execute(array $data = []): bool + protected function process(array $data = []): bool { static::$called = true; diff --git a/tests/TestCase/Model/Behavior/SearchBehaviorTest.php b/tests/TestCase/Model/Behavior/SearchBehaviorTest.php index 498d43f6..5efe8c78 100644 --- a/tests/TestCase/Model/Behavior/SearchBehaviorTest.php +++ b/tests/TestCase/Model/Behavior/SearchBehaviorTest.php @@ -182,7 +182,7 @@ public function testFinder() 'search' => 'b', 'group' => 'main', ]; - $this->assertFalse($this->Articles->isSearch()); + $this->assertFalse($this->Articles->getBehavior('Search')->isSearch()); $query = $this->Articles->find('search', search: $queryString); $this->assertEquals(3, $query->clause('where')->count()); @@ -204,7 +204,7 @@ public function testFinder() ], ); $this->assertEquals(2, $query->clause('where')->count()); - $this->assertTrue($this->Articles->isSearch()); + $this->assertTrue($this->Articles->getBehavior('Search')->isSearch()); } /** @@ -227,7 +227,7 @@ public function testEmptyValues() $this->Articles->addBehavior('Search.Search', [ 'emptyValues' => ['a'], ]); - $this->Articles->searchManager() + $this->Articles->getBehavior('Search')->searchManager() ->value('foo') ->like('search') ->value('baz') @@ -239,7 +239,7 @@ public function testEmptyValues() $this->Articles->addBehavior('Search.Search', [ 'emptyValues' => ['a', '0'], ]); - $this->Articles->searchManager() + $this->Articles->getBehavior('Search')->searchManager() ->value('foo') ->like('search') ->value('baz') @@ -315,14 +315,14 @@ public static function collectionFinderProvider() */ public function testSearchManager() { - $manager = $this->Articles->searchManager(); + $manager = $this->Articles->getBehavior('Search')->searchManager(); $this->assertInstanceOf('\Search\Manager', $manager); } public function testExtraParams(): void { $result = []; - $manager = $this->Articles->searchManager(); + $manager = $this->Articles->getBehavior('Search')->searchManager(); $manager->callback('field1', [ 'callback' => function (SelectQuery $query, array $args) use (&$result) { $result = $args; From 0af1957fc3091890df104b7bd810930f631f1174 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 28 Jan 2026 19:28:45 +0100 Subject: [PATCH 2/3] Support both _execute() and process() for CakePHP 5.0-5.3 compat --- .../TestCase/Controller/Component/SearchComponentTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/TestCase/Controller/Component/SearchComponentTest.php b/tests/TestCase/Controller/Component/SearchComponentTest.php index cefcd87a..9b268a3e 100644 --- a/tests/TestCase/Controller/Component/SearchComponentTest.php +++ b/tests/TestCase/Controller/Component/SearchComponentTest.php @@ -418,6 +418,13 @@ public function testPostFormValidationSuccess(): void { public static $called = false; + protected function _execute(array $data = []): bool + { + static::$called = true; + + return true; + } + protected function process(array $data = []): bool { static::$called = true; From ddc132b582c79ce1c7ac97854cd48ba01baa4379 Mon Sep 17 00:00:00 2001 From: mscherer Date: Wed, 28 Jan 2026 19:32:03 +0100 Subject: [PATCH 3/3] Use version-aware form method override for CakePHP 5.0-5.3 compat --- .../Component/SearchComponentTest.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/TestCase/Controller/Component/SearchComponentTest.php b/tests/TestCase/Controller/Component/SearchComponentTest.php index 9b268a3e..70c27a24 100644 --- a/tests/TestCase/Controller/Component/SearchComponentTest.php +++ b/tests/TestCase/Controller/Component/SearchComponentTest.php @@ -424,14 +424,22 @@ protected function _execute(array $data = []): bool return true; } + }; - protected function process(array $data = []): bool + // CakePHP 5.3+ uses process() instead of _execute() + if (method_exists(SearchForm::class, 'process')) { + $mock = new class extends SearchForm { - static::$called = true; + public static $called = false; - return true; - } - }; + protected function process(array $data = []): bool + { + static::$called = true; + + return true; + } + }; + } $this->Search->setConfig('formClass', $mock::class);