Issue #3206429 by Taran2L, chmez: [PHP 8] test failures in Drupal error handlers
parent
b6867ff622
commit
4c11b779d9
|
@ -164,13 +164,16 @@ class SimpleTestFunctionalTest extends DrupalWebTestCase {
|
|||
$this->pass(t('Test ID is @id.', array('@id' => $this->testId)));
|
||||
|
||||
// Generates a warning.
|
||||
$i = 1 / 0;
|
||||
$a = '';
|
||||
foreach ($a as $b) {
|
||||
|
||||
}
|
||||
|
||||
// Call an assert function specific to that class.
|
||||
$this->assertNothing();
|
||||
|
||||
// Generates a warning inside a PHP function.
|
||||
array_key_exists(NULL, NULL);
|
||||
// Generates 3 warnings inside a PHP function.
|
||||
simplexml_load_string('<fake>');
|
||||
|
||||
debug('Foo', 'Debug');
|
||||
}
|
||||
|
@ -195,19 +198,21 @@ class SimpleTestFunctionalTest extends DrupalWebTestCase {
|
|||
$this->assertAssertion(t('Invalid permission %permission.', array('%permission' => $this->invalid_permission)), 'Role', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
|
||||
// Check that a warning is caught by simpletest.
|
||||
$this->assertAssertion('Division by zero', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
// The exact error message differs between PHP versions so we check only
|
||||
// the presense of the 'foreach' statement.
|
||||
$this->assertAssertion('foreach()', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
|
||||
// Check that the backtracing code works for specific assert function.
|
||||
$this->assertAssertion('This is nothing.', 'Other', 'Pass', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
|
||||
// Check that errors that occur inside PHP internal functions are correctly reported.
|
||||
// The exact error message differs between PHP versions so we check only
|
||||
// the function name 'array_key_exists'.
|
||||
$this->assertAssertion('array_key_exists', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
// the function name 'simplexml_load_string'.
|
||||
$this->assertAssertion('simplexml_load_string', 'Warning', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
|
||||
$this->assertAssertion("Debug: 'Foo'", 'Debug', 'Fail', 'simpletest.test', 'SimpleTestFunctionalTest->stubTest()');
|
||||
|
||||
$this->assertEqual('6 passes, 5 fails, 2 exceptions, and 1 debug message', $this->childTestResults['summary'], 'Stub test summary is correct');
|
||||
$this->assertEqual('6 passes, 5 fails, 4 exceptions, and 1 debug message', $this->childTestResults['summary'], 'Stub test summary is correct');
|
||||
|
||||
$this->test_ids[] = $test_id = $this->getTestIdFromResults();
|
||||
$this->assertTrue($test_id, 'Found test ID in results.');
|
||||
|
|
|
@ -2633,8 +2633,8 @@ class DrupalErrorCollectionUnitTest extends DrupalWebTestCase {
|
|||
$this->assertEqual(count($this->collectedErrors), 3, 'Three errors were collected');
|
||||
|
||||
if (count($this->collectedErrors) == 3) {
|
||||
$this->assertError($this->collectedErrors[0], 'Notice', 'error_test_generate_warnings()', 'error_test.module', 'Undefined variable: bananas');
|
||||
$this->assertError($this->collectedErrors[1], 'Warning', 'error_test_generate_warnings()', 'error_test.module', 'Division by zero');
|
||||
$this->assertError($this->collectedErrors[0], 'Notice', 'error_test_generate_warnings()', 'error_test.module', 'Object of class stdClass could not be converted to int');
|
||||
$this->assertError($this->collectedErrors[1], 'Warning', 'error_test_generate_warnings()', 'error_test.module', \PHP_VERSION_ID < 80000 ? 'Invalid argument supplied for foreach()' : 'foreach() argument must be of type array|object, string given');
|
||||
$this->assertError($this->collectedErrors[2], 'User warning', 'error_test_generate_warnings()', 'error_test.module', 'Drupal is awesome');
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -22,13 +22,13 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
|
|||
function testErrorHandler() {
|
||||
$error_notice = array(
|
||||
'%type' => 'Notice',
|
||||
'!message' => 'Undefined variable: bananas',
|
||||
'!message' => 'Object of class stdClass could not be converted to int',
|
||||
'%function' => 'error_test_generate_warnings()',
|
||||
'%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
|
||||
);
|
||||
$error_warning = array(
|
||||
'%type' => 'Warning',
|
||||
'!message' => 'Division by zero',
|
||||
'!message' => \PHP_VERSION_ID < 80000 ? 'Invalid argument supplied for foreach()' : 'foreach() argument must be of type array|object, string given',
|
||||
'%function' => 'error_test_generate_warnings()',
|
||||
'%file' => drupal_realpath('modules/simpletest/tests/error_test.module'),
|
||||
);
|
||||
|
@ -113,4 +113,3 @@ class DrupalErrorHandlerTestCase extends DrupalWebTestCase {
|
|||
$this->assertNoRaw($message, format_string('Did not find error message: !message.', array('!message' => $message)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,9 +40,13 @@ function error_test_generate_warnings($collect_errors = FALSE) {
|
|||
// Tell Drupal error reporter to send errors to Simpletest or not.
|
||||
define('SIMPLETEST_COLLECT_ERRORS', $collect_errors);
|
||||
// This will generate a notice.
|
||||
$monkey_love = $bananas;
|
||||
$notice = new \stdClass();
|
||||
$notice == 1 ? 1 : 0;
|
||||
// This will generate a warning.
|
||||
$awesomely_big = 1/0;
|
||||
$a = '';
|
||||
foreach ($a as $b) {
|
||||
|
||||
}
|
||||
// This will generate a user error.
|
||||
trigger_error("Drupal is awesome", E_USER_WARNING);
|
||||
return "";
|
||||
|
|
Loading…
Reference in New Issue