Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Cake/Console/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function dispatchShell() {
*/
public function runCommand($command, $argv) {
$isTask = $this->hasTask($command);
$isMethod = $this->hasMethod($command);
$isMethod = $command !== null && $this->hasMethod($command);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean runCommand() is actually called with a null command?

$isMain = $this->hasMethod('main');

if ($isTask || $isMethod && $command !== 'execute') {
Expand Down
16 changes: 13 additions & 3 deletions lib/Cake/Error/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static function handleException($exception) {

$renderer = isset($config['renderer']) ? $config['renderer'] : 'ExceptionRenderer';
if ($renderer !== 'ExceptionRenderer') {
list($plugin, $renderer) = pluginSplit($renderer, true);
[$plugin, $renderer] = pluginSplit($renderer, true);
App::uses($renderer, $plugin . 'Error');
}
try {
Expand Down Expand Up @@ -204,10 +204,20 @@ protected static function _log($exception, $config) {
* @return bool true if error was handled
*/
public static function handleError($code, $description, $file = null, $line = null, $context = null) {
if (error_reporting() === 0) {

/**
* The @ operator will no longer silence fatal errors
* (E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR,
* E_RECOVERABLE_ERROR, E_PARSE). Error handlers that
* expect error_reporting to be 0 when @ is used,
* should be adjusted to use a mask check instead:
* @see https://www.php.net/manual/en/migration80.incompatible.php
*/
if (!(error_reporting() & $code)) {
return false;
}
list($error, $log) = static::mapErrorCode($code);

[$error, $log] = static::mapErrorCode($code);
if ($log === LOG_ERR) {
return static::handleFatalError($code, $description, $file, $line);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Event/CakeEventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function dispatch($event) {
break;
}
if ($listener['passParams'] === true) {
$result = call_user_func_array($listener['callable'], $event->data);
$result = call_user_func_array($listener['callable'], array_values($event->data));
} else {
$result = call_user_func($listener['callable'], $event);
}
Expand Down
16 changes: 15 additions & 1 deletion lib/Cake/Model/Datasource/DboSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,18 @@ public function value($data, $column = null, $null = true) {
if (is_float($data)) {
return str_replace(',', '.', strval($data));
}

$isNumeric = is_numeric($data);

// as of PHP8, numeric strings with leading and/or trailing whitespace are considered
// numeric by PHP. we want to NOT consider these numeric because they need to be quoted
// for PDO purposes
if (is_string($data) && trim($data) !== $data) {
$isNumeric = false;
}

if (((is_int($data) || $data === '0') || (
is_numeric($data) &&
$isNumeric &&
strpos($data, ',') === false &&
$data[0] != '0' &&
strpos($data, 'e') === false)
Expand Down Expand Up @@ -567,6 +577,10 @@ public function lastNumRows($source = null) {
/**
* DataSource Query abstraction
*
* @param string $sql The SQL to pass to DboSource::fetchAll()
* @param array|bool|null $params Either parameters to be bound as values for the SQL statement,
* or a boolean to control query caching.
* @param array $options additional options for the query.
* @return resource Result resource identifier.
*/
public function query() {
Expand Down
31 changes: 20 additions & 11 deletions lib/Cake/Test/Case/Error/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ public function setUp(): void {
Router::setRequestInfo($request);
Configure::write('debug', 2);

CakeLog::disable('stdout');
CakeLog::disable('stderr');
$configuredLoggers = CakeLog::configured();
in_array("stdout", $configuredLoggers) ? CakeLog::disable('stdout') : null;
in_array("stderr", $configuredLoggers) ? CakeLog::disable('stderr') : null;
}

/**
Expand All @@ -81,8 +82,10 @@ public function tearDown(): void {
if ($this->_restoreError) {
restore_error_handler();
}
CakeLog::enable('stdout');
CakeLog::enable('stderr');

$configuredLoggers = CakeLog::configured();
in_array("stdout", $configuredLoggers) ? CakeLog::enable('stdout') : null;
in_array("stderr", $configuredLoggers) ? CakeLog::enable('stderr') : null;
}

/**
Expand All @@ -100,9 +103,13 @@ public function testHandleErrorDebugOn() {
$wrong .= '';
$result = ob_get_clean();

$errorLevel = PHP_VERSION_ID >= 80000
? "Warning"
: "Notice";

$this->assertRegExp('/<pre class="cake-error">/', $result);
$this->assertRegExp('/<b>Notice<\/b>/', $result);
$this->assertRegExp('/variable:\s+wrong/', $result);
$this->assertRegExp("/<b>{$errorLevel}<\\/b>/", $result);
$this->assertRegExp('/variable:?\s+\$?wrong/', $result);
}

/**
Expand Down Expand Up @@ -168,12 +175,13 @@ public function testHandleErrorDebugOff() {
set_error_handler('ErrorHandler::handleError');
$this->_restoreError = true;

$out .= '';
trigger_error("This is a notice", E_USER_NOTICE);

$result = file(LOGS . 'debug.log');
$this->assertEquals(1, count($result));
self::assertNotFalse($result, "Call to file() returned false, couldn't read lines from debug.log");
self::assertCount(1, $result);
$this->assertRegExp(
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (Notice|Debug): Notice \(8\): Undefined variable:\s+out in \[.+ line \d+\]$/',
"/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} Notice: Notice \(" . E_USER_NOTICE . "\): This is a notice in \[.+ line \d+\]$/",
$result[0]
);
if (file_exists(LOGS . 'debug.log')) {
Expand All @@ -196,11 +204,12 @@ public function testHandleErrorLoggingTrace() {
set_error_handler('ErrorHandler::handleError');
$this->_restoreError = true;

$out .= '';
trigger_error("This is a notice", E_USER_NOTICE);

$result = file(LOGS . 'debug.log');
self::assertNotFalse($result, "Call to file() returned false, couldn't read lines from debug.log");
$this->assertRegExp(
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (Notice|Debug): Notice \(8\): Undefined variable:\s+out in \[.+ line \d+\]$/',
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} (Notice): Notice \('.E_USER_NOTICE.'\): This is a notice in \[.+ line \d+\]$/',
$result[0]
);
$this->assertRegExp('/^Trace:/', $result[1]);
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/Test/Case/Model/ConnectionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function testSourceList() {
ConnectionManager::getDataSource('test');
$sources = ConnectionManager::sourceList();
$this->assertTrue(count($sources) >= 1);
$this->assertTrue(in_array('test', array_keys($sources)));
$this->assertTrue(in_array('test', $sources));
}

/**
Expand Down
107 changes: 1 addition & 106 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,111 +356,6 @@ public function testIndexDetection() {
$this->assertEquals($expected, $result);
}

/**
* MySQL 4.x returns index data in a different format,
* Using a mock ensure that MySQL 4.x output is properly parsed.
*
* @group indices
* @return void
*/
public function testIndexOnMySQL4Output() {
$name = $this->Dbo->fullTableName('simple');

$mockDbo = $this->getMock('Mysql', array('connect', '_execute', 'getVersion'));
$columnData = array(
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '0',
'Key_name' => 'PRIMARY',
'Seq_in_index' => '1',
'Column_name' => 'id',
'Collation' => 'A',
'Cardinality' => '0',
'Sub_part' => null,
'Packed' => null,
'Null' => '',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'pointless_bool',
'Seq_in_index' => '1',
'Column_name' => 'bool',
'Collation' => 'A',
'Cardinality' => null,
'Sub_part' => null,
'Packed' => null,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'pointless_small_int',
'Seq_in_index' => '1',
'Column_name' => 'small_int',
'Collation' => 'A',
'Cardinality' => null,
'Sub_part' => null,
'Packed' => null,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'one_way',
'Seq_in_index' => '1',
'Column_name' => 'bool',
'Collation' => 'A',
'Cardinality' => null,
'Sub_part' => null,
'Packed' => null,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
)),
array('0' => array(
'Table' => 'with_compound_keys',
'Non_unique' => '1',
'Key_name' => 'one_way',
'Seq_in_index' => '2',
'Column_name' => 'small_int',
'Collation' => 'A',
'Cardinality' => null,
'Sub_part' => null,
'Packed' => null,
'Null' => 'YES',
'Index_type' => 'BTREE',
'Comment' => ''
))
);

$mockDbo->expects($this->once())->method('getVersion')->will($this->returnValue('4.1'));
$resultMock = $this->getMock('PDOStatement', array('fetch'));
$mockDbo->expects($this->once())
->method('_execute')
->with('SHOW INDEX FROM ' . $name)
->will($this->returnValue($resultMock));

foreach ($columnData as $i => $data) {
$resultMock->expects($this->at($i))->method('fetch')->will($this->returnValue((object)$data));
}

$result = $mockDbo->index($name, false);
$expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
);
$this->assertEquals($expected, $result);
}

/**
* testColumn method
*
Expand Down Expand Up @@ -906,7 +801,7 @@ public function testDescribeHandleCurrentTimestamp() {
* @return void
*/
public function testDescribeHandleCurrentTimestampDatetime() {
$mysqlVersion = $this->Dbo->query('SELECT VERSION() as version', array('log' => false));
$mysqlVersion = $this->Dbo->query('SELECT VERSION() as version', [], array('log' => false));
$this->skipIf(version_compare($mysqlVersion[0][0]['version'], '5.6.0', '<'));

$name = $this->Dbo->fullTableName('timestamp_default_values');
Expand Down
Loading