Skip to content

Commit b427932

Browse files
committed
Fix CakePHP 4.x deprecations.
- TestListenerTrait is used by Cake\TestSuite\Fixture\FixtureInjector; but - It's removed in CakePHP 5.0.0 and will no longer throw deprecations.
1 parent c2b8fdd commit b427932

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/Error/JsonApiExceptionRenderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use Cake\Controller\Controller;
77
use Cake\Core\Configure;
8-
use Cake\Core\Exception\Exception;
8+
use Cake\Core\Exception\CakeException;
99
use Cake\Error\Debugger;
1010
use Cake\Http\Response;
1111
use Cake\Utility\Inflector;
@@ -193,7 +193,7 @@ protected function _addDebugNode(string $json): string
193193

194194
try {
195195
return (string)json_encode($result, JSON_PRETTY_PRINT);
196-
} catch (Exception $e) {
196+
} catch (CakeException $e) {
197197
$result['debug']['message'] = $e->getMessage();
198198
$result['debug']['trace'] = [
199199
'error' => 'Unable to encode stack trace',

src/Listener/JsonApiListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ protected function _renderWithIdentifiers(Subject $subject): Response
881881
*/
882882
protected function _renderWithResources(Subject $subject): Response
883883
{
884-
$repository = $this->_controller()->loadModel(); // Default model class
884+
$repository = $this->_controller()->fetchModel(); // Default model class
885885

886886
$usedAssociations = [];
887887
if (isset($subject->query)) {

tests/TestCase/Error/JsonApiExceptionRendererTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use Cake\Controller\Controller;
77
use Cake\Core\Configure;
8-
use Cake\Core\Exception\Exception;
8+
use Cake\Core\Exception\CakeException;
99
use Cake\Core\Plugin;
1010
use Cake\Http\Response;
1111
use Cake\Http\ServerRequest;
@@ -52,7 +52,7 @@ public function setUp(): void
5252
*/
5353
public function testRenderWithNonValidationError()
5454
{
55-
$exception = new Exception('Hello World');
55+
$exception = new CakeException('Hello World');
5656

5757
$controller = $this->getMockBuilder(Controller::class)
5858
->onlyMethods(['render'])
@@ -179,7 +179,7 @@ public function testValidationExceptionsFallBackToStatusCode422()
179179

180180
// First call should throw an exception.
181181
if ($callCount === 1) {
182-
throw new Exception('woot');
182+
throw new CakeException('woot');
183183
}
184184

185185
// Second call should succeed and return response with status.

tests/TestCase/View/JsonApiViewTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ protected function _getView(?string $tableName, array $viewVars = [], array $opt
147147

148148
// still here, create view with viewVars for response with resource(s)
149149
$controller->setName($tableName); // e.g. Countries
150-
$table = $controller->loadModel(); // table object
150+
$table = $controller->fetchModel(); // table object
151151

152152
// fetch data from test viewVar normally found in subject
153153
$subject = new Subject(['event' => new Event('Crud.beforeHandle')]);
@@ -157,7 +157,7 @@ protected function _getView(?string $tableName, array $viewVars = [], array $opt
157157
} else {
158158
$subject->entity = $findResult;
159159
}
160-
$subject->query = $table->query();
160+
$subject->query = $table->selectQuery();
161161

162162
// create required '_entities' and '_associations' viewVars normally
163163
// produced and set by the JsonApiListener

0 commit comments

Comments
 (0)