test: Attempting to read an undefined variable causes a Warning error (PHP 8.0+)

see: https://www.php.net/manual/en/migration80.incompatible.php
This commit is contained in:
Koji Tanaka 2023-01-07 15:54:44 +09:00 committed by Kamil Wylegala
parent 76d1673958
commit a5f6b6c8ee

View file

@ -109,8 +109,8 @@ class ErrorHandlerTest extends CakeTestCase {
$result = ob_get_clean(); $result = ob_get_clean();
$this->assertMatchesRegularExpression('/<pre class="cake-error">/', $result); $this->assertMatchesRegularExpression('/<pre class="cake-error">/', $result);
$this->assertMatchesRegularExpression('/<b>Notice<\/b>/', $result); $this->assertMatchesRegularExpression('/<b>Warning<\/b>/', $result);
$this->assertMatchesRegularExpression('/variable:\s+wrong/', $result); $this->assertMatchesRegularExpression('/variable\s+\$wrong/', $result);
} }
/** /**
@ -169,8 +169,8 @@ class ErrorHandlerTest extends CakeTestCase {
public function testHandleErrorDebugOff() { public function testHandleErrorDebugOff() {
Configure::write('debug', 0); Configure::write('debug', 0);
Configure::write('Error.trace', false); Configure::write('Error.trace', false);
if (file_exists(LOGS . 'debug.log')) { if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'debug.log'); unlink(LOGS . 'error.log');
} }
set_error_handler('ErrorHandler::handleError'); set_error_handler('ErrorHandler::handleError');
@ -178,10 +178,10 @@ class ErrorHandlerTest extends CakeTestCase {
$out .= ''; $out .= '';
$result = file(LOGS . 'debug.log'); $result = file(LOGS . 'error.log');
$this->assertEquals(1, count($result)); $this->assertEquals(1, count($result));
$this->assertMatchesRegularExpression( $this->assertMatchesRegularExpression(
'/^\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} Warning: Warning \(2\): Undefined variable\s+\$out in \[.+ line \d+\]$/',
$result[0] $result[0]
); );
if (file_exists(LOGS . 'debug.log')) { if (file_exists(LOGS . 'debug.log')) {
@ -197,8 +197,8 @@ class ErrorHandlerTest extends CakeTestCase {
public function testHandleErrorLoggingTrace() { public function testHandleErrorLoggingTrace() {
Configure::write('debug', 0); Configure::write('debug', 0);
Configure::write('Error.trace', true); Configure::write('Error.trace', true);
if (file_exists(LOGS . 'debug.log')) { if (file_exists(LOGS . 'error.log')) {
unlink(LOGS . 'debug.log'); unlink(LOGS . 'error.log');
} }
set_error_handler('ErrorHandler::handleError'); set_error_handler('ErrorHandler::handleError');
@ -206,9 +206,9 @@ class ErrorHandlerTest extends CakeTestCase {
$out .= ''; $out .= '';
$result = file(LOGS . 'debug.log'); $result = file(LOGS . 'error.log');
$this->assertMatchesRegularExpression( $this->assertMatchesRegularExpression(
'/^\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} Warning: Warning \(2\): Undefined variable\s+\$out in \[.+ line \d+\]$/',
$result[0] $result[0]
); );
$this->assertMatchesRegularExpression('/^Trace:/', $result[1]); $this->assertMatchesRegularExpression('/^Trace:/', $result[1]);