From 49bbc21e1df15ee5ca21dd8ec3623994fe210e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgaras=20Janu=C5=A1auskas?= Date: Thu, 5 Dec 2019 12:52:16 +0200 Subject: [PATCH] Fix failures on PHP 7.4. Run phpcs on PHP 7.0 --- .travis.yml | 10 ++--- lib/Cake/Console/ShellDispatcher.php | 2 +- lib/Cake/Model/Datasource/Database/Sqlite.php | 1 - lib/Cake/Model/Model.php | 4 +- lib/Cake/Test/Case/Cache/CacheTest.php | 8 +++- .../Model/Datasource/Database/MysqlTest.php | 37 +------------------ .../Test/Case/View/Helper/FormHelperTest.php | 2 +- .../Test/Case/View/Helper/RssHelperTest.php | 6 ++- lib/Cake/Test/Case/View/ViewTest.php | 32 ++++++++++------ 9 files changed, 40 insertions(+), 62 deletions(-) diff --git a/.travis.yml b/.travis.yml index a970ba3a5..b2656b9dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: php +os: linux dist: xenial php: @@ -8,7 +9,7 @@ php: - 7.4 env: - matrix: + jobs: - DB=mysql global: - PHPUNIT=5.7.19 @@ -19,7 +20,7 @@ services: - postgresql - mysql -matrix: +jobs: fast_finish: true include: - php: 5.3 @@ -41,12 +42,9 @@ matrix: - php: 7.3 env: DB=sqlite - - php: 7.2 + - php: 7.0 env: PHPCS=1 - allow_failures: - - php: 7.4 - before_script: - if [[ ${TRAVIS_PHP_VERSION:0:3} =~ ^7\.[234]$ ]] ; then pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; fi - composer require "phpunit/phpunit=$PHPUNIT" diff --git a/lib/Cake/Console/ShellDispatcher.php b/lib/Cake/Console/ShellDispatcher.php index 5249008ea..22a4e53f7 100644 --- a/lib/Cake/Console/ShellDispatcher.php +++ b/lib/Cake/Console/ShellDispatcher.php @@ -223,7 +223,7 @@ class ShellDispatcher { } $methods = array_diff(get_class_methods($Shell), get_class_methods('Shell')); $added = in_array($command, $methods); - $private = $command[0] === '_' && method_exists($Shell, $command); + $private = substr($command, 0, 1) === '_' && method_exists($Shell, $command); if (!$private) { if ($added) { diff --git a/lib/Cake/Model/Datasource/Database/Sqlite.php b/lib/Cake/Model/Datasource/Database/Sqlite.php index 749d73b9a..487868be4 100644 --- a/lib/Cake/Model/Datasource/Database/Sqlite.php +++ b/lib/Cake/Model/Datasource/Database/Sqlite.php @@ -179,7 +179,6 @@ class Sqlite extends DboSource { ); foreach ($result as $column) { - $column = (array)$column; $default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'"); $fields[$column['name']] = array( diff --git a/lib/Cake/Model/Model.php b/lib/Cake/Model/Model.php index 6f14d785a..860ad5bdf 100644 --- a/lib/Cake/Model/Model.php +++ b/lib/Cake/Model/Model.php @@ -1358,7 +1358,7 @@ class Model extends CakeObject implements CakeEventListener { } } - if (!isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) || $data[$val][0] === '-')) { + if (!isset($data[$val]) || isset($data[$val]) && (empty($data[$val]) || substr($data[$val], 0, 1) === '-')) { return null; } @@ -1991,7 +1991,7 @@ class Model extends CakeObject implements CakeEventListener { */ protected function _isUUIDField($field) { $field = $this->schema($field); - return $field['length'] == 36 && in_array($field['type'], array('string', 'binary', 'uuid')); + return $field !== null && $field['length'] == 36 && in_array($field['type'], array('string', 'binary', 'uuid')); } /** diff --git a/lib/Cake/Test/Case/Cache/CacheTest.php b/lib/Cake/Test/Case/Cache/CacheTest.php index 5a36aeef7..0dfd60209 100644 --- a/lib/Cake/Test/Case/Cache/CacheTest.php +++ b/lib/Cake/Test/Case/Cache/CacheTest.php @@ -189,8 +189,12 @@ class CacheTest extends CakeTestCase { $result = Cache::config('tests', array('engine' => 'File', 'path' => TMP . 'tests')); $this->assertEquals(Cache::settings('tests'), $result['settings']); - Cache::config('sessions', $_cacheConfigSessions['settings']); - Cache::config('tests', $_cacheConfigTests['settings']); + if ($_cacheConfigSessions !== false) { + Cache::config('sessions', $_cacheConfigSessions['settings']); + } + if ($_cacheConfigTests !== false) { + Cache::config('tests', $_cacheConfigTests['settings']); + } } /** diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index cc2cce668..f569d3627 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -356,41 +356,6 @@ class MysqlTest extends CakeTestCase { $this->assertEquals($expected, $result); } -/** - * testBuildColumn method - * - * @return void - */ - public function testBuildColumn() { - $restore = $this->Dbo->columns; - $this->Dbo->columns = array('varchar(255)' => 1); - $data = array( - 'name' => 'testName', - 'type' => 'varchar(255)', - 'default', - 'null' => true, - 'key', - 'comment' => 'test' - ); - $result = $this->Dbo->buildColumn($data); - $expected = '`testName` DEFAULT NULL COMMENT \'test\''; - $this->assertEquals($expected, $result); - - $data = array( - 'name' => 'testName', - 'type' => 'varchar(255)', - 'default', - 'null' => true, - 'key', - 'charset' => 'utf8', - 'collate' => 'utf8_unicode_ci' - ); - $result = $this->Dbo->buildColumn($data); - $expected = '`testName` CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL'; - $this->assertEquals($expected, $result); - $this->Dbo->columns = $restore; - } - /** * MySQL 4.x returns index data in a different format, * Using a mock ensure that MySQL 4.x output is properly parsed. @@ -3166,7 +3131,7 @@ SQL; * * @return void */ - public function testBuildColumn2() { + public function testBuildColumn() { $data = array( 'name' => 'testName', 'type' => 'string', diff --git a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php index 4aa6c66fb..eab4b0bd5 100644 --- a/lib/Cake/Test/Case/View/Helper/FormHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/FormHelperTest.php @@ -7975,7 +7975,7 @@ class FormHelperTest extends CakeTestCase { ); $this->assertTags($result, $expected); - $this->request->data['Contact']['published'] = ''; + $this->Form->request->data['Contact']['published'] = ''; $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year')); $expected = array( array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')), diff --git a/lib/Cake/Test/Case/View/Helper/RssHelperTest.php b/lib/Cake/Test/Case/View/Helper/RssHelperTest.php index d6606a7e3..0deae0d90 100644 --- a/lib/Cake/Test/Case/View/Helper/RssHelperTest.php +++ b/lib/Cake/Test/Case/View/Helper/RssHelperTest.php @@ -245,7 +245,11 @@ class RssHelperTest extends CakeTestCase { array('title' => 'title3', 'guid' => 'http://www.example.com/guid3', 'link' => 'http://www.example.com/link3', 'description' => 'description3') ); - $result = $this->Rss->items($items, create_function('$v', '$v[\'title\'] = $v[\'title\'] . \'-transformed\'; return $v;')); + $result = $this->Rss->items($items, function ($v) { + $v['title'] = $v['title'] . '-transformed'; + + return $v; + }); $expected = array( '_checkException( + 'Object of class TestObjectWithoutToString could not be converted to string' + ); + $objectWithToString = new TestObjectWithoutToString(); $this->View->assign('testWithObjectWithoutToString', $objectWithToString); } @@ -1547,13 +1547,13 @@ class ViewTest extends CakeTestCase { /** * Test appending an object without __toString magic method to a block with append. * - * This should produce a "Object of class TestObjectWithoutToString could not be converted to string" error - * which gets thrown as a PHPUnit_Framework_Error Exception by PHPUnit. - * - * @expectedException PHPUnit_Framework_Error * @return void */ public function testBlockAppendObjectWithoutToString() { + $this->_checkException( + 'Object of class TestObjectWithoutToString could not be converted to string' + ); + $object = new TestObjectWithoutToString(); $this->View->assign('testBlock', 'Block '); $this->View->append('testBlock', $object); @@ -1576,13 +1576,13 @@ class ViewTest extends CakeTestCase { /** * Test prepending an object without __toString magic method to a block with prepend. * - * This should produce a "Object of class TestObjectWithoutToString could not be converted to string" error - * which gets thrown as a PHPUnit_Framework_Error Exception by PHPUnit. - * - * @expectedException PHPUnit_Framework_Error * @return void */ public function testBlockPrependObjectWithoutToString() { + $this->_checkException( + 'Object of class TestObjectWithoutToString could not be converted to string' + ); + $object = new TestObjectWithoutToString(); $this->View->assign('test', 'Block '); $this->View->prepend('test', $object); @@ -1839,4 +1839,12 @@ TEXT; $result = $this->View->get('title', $default); $this->assertEquals($expected, $result); } + + protected function _checkException($message) { + if (version_compare(PHP_VERSION, '7.4', '>=')) { + $this->setExpectedException('Error', $message); + } else { + $this->setExpectedException('PHPUnit_Framework_Error', $message); + } + } }