Skip to content

Commit

Permalink
Merge pull request #609 from FriendsOfCake/cake-37
Browse files Browse the repository at this point in the history
Fix deprecation errors on Cake 3.7.
  • Loading branch information
ADmad committed Dec 9, 2018
2 parents 052b162 + 85b66ad commit f33e649
Show file tree
Hide file tree
Showing 20 changed files with 115 additions and 29 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"cakephp/cakephp": "^3.5"
},
"require-dev": {
"cakephp/chronos": "^1.1",
"phpunit/phpunit": "^5.7.14|^6.0",
"friendsofcake/cakephp-test-utilities": "^1.0",
"friendsofcake/search": "^4.4",
Expand Down
11 changes: 9 additions & 2 deletions src/Listener/ApiQueryLogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,15 @@ public function setupLogging(Event $event)
{
foreach ($this->_getSources() as $connectionName) {
try {
$this->_getSource($connectionName)->logQueries(true);
$this->_getSource($connectionName)->setLogger(new QueryLogger());
$connection = $this->_getSource($connectionName);

if (method_exists($connection, 'enableQueryLogging')) {
$connection->enableQueryLogging(true);
} else {
$connection->logQueries(true);
}

$connection->setLogger(new QueryLogger());
} catch (MissingDatasourceConfigException $e) {
//Safe to ignore this :-)
}
Expand Down
17 changes: 17 additions & 0 deletions src/TestSuite/IntegrationTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,21 @@ public function setUp()
Router::connect('/:controller/:action/*', [], ['routeClass' => 'DashedRoute']);
$this->useHttpServer(false);
}

/**
* Helper method for check deprecation methods
*
* @param callable $callable callable function that will receive asserts
* @return void
*/
public function deprecated($callable)
{
$errorLevel = error_reporting();
error_reporting(E_ALL ^ E_USER_DEPRECATED);
try {
$callable();
} finally {
error_reporting($errorLevel);
}
}
}
17 changes: 17 additions & 0 deletions src/TestSuite/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,21 @@ public function setUp()
parent::setUp();
$this->resetReflectionCache();
}

/**
* Helper method for check deprecation methods
*
* @param callable $callable callable function that will receive asserts
* @return void
*/
public function deprecated($callable)
{
$errorLevel = error_reporting();
error_reporting(E_ALL ^ E_USER_DEPRECATED);
try {
$callable();
} finally {
error_reporting($errorLevel);
}
}
}
7 changes: 6 additions & 1 deletion tests/TestCase/Action/AddActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -17,7 +18,7 @@ class AddActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* Table class to mock on
Expand All @@ -33,6 +34,10 @@ class AddActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
5 changes: 5 additions & 0 deletions tests/TestCase/Action/BaseActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Http\Exception\BadRequestException;
use Cake\Http\Exception\MethodNotAllowedException;
use Cake\Http\Exception\NotFoundException;
Expand All @@ -19,6 +20,10 @@ class BaseActionTest extends TestCase

public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->Request = $this->getMockBuilder(ServerRequest::class)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Action/Bulk/DeleteActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class DeleteActionTest extends IntegrationTestCase
* @var array
*/
public $fixtures = [
'plugin.crud.blogs',
'plugin.crud.users'
'plugin.Crud.Blogs',
'plugin.Crud.Users'
];

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Action/Bulk/SetValueActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class SetValueActionTest extends IntegrationTestCase
* @var array
*/
public $fixtures = [
'plugin.crud.blogs',
'plugin.crud.users'
'plugin.Crud.Blogs',
'plugin.Crud.Users',
];

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Action/Bulk/ToggleActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ToggleActionTest extends IntegrationTestCase
* @var array
*/
public $fixtures = [
'plugin.crud.blogs',
'plugin.crud.users'
'plugin.Crud.Blogs',
'plugin.Crud.Users'
];

/**
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Action/DeleteActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -17,7 +18,7 @@ class DeleteActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* Table class to mock on
Expand All @@ -33,6 +34,10 @@ class DeleteActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Action/EditActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -17,7 +18,7 @@ class EditActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* Table class to mock on
Expand All @@ -33,6 +34,10 @@ class EditActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Action/IndexActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -18,7 +19,7 @@ class IndexActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* setUp()
Expand All @@ -27,6 +28,10 @@ class IndexActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Action/LookupActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -18,7 +19,7 @@ class LookupActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* setUp()
Expand All @@ -27,6 +28,10 @@ class LookupActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
7 changes: 6 additions & 1 deletion tests/TestCase/Action/ViewActionTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Crud\Test\TestCase\Action;

use Cake\Core\Plugin;
use Cake\Routing\DispatcherFactory;
use Cake\Routing\Router;
use Crud\TestSuite\IntegrationTestCase;
Expand All @@ -18,7 +19,7 @@ class ViewActionTest extends IntegrationTestCase
*
* @var array
*/
public $fixtures = ['plugin.crud.blogs'];
public $fixtures = ['plugin.Crud.Blogs'];

/**
* setUp()
Expand All @@ -27,6 +28,10 @@ class ViewActionTest extends IntegrationTestCase
*/
public function setUp()
{
$this->deprecated(function () {
Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);
});

parent::setUp();

$this->useHttpServer(true);
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/ActionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public static function suite()
{
$suite = new TestSuite('All CRUD action tests');

$path = Plugin::path('Crud');
$testPath = $path . '/tests/TestCase';
$testPath = ROOT . '/tests/TestCase';
if (!is_dir($testPath)) {
return $suite;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/AllTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public static function suite()
{
$suite = new TestSuite('All Crud plugin tests');

$path = Plugin::path('Crud');
$testPath = $path . DS . 'tests' . DS . 'TestCase';
$testPath = ROOT . DS . 'tests' . DS . 'TestCase';
if (!is_dir($testPath)) {
return $suite;
}
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase/Listener/ApiQueryLogListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,19 @@ public function testBeforeRenderDebugTrue()
*/
public function testSetupLogging()
{
$methodName = 'enableQueryLogging';
if (version_compare(Configure::version(), '3.7.0RC', '<')) {
$methodName = 'logQueries';
}

$DefaultSource = $this
->getMockBuilder('\Cake\Database\Connection')
->disableOriginalConstructor()
->setMethods(['logQueries', 'setLogger'])
->setMethods([$methodName, 'setLogger'])
->getMock();
$DefaultSource
->expects($this->once())
->method('logQueries')
->method($methodName)
->with(true);
$DefaultSource
->expects($this->once())
Expand Down
19 changes: 14 additions & 5 deletions tests/TestCase/Listener/SearchListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class SearchListenerTest extends TestCase
{
public function tearDown()
{
Plugin::unload('Search');
$this->deprecated(function () {
Plugin::unload('Search');
});

TableRegistry::clear();
}

Expand Down Expand Up @@ -54,7 +57,9 @@ public function testImplementedEvents()
*/
public function testInjectSearchException()
{
Plugin::load('Search', ['path' => ROOT . DS]);
$this->deprecated(function () {
Plugin::load('Search', ['path' => ROOT . DS]);
});

$request = new ServerRequest();
$response = new Response();
Expand Down Expand Up @@ -101,7 +106,9 @@ public function testInjectSearchException()
*/
public function testInjectSearch()
{
Plugin::load('Search', ['path' => ROOT . DS]);
$this->deprecated(function () {
Plugin::load('Search', ['path' => ROOT . DS]);
});

$params = [
'search' => [
Expand Down Expand Up @@ -166,8 +173,10 @@ public function testInjectSearch()
*/
public function testInjectSearchWebserviceEndpoint()
{
Plugin::load('Search', ['path' => ROOT . DS]);
Plugin::load('Muffin/Webservice', ['path' => ROOT . '/vendor/muffin/webservice/']);
$this->deprecated(function () {
Plugin::load('Search', ['path' => ROOT . DS]);
Plugin::load('Muffin/Webservice', ['path' => ROOT . '/vendor/muffin/webservice/']);
});

$params = [
'search' => [
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/ListenersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ public static function suite()
{
$suite = new TestSuite('All CRUD listener tests');

$path = Plugin::path('Crud');
$testPath = $path . DS . 'tests' . DS . 'TestCase';
$testPath = ROOT . DS . 'tests' . DS . 'TestCase';
if (!is_dir($testPath)) {
return $suite;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@
'defaults' => 'php'
]);

Cake\Core\Plugin::load('Crud', ['path' => ROOT . DS, 'autoload' => true]);

// Ensure default test connection is defined
if (!getenv('db_dsn')) {
putenv('db_dsn=sqlite:///:memory:');
Expand Down

0 comments on commit f33e649

Please sign in to comment.