From 818aa3c3daadd7df3574aea5f7131683e298245d Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 00:36:56 +0200 Subject: [PATCH] Getting ready for PHP8, handling changed error levels/handlers mostly --- .travis.yml | 2 +- ...ernal_compile_private_special_variable.php | 4 ++-- .../UndefinedTemplateVarTest.php | 24 +++++++++++-------- .../MuteExpectedErrorsTest.php | 2 +- .../ConfigFileTests/file/ConfigVarTest.php | 6 ++++- .../ClearAllAssign/ClearAllAssignBCTest.php | 2 +- .../ClearAllAssign/ClearAllAssignTest.php | 6 ++--- .../ClearAssign/ClearAssignBCTest.php | 4 ++-- .../ClearAssign/ClearAssignTest.php | 4 ++-- .../TagTests/Foreach/CompileForeachTest.php | 2 +- .../PluginFunctionHtmlCheckboxesTest.php | 2 +- .../PluginFunctionHtmlOptionsTest.php | 2 +- .../PluginFunctionHtmlRadiosTest.php | 2 +- .../ConstantTests/ConstantsTest.php | 2 ++ 14 files changed, 37 insertions(+), 27 deletions(-) diff --git a/.travis.yml b/.travis.yml index f39da33b..21b766cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ dist: trusty matrix: include: - - php: 5.3 # Composer requires PHP 5.3.2+ to run, so we cannot test below 5.3 + - php: 5.3 # Composer and PHPUnit require PHP 5.3.2+ to run, so we cannot test below 5.3 dist: precise # PHP 5.3 is supported only on Precise. - php: 5.4 - php: 5.5 diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index b317c9f3..92a3844b 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -94,9 +94,9 @@ class Smarty_Internal_Compile_Private_Special_Variable extends Smarty_Internal_C break; } if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) { - return "@constant('{$_index[1]}')"; + return "defined('{$_index[1]}') ? constant('{$_index[1]}') : null"; } else { - return "@constant({$_index[1]})"; + return "defined({$_index[1]}) ? @constant({$_index[1]}) : null"; } // no break case 'config': diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index 8a564cbc..b40ff24e 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -29,7 +29,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty public function testE_NoticeDisabled() { $e1 = error_reporting(); - $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); $e2 = error_reporting(); $this->assertEquals($e1, $e2); @@ -41,7 +41,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty public function testE_NoticeDisabledTplObject_1() { $e1 = error_reporting(); - $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $tpl = $this->smarty->createTemplate('001_main.tpl'); $this->assertEquals('undefined = ', $tpl->fetch()); $e2 = error_reporting(); @@ -51,7 +51,7 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty public function testE_NoticeDisabledTplObject_2() { $e1 = error_reporting(); - $this->smarty->setErrorReporting(E_ALL & ~E_NOTICE); + $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $tpl = $this->smarty->createTemplate('001_main.tpl'); $this->assertEquals('undefined = ', $this->smarty->fetch($tpl)); $e2 = error_reporting(); @@ -60,15 +60,19 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty /** * Throw E_NOTICE message - * - * @expectedException PHPUnit_Framework_Error_Notice - * @expectedExceptionMessage Undefined index: foo */ public function testE_Notice() { - $e1 = error_reporting(); - $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); - $e2 = error_reporting(); - $this->assertEquals($e1, $e2); + if (PHP_VERSION_ID >= 80000) { + $this->expectExceptionMessage("Undefined array key \"foo\""); + $this->expectException(PHPUnit_Framework_Error_Warning::class); + } else { + $this->expectExceptionMessage("Undefined index: foo"); + $this->expectException(PHPUnit_Framework_Error_Notice::class); + } + $e1 = error_reporting(); + $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); } } diff --git a/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php b/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php index 2c39bdfb..19afd4dd 100644 --- a/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php +++ b/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php @@ -27,7 +27,7 @@ class MuteExpectedErrorsTest extends PHPUnit_Smarty { $this->cleanDirs(); } - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) { $this->_errors[] = $errfile . ' line ' . $errline; } diff --git a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php index 8a23ba3d..24a2a0e8 100644 --- a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php +++ b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php @@ -403,7 +403,11 @@ class ConfigVarTest extends PHPUnit_Smarty $this->assertEquals("", $this->smarty->fetch('foo.tpl')); } catch (Exception $e) { - $this->assertEquals('Undefined variable: foo', $e->getMessage()); + if (PHP_VERSION_ID >= 80000) { + $this->assertEquals('Undefined variable $foo', $e->getMessage()); + } else { + $this->assertEquals('Undefined variable: foo', $e->getMessage()); + } } } } diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php index eff71dee..48c104e9 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php @@ -33,7 +33,7 @@ class ClearAllAssignBCTest extends PHPUnit_Smarty public function testSmarty2ClearAllAssignInSmarty() { - error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE))); + error_reporting((error_reporting() & ~(E_NOTICE | E_WARNING | E_USER_NOTICE))); $this->smartyBC->clear_all_assign(); $this->assertEquals('barblar', $this->smartyBC->fetch($this->_tplBC)); } diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php index 2b3b3cac..459e8557 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php @@ -46,7 +46,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty */ public function testClearAllAssignInTemplate() { - error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE))); + error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING))); $this->_tpl->clearAllAssign(); $this->assertEquals('foobar', $this->smarty->fetch($this->_tpl)); } @@ -56,7 +56,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty */ public function testClearAllAssignInData() { - error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE))); + error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING))); $this->_data->clearAllAssign(); $this->assertEquals('fooblar', $this->smarty->fetch($this->_tpl)); } @@ -66,7 +66,7 @@ class ClearAllAssignTest extends PHPUnit_Smarty */ public function testClearAllAssignInSmarty() { - error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE))); + error_reporting((error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING))); $this->smarty->clearAllAssign(); $this->assertEquals('barblar', $this->smarty->fetch($this->_tpl)); } diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php index 17a0ed5f..b9867627 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php @@ -33,14 +33,14 @@ class ClearAssignBCTest extends PHPUnit_Smarty } public function testSmarty2ClearAssign() { - $this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); + $this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)); $this->smartyBC->clear_assign('blar'); $this->assertEquals('foobar', $this->smartyBC->fetch('eval:{$foo}{$bar}{$blar}')); } public function testSmarty2ArrayClearAssign() { - $this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); + $this->smartyBC->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)); $this->smartyBC->clear_assign(array('blar', 'foo')); $this->assertEquals('bar', $this->smartyBC->fetch('eval:{$foo}{$bar}{$blar}')); } diff --git a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php index d47e9da6..2b466928 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php @@ -36,7 +36,7 @@ class ClearAssignTest extends PHPUnit_Smarty */ public function testClearAssign() { - $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); + $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)); $this->smarty->clearAssign('blar'); $this->assertEquals('foobar', $this->smarty->fetch('eval:{$foo}{$bar}{$blar}')); } @@ -46,7 +46,7 @@ class ClearAssignTest extends PHPUnit_Smarty */ public function testArrayClearAssign() { - $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); + $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)); $this->smarty->clearAssign(array('blar', 'foo')); $this->assertEquals('bar', $this->smarty->fetch('eval:{$foo}{$bar}{$blar}')); } diff --git a/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php b/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php index 78a5214f..0630d6f8 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php @@ -44,7 +44,7 @@ class CompileForeachTest extends PHPUnit_Smarty $this->smarty->assign('foo', $foo); } else { // unassigned $from parameter - $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE)); + $this->smarty->setErrorReporting(error_reporting() & ~(E_NOTICE | E_USER_NOTICE | E_WARNING)); } $this->assertEquals($result, $this->smarty->fetch($file), "testForeach - {$code} - {$testName}"); diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php index 3d28dc67..8eff915f 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php @@ -275,7 +275,7 @@ class PluginFunctionHtmlCheckboxesTest extends PHPUnit_Smarty protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) { $this->_errors[] = $errstr; } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php index c5f7e6c9..fe8c5a06 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php @@ -369,7 +369,7 @@ class PluginFunctionHtmlOptionsTest extends PHPUnit_Smarty protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) { $this->_errors[] = $errstr; } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php index 0f5789b2..e8bc8eb2 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php @@ -275,7 +275,7 @@ class PluginFunctionHtmlRadiosTest extends PHPUnit_Smarty protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) { $this->_errors[] = $errstr; } diff --git a/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php b/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php index 3ab161b9..42f9df6f 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php @@ -78,11 +78,13 @@ class ConstantsTest extends PHPUnit_Smarty } public function testConstantsUndefined() { + $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $tpl = $this->smarty->createTemplate('string:{$smarty.const.MYCONSTANT2}'); $this->assertEquals("", $this->smarty->fetch($tpl)); } public function testConstantsUndefined2() { + $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); $tpl = $this->smarty->createTemplate('eval:{$foo = MYCONSTANT2}{$foo}'); $this->assertEquals("MYCONSTANT2", $this->smarty->fetch($tpl)); }