Fix failures on PHP 7.4. Run phpcs on PHP 7.0

This commit is contained in:
Edgaras Janušauskas 2019-12-05 12:52:16 +02:00
parent b56ea15eba
commit 49bbc21e1d
9 changed files with 40 additions and 62 deletions

View file

@ -1,5 +1,6 @@
language: php language: php
os: linux
dist: xenial dist: xenial
php: php:
@ -8,7 +9,7 @@ php:
- 7.4 - 7.4
env: env:
matrix: jobs:
- DB=mysql - DB=mysql
global: global:
- PHPUNIT=5.7.19 - PHPUNIT=5.7.19
@ -19,7 +20,7 @@ services:
- postgresql - postgresql
- mysql - mysql
matrix: jobs:
fast_finish: true fast_finish: true
include: include:
- php: 5.3 - php: 5.3
@ -41,12 +42,9 @@ matrix:
- php: 7.3 - php: 7.3
env: DB=sqlite env: DB=sqlite
- php: 7.2 - php: 7.0
env: PHPCS=1 env: PHPCS=1
allow_failures:
- php: 7.4
before_script: before_script:
- if [[ ${TRAVIS_PHP_VERSION:0:3} =~ ^7\.[234]$ ]] ; then pear config-set preferred_state snapshot && yes "" | pecl install mcrypt ; fi - 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" - composer require "phpunit/phpunit=$PHPUNIT"

View file

@ -223,7 +223,7 @@ class ShellDispatcher {
} }
$methods = array_diff(get_class_methods($Shell), get_class_methods('Shell')); $methods = array_diff(get_class_methods($Shell), get_class_methods('Shell'));
$added = in_array($command, $methods); $added = in_array($command, $methods);
$private = $command[0] === '_' && method_exists($Shell, $command); $private = substr($command, 0, 1) === '_' && method_exists($Shell, $command);
if (!$private) { if (!$private) {
if ($added) { if ($added) {

View file

@ -179,7 +179,6 @@ class Sqlite extends DboSource {
); );
foreach ($result as $column) { foreach ($result as $column) {
$column = (array)$column;
$default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'"); $default = ($column['dflt_value'] === 'NULL') ? null : trim($column['dflt_value'], "'");
$fields[$column['name']] = array( $fields[$column['name']] = array(

View file

@ -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; return null;
} }
@ -1991,7 +1991,7 @@ class Model extends CakeObject implements CakeEventListener {
*/ */
protected function _isUUIDField($field) { protected function _isUUIDField($field) {
$field = $this->schema($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'));
} }
/** /**

View file

@ -189,8 +189,12 @@ class CacheTest extends CakeTestCase {
$result = Cache::config('tests', array('engine' => 'File', 'path' => TMP . 'tests')); $result = Cache::config('tests', array('engine' => 'File', 'path' => TMP . 'tests'));
$this->assertEquals(Cache::settings('tests'), $result['settings']); $this->assertEquals(Cache::settings('tests'), $result['settings']);
Cache::config('sessions', $_cacheConfigSessions['settings']); if ($_cacheConfigSessions !== false) {
Cache::config('tests', $_cacheConfigTests['settings']); Cache::config('sessions', $_cacheConfigSessions['settings']);
}
if ($_cacheConfigTests !== false) {
Cache::config('tests', $_cacheConfigTests['settings']);
}
} }
/** /**

View file

@ -356,41 +356,6 @@ class MysqlTest extends CakeTestCase {
$this->assertEquals($expected, $result); $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, * MySQL 4.x returns index data in a different format,
* Using a mock ensure that MySQL 4.x output is properly parsed. * Using a mock ensure that MySQL 4.x output is properly parsed.
@ -3166,7 +3131,7 @@ SQL;
* *
* @return void * @return void
*/ */
public function testBuildColumn2() { public function testBuildColumn() {
$data = array( $data = array(
'name' => 'testName', 'name' => 'testName',
'type' => 'string', 'type' => 'string',

View file

@ -7975,7 +7975,7 @@ class FormHelperTest extends CakeTestCase {
); );
$this->assertTags($result, $expected); $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')); $result = $this->Form->year('Contact.published', 2006, 2007, array('class' => 'year'));
$expected = array( $expected = array(
array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')), array('select' => array('name' => 'data[Contact][published][year]', 'id' => 'ContactPublishedYear', 'class' => 'year')),

View file

@ -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') 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( $expected = array(
'<item', '<item',
'<title', 'title1-transformed', '/title', '<title', 'title1-transformed', '/title',

View file

@ -1495,13 +1495,13 @@ class ViewTest extends CakeTestCase {
/** /**
* Test setting a block's content to an object without __toString magic method * Test setting a block's content to an object without __toString magic method
* *
* 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 * @return void
*/ */
public function testBlockSetObjectWithoutToString() { public function testBlockSetObjectWithoutToString() {
$this->_checkException(
'Object of class TestObjectWithoutToString could not be converted to string'
);
$objectWithToString = new TestObjectWithoutToString(); $objectWithToString = new TestObjectWithoutToString();
$this->View->assign('testWithObjectWithoutToString', $objectWithToString); $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. * 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 * @return void
*/ */
public function testBlockAppendObjectWithoutToString() { public function testBlockAppendObjectWithoutToString() {
$this->_checkException(
'Object of class TestObjectWithoutToString could not be converted to string'
);
$object = new TestObjectWithoutToString(); $object = new TestObjectWithoutToString();
$this->View->assign('testBlock', 'Block '); $this->View->assign('testBlock', 'Block ');
$this->View->append('testBlock', $object); $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. * 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 * @return void
*/ */
public function testBlockPrependObjectWithoutToString() { public function testBlockPrependObjectWithoutToString() {
$this->_checkException(
'Object of class TestObjectWithoutToString could not be converted to string'
);
$object = new TestObjectWithoutToString(); $object = new TestObjectWithoutToString();
$this->View->assign('test', 'Block '); $this->View->assign('test', 'Block ');
$this->View->prepend('test', $object); $this->View->prepend('test', $object);
@ -1839,4 +1839,12 @@ TEXT;
$result = $this->View->get('title', $default); $result = $this->View->get('title', $default);
$this->assertEquals($expected, $result); $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);
}
}
} }