*/
public function implementedEvents(): array
{
diff --git a/src/TestSuite/IntegrationTestCase.php b/src/TestSuite/IntegrationTestCase.php
index 74c5a39c6..c94cd706d 100644
--- a/src/TestSuite/IntegrationTestCase.php
+++ b/src/TestSuite/IntegrationTestCase.php
@@ -49,7 +49,9 @@ public function setUp(): void
Router::extensions('json');
- Router::connect('/:controller', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
- Router::connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
+ $routeBuilder = Router::createRouteBuilder('/');
+
+ $routeBuilder->connect('/{controller}', ['action' => 'index'], ['routeClass' => 'DashedRoute']);
+ $routeBuilder->connect('/{controller}/{action}/*', [], ['routeClass' => 'DashedRoute']);
}
}
diff --git a/src/Traits/FindMethodTrait.php b/src/Traits/FindMethodTrait.php
index 6784054f6..0d7a7dcdb 100644
--- a/src/Traits/FindMethodTrait.php
+++ b/src/Traits/FindMethodTrait.php
@@ -61,7 +61,10 @@ protected function _findRecord(?string $id, Subject $subject): EntityInterface
[$finder, $options] = $this->_extractFinder();
$query = $repository->find($finder, $options);
- /** @psalm-suppress PossiblyInvalidArgument */
+ /**
+ * @psalm-suppress PossiblyInvalidArgument
+ * @psalm-suppress InvalidArrayOffset
+ */
$query->where([current($query->aliasField($repository->getPrimaryKey())) => $id]);
$subject->set([
diff --git a/src/Traits/SerializeTrait.php b/src/Traits/SerializeTrait.php
index 589a99950..97e2746e0 100644
--- a/src/Traits/SerializeTrait.php
+++ b/src/Traits/SerializeTrait.php
@@ -20,6 +20,6 @@ public function serialize(?array $keys = null)
return (array)$this->getConfig('serialize');
}
- return $this->setConfig('serialize', (array)$keys);
+ return $this->setConfig('serialize', $keys);
}
}
diff --git a/tests/TestCase/Action/AddActionTest.php b/tests/TestCase/Action/AddActionTest.php
index 2587b84fc..a34631d9f 100644
--- a/tests/TestCase/Action/AddActionTest.php
+++ b/tests/TestCase/Action/AddActionTest.php
@@ -4,6 +4,7 @@
namespace Crud\Test\TestCase\Action;
use Cake\Controller\Component\FlashComponent;
+use Cake\Core\Configure;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
@@ -239,16 +240,17 @@ function ($event) {
$this->_subscribeToEvents($this->_controller);
- $this->_controller->Blogs = $this->getMockForModel(
+ $blogs = $this->getMockForModel(
$this->tableClass,
['save'],
['alias' => 'Blogs', 'table' => 'blogs']
);
-
- $this->_controller->Blogs
+ $blogs
->expects($this->once())
->method('save')
->will($this->returnValue(false));
+
+ $this->getTableLocator()->set('Blogs', $blogs);
}
);
@@ -314,7 +316,11 @@ function ($event) {
$this->assertFalse($this->_subject->success);
$this->assertFalse($this->_subject->created);
- $expected = 'Name need to be at least 10 characters long
';
+ if (version_compare(Configure::version(), '4.3.0', '>=')) {
+ $expected = 'Name need to be at least 10 characters long
';
+ } else {
+ $expected = 'Name need to be at least 10 characters long
';
+ }
$this->assertStringContainsString(
$expected,
(string)$this->_response->getBody(),
@@ -344,10 +350,9 @@ public function apiGetHttpMethodProvider()
*/
public function testApiGet($method)
{
- Router::scope('/', function ($routes) {
- $routes->setExtensions(['json']);
- $routes->fallbacks();
- });
+ Router::createRouteBuilder('/')
+ ->setExtensions(['json'])
+ ->fallbacks();
$this->{$method}('/Blogs/add.json');
diff --git a/tests/TestCase/Action/BaseActionTest.php b/tests/TestCase/Action/BaseActionTest.php
index 5e2b961c2..0d680c8bc 100644
--- a/tests/TestCase/Action/BaseActionTest.php
+++ b/tests/TestCase/Action/BaseActionTest.php
@@ -46,9 +46,9 @@ public function setUp(): void
->addMethods(['foobar'])
->getMock();
$this->Controller->Crud = $this->Crud;
- $this->Controller->modelClass = 'CrudExamples';
- $this->Controller->CrudExamples = $this->getTableLocator()->get('Crud.CrudExamples');
- $this->Controller->CrudExamples->setAlias('MyModel');
+ $this->Controller->defaultTable = 'CrudExamples';
+
+ $this->getTableLocator()->get('CrudExamples')->setAlias('MyModel');
$this->actionClassName = $this->getMockBuilder(BaseAction::class)
->addMethods(['_handle'])
diff --git a/tests/TestCase/Action/DeleteActionTest.php b/tests/TestCase/Action/DeleteActionTest.php
index 743781cae..567d50901 100644
--- a/tests/TestCase/Action/DeleteActionTest.php
+++ b/tests/TestCase/Action/DeleteActionTest.php
@@ -70,16 +70,17 @@ function ($event) {
$this->_subscribeToEvents($this->_controller);
- $this->_controller->Blogs = $this->getMockForModel(
+ $blogs = $this->getMockForModel(
$this->tableClass,
['delete'],
['alias' => 'Blogs', 'table' => 'blogs']
);
-
- $this->_controller->Blogs
+ $blogs
->expects($this->once())
->method('delete')
->will($this->returnValue(true));
+
+ $this->getTableLocator()->set('Blogs', $blogs);
}
);
@@ -124,15 +125,16 @@ function ($event) {
$event->stopPropagation();
});
- $this->_controller->Blogs = $this->getMockForModel(
+ $blogs = $this->getMockForModel(
$this->tableClass,
['delete'],
['alias' => 'Blogs', 'table' => 'blogs']
);
-
- $this->_controller->Blogs
+ $blogs
->expects($this->never())
->method('delete');
+
+ $this->getTableLocator()->set('Blogs', $blogs);
}
);
@@ -178,16 +180,17 @@ function ($event) {
$event->stopPropagation();
});
- $this->_controller->Blogs = $this->getMockForModel(
+ $blogs = $this->getMockForModel(
$this->tableClass,
['delete'],
['alias' => 'Blogs', 'table' => 'blogs']
);
-
- $this->_controller->Blogs
+ $blogs
->expects($this->once())
->method('delete')
->will($this->returnValue(true));
+
+ $this->getTableLocator()->set('Blogs', $blogs);
}
);
diff --git a/tests/TestCase/Action/EditActionTest.php b/tests/TestCase/Action/EditActionTest.php
index 95bf9507f..cd80acd9e 100644
--- a/tests/TestCase/Action/EditActionTest.php
+++ b/tests/TestCase/Action/EditActionTest.php
@@ -4,6 +4,7 @@
namespace Crud\Test\TestCase\Action;
use Cake\Controller\Component\FlashComponent;
+use Cake\Core\Configure;
use Crud\TestSuite\IntegrationTestCase;
/**
@@ -167,16 +168,17 @@ function ($event) {
$this->_subscribeToEvents($this->_controller);
- $this->_controller->Blogs = $this->getMockForModel(
+ $blogs = $this->getMockForModel(
$this->tableClass,
['save'],
['alias' => 'Blogs', 'table' => 'blogs']
);
-
- $this->_controller->Blogs
+ $blogs
->expects($this->once())
->method('save')
->will($this->returnValue(false));
+
+ $this->getTableLocator()->set('Blogs', $blogs);
}
);
@@ -242,7 +244,11 @@ function ($event) {
$this->assertFalse($this->_subject->success);
$this->assertFalse($this->_subject->created);
- $expected = 'Name need to be at least 10 characters long
';
+ if (version_compare(Configure::version(), '4.3.0', '>=')) {
+ $expected = 'Name need to be at least 10 characters long
';
+ } else {
+ $expected = 'Name need to be at least 10 characters long
';
+ }
$this->assertStringContainsString(
$expected,
(string)$this->_response->getBody(),
diff --git a/tests/TestCase/Controller/Component/CrudComponentTest.php b/tests/TestCase/Controller/Component/CrudComponentTest.php
index 614f793fd..9e1f85b4e 100644
--- a/tests/TestCase/Controller/Component/CrudComponentTest.php
+++ b/tests/TestCase/Controller/Component/CrudComponentTest.php
@@ -57,6 +57,7 @@ public function setUp(): void
->onlyMethods(['redirect', 'render'])
->setConstructorArgs([$this->request, $response, 'CrudExamples', EventManager::instance()])
->getMock();
+ $this->controller->defaultTable = 'CrudExamples';
$this->Registry = $this->controller->components();
diff --git a/tests/TestCase/Error/ExceptionRendererTest.php b/tests/TestCase/Error/ExceptionRendererTest.php
index 8c79ee68d..f7a2eb1bd 100644
--- a/tests/TestCase/Error/ExceptionRendererTest.php
+++ b/tests/TestCase/Error/ExceptionRendererTest.php
@@ -63,6 +63,11 @@ public function testNormalExceptionRendering()
],
];
+ if (version_compare(Configure::version(), '4.2.0', '<')) {
+ $expected['exception']['class'] = 'Cake\Core\Exception\Exception';
+ $expected['exception']['code'] = 500;
+ }
+
$actual = $viewVars['data'];
unset($actual['trace'], $actual['file'], $actual['line']);
$this->assertEquals($expected, $actual);
@@ -139,6 +144,11 @@ public function testNormalExceptionRenderingQueryLog()
],
];
+ if (version_compare(Configure::version(), '4.2.0', '<')) {
+ $expected['exception']['class'] = 'Cake\Core\Exception\Exception';
+ $expected['exception']['code'] = 500;
+ }
+
$actual = $viewVars['data'];
$queryLog = $viewVars['queryLog'];
@@ -209,6 +219,11 @@ public function testNormalNestedExceptionRendering()
],
];
+ if (version_compare(Configure::version(), '4.2.0', '<')) {
+ $expected['exception']['class'] = 'Cake\Core\Exception\Exception';
+ $expected['exception']['code'] = 500;
+ }
+
$actual = $viewVars['data'];
unset($actual['trace'], $actual['file'], $actual['line']);
$this->assertEquals($expected, $actual);
@@ -269,6 +284,11 @@ public function testMissingViewExceptionDuringRendering()
],
];
+ if (version_compare(Configure::version(), '4.2.0', '<')) {
+ $expected['exception']['class'] = 'Cake\Core\Exception\Exception';
+ $expected['exception']['code'] = 500;
+ }
+
$actual = $viewVars['data'];
unset($actual['trace'], $actual['file'], $actual['line']);
$this->assertEquals($expected, $actual);
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index e83cbd630..d53343c50 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1,5 +1,6 @@
create(TMP . 'cache/models', 0777);
-$TMP->create(TMP . 'cache/persistent', 0777);
-$TMP->create(TMP . 'cache/views', 0777);
-
$cache = [
'default' => [
'engine' => 'File'
@@ -90,3 +86,8 @@
]);
Plugin::getCollection()->add(new \Crud\Plugin());
+
+Configure::write(
+ 'Error.ignoredDeprecationPaths',
+ ['vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php']
+);
diff --git a/tests/test_app/config/routes.php b/tests/test_app/config/routes.php
index 1e3361239..f92e7cbbb 100644
--- a/tests/test_app/config/routes.php
+++ b/tests/test_app/config/routes.php
@@ -1,11 +1,9 @@
scope('/', function ($routes) {
+ $routes->setExtensions(['json']);
-Router::scope('/', function ($routes) {
- $routes->extensions(['json']);
-
- $routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'InflectedRoute']);
- $routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);
+ $routes->connect('/{controller}', ['action' => 'index'], ['routeClass' => 'InflectedRoute']);
+ $routes->connect('/{controller}/{action}/*', [], ['routeClass' => 'InflectedRoute']);
});
diff --git a/tests/test_app/src/Model/Table/CrudExamplesTable.php b/tests/test_app/src/Model/Table/CrudExamplesTable.php
index 80db5f25f..5b45f5e0d 100644
--- a/tests/test_app/src/Model/Table/CrudExamplesTable.php
+++ b/tests/test_app/src/Model/Table/CrudExamplesTable.php
@@ -14,14 +14,7 @@
*/
class CrudExamplesTable extends Table
{
- public $alias = 'CrudExamples';
-
- public $findMethods = [
- 'published' => true,
- 'unpublished' => true,
- 'firstPublished' => true,
- 'firstUnpublished' => true,
- ];
+ protected $_alias = 'CrudExamples';
/**
* [initialize description]