From e12895359b5c7969923dbfa62fe2f507ee399903 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Sa=CC=81=20Pereira?= Date: Wed, 29 Jul 2020 23:24:53 +0100 Subject: [PATCH 01/10] Set $errcontext argument optional to support PHP 8 - Argument is optional and deprecated in PHP 7.2 --- libs/sysplugins/smarty_internal_errorhandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sysplugins/smarty_internal_errorhandler.php b/libs/sysplugins/smarty_internal_errorhandler.php index 0ba00659d..56dca18fa 100644 --- a/libs/sysplugins/smarty_internal_errorhandler.php +++ b/libs/sysplugins/smarty_internal_errorhandler.php @@ -65,7 +65,7 @@ public static function muteExpectedErrors() * * @return bool */ - public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext) + public static function mutingErrorHandler($errno, $errstr, $errfile, $errline, $errcontext = array()) { $_is_muted_directory = false; // add the SMARTY_DIR to the list of muted directories From 818aa3c3daadd7df3574aea5f7131683e298245d Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 00:36:56 +0200 Subject: [PATCH 02/10] 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 f39da33be..21b766cf3 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 b317c9f33..92a3844b2 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 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $ 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 8a564cbc3..b40ff24e7 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -29,7 +29,7 @@ public function testInit() 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 @@ public function testE_NoticeDisabled() 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 @@ public function testE_NoticeDisabledTplObject_1() 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 @@ public function testE_NoticeDisabledTplObject_2() /** * 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 2c39bdfb4..19afd4dd5 100644 --- a/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php +++ b/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php @@ -27,7 +27,7 @@ public function testInit() { $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 8a23ba3db..24a2a0e89 100644 --- a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php +++ b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php @@ -403,7 +403,11 @@ public function testConfigUndefinedNotice() $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 eff71deea..48c104e9a 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignBCTest.php @@ -33,7 +33,7 @@ public function setUp() 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 2b3b3cacc..459e8557b 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAllAssign/ClearAllAssignTest.php @@ -46,7 +46,7 @@ public function testAllVariablesAccessable() */ 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 @@ public function testClearAllAssignInTemplate() */ 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 @@ public function testClearAllAssignInData() */ 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 17a0ed5fa..b98676271 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignBCTest.php @@ -33,14 +33,14 @@ public function testInit() } 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 d47e9da60..2b466928f 100644 --- a/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php +++ b/tests/UnitTests/SmartyMethodsTests/ClearAssign/ClearAssignTest.php @@ -36,7 +36,7 @@ public function testAllVariablesAccessable() */ 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 @@ public function testClearAssign() */ 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 78a5214f9..0630d6f89 100644 --- a/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/Foreach/CompileForeachTest.php @@ -44,7 +44,7 @@ public function testForeach($code, $foo, $result, $testName, $testNumber) $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 3d28dc676..8eff915f0 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php @@ -275,7 +275,7 @@ public function testObjectList() 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 c5f7e6c94..fe8c5a063 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php @@ -369,7 +369,7 @@ public function testObjectList() 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 0f5789b2b..e8bc8eb23 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php @@ -275,7 +275,7 @@ public function testObjectList() 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 3ab161b99..42f9df6fe 100644 --- a/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php +++ b/tests/UnitTests/TemplateSource/ValueTests/ConstantTests/ConstantsTest.php @@ -78,11 +78,13 @@ public function testConstants7() } 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)); } From 62dc42b0c51606df5f92a9b66af5bb60b7fc09ff Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 00:39:17 +0200 Subject: [PATCH 03/10] php5 compat syntax --- .../A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php | 2 +- .../PluginFunction/PluginFunctionHtmlCheckboxesTest.php | 2 +- .../TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php | 2 +- .../TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php b/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php index 19afd4dd5..6fbb53c16 100644 --- a/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php +++ b/tests/UnitTests/A_Core/MuteExpectedErrors/MuteExpectedErrorsTest.php @@ -27,7 +27,7 @@ public function testInit() { $this->cleanDirs(); } - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = array()) { $this->_errors[] = $errfile . ' line ' . $errline; } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php index 8eff915f0..2e4d6e684 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlCheckboxesTest.php @@ -275,7 +275,7 @@ public function testObjectList() protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = array()) { $this->_errors[] = $errstr; } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php index fe8c5a063..d9182c4e5 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlOptionsTest.php @@ -369,7 +369,7 @@ public function testObjectList() protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = array()) { $this->_errors[] = $errstr; } diff --git a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php index e8bc8eb23..819d10495 100644 --- a/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/PluginFunction/PluginFunctionHtmlRadiosTest.php @@ -275,7 +275,7 @@ public function testObjectList() protected $_errors = array(); - public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = []) + public function error_handler($errno, $errstr, $errfile, $errline, $errcontext = array()) { $this->_errors[] = $errstr; } From 3b0b48ed3e06485fe89c9fc4fce510711aa658a1 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 10:21:25 +0200 Subject: [PATCH 04/10] Updated UndefinedTemplateVarTest for PHP8 (and disabled a check for PHP<5.6) and re-enabled php:nightly in travis config --- .travis.yml | 2 +- .../UndefinedTemplateVarTest.php | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 21b766cf3..80752e3dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ matrix: - php: 7.2 - php: 7.3 - php: 7.4 -# - php: nightly # PHP nightly build testing disabled because PHPUnit doesn't support PHP8 yet. + - php: nightly # PHP nightly build testing disabled because PHPUnit doesn't support PHP8 yet. fast_finish: true allow_failures: - php: nightly diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index b40ff24e7..229420f0a 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -24,9 +24,9 @@ public function testInit() $this->cleanDirs(); } /** - * Test E_NOTICE suppression template fetched by Smarty object + * Test Error suppression template fetched by Smarty object */ - public function testE_NoticeDisabled() + public function testErrorDisabled() { $e1 = error_reporting(); $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); @@ -36,9 +36,9 @@ public function testE_NoticeDisabled() } /** - * Test E_NOTICE suppression template fetched by template object + * Test Error suppression template fetched by template object */ - public function testE_NoticeDisabledTplObject_1() + public function testErrorDisabledTplObject_1() { $e1 = error_reporting(); $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); @@ -48,7 +48,10 @@ public function testE_NoticeDisabledTplObject_1() $this->assertEquals($e1, $e2); } - public function testE_NoticeDisabledTplObject_2() + /** + * Test Error suppression template object fetched by Smarty object + */ + public function testErrorDisabledTplObject_2() { $e1 = error_reporting(); $this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE); @@ -59,14 +62,14 @@ public function testE_NoticeDisabledTplObject_2() } /** - * Throw E_NOTICE message + * Throw Error message */ - public function testE_Notice() + public function testError() { if (PHP_VERSION_ID >= 80000) { $this->expectExceptionMessage("Undefined array key \"foo\""); $this->expectException(PHPUnit_Framework_Error_Warning::class); - } else { + } elseif (PHP_VERSION_ID >= 56000) { $this->expectExceptionMessage("Undefined index: foo"); $this->expectException(PHPUnit_Framework_Error_Notice::class); } From ca2be225d62c0b2c4e5a803668f805de018393e4 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 11:07:03 +0200 Subject: [PATCH 05/10] Attempt to fix travis runs for (almost) all php versions supported --- .travis.yml | 15 ++++++++++----- composer.json | 2 +- tests/Bootstrap.php | 1 - .../UndefinedTemplateVarTest.php | 2 ++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 80752e3dd..69b760189 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,19 +4,27 @@ sudo: false dist: trusty -matrix: +install: + - travis_retry composer require phpunit/phpunit:^7.5 + +jobs: include: - 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. + install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.4 + install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.5 + install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.6 + install: travis_retry composer require phpunit/phpunit:^5.7 - php: 7.0 + install: travis_retry composer require phpunit/phpunit:^6.5 - php: 7.1 - php: 7.2 - php: 7.3 - php: 7.4 - - php: nightly # PHP nightly build testing disabled because PHPUnit doesn't support PHP8 yet. + - php: nightly fast_finish: true allow_failures: - php: nightly @@ -31,8 +39,5 @@ before_script: before_install: - phpenv config-rm xdebug.ini || return 0 -install: - - travis_retry composer install - script: - ./phpunit.sh diff --git a/composer.json b/composer.json index 9a5e7fd65..183f9f240 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ } }, "require-dev": { - "phpunit/phpunit": "6.4.1 || ^5.7 || ^4.8", + "phpunit/phpunit": "^7.5 || ^6.5 || ^5.7 || ^4.8", "smarty/smarty-lexer": "^3.1" } } diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index b3e05a8c6..ac4a4e6f2 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -16,7 +16,6 @@ class_alias('\PHPUnit\Framework\Error\Notice', '\PHPUnit_Framework_Error_Notice' class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error_Error'); class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning'); class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Deprecated'); - class_alias('\PHPUnit\Util\Configuration', '\PHPUnit_Util_Configuration'); } require_once 'PHPUnit_Smarty.php'; diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index 229420f0a..a23d6aa0b 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -72,6 +72,8 @@ public function testError() } elseif (PHP_VERSION_ID >= 56000) { $this->expectExceptionMessage("Undefined index: foo"); $this->expectException(PHPUnit_Framework_Error_Notice::class); + } else { + return; // skip this test } $e1 = error_reporting(); $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); From 7d48d8692f3f3d713009af74be3116be6b17b69f Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 12:55:43 +0200 Subject: [PATCH 06/10] Fix unit tests for php8, force composer to think we are still php7 to pick a supported phpunit and being less specific about an error msg because PHP8 is in active development and the exact wording is changing. --- .travis.yml | 7 ++-- .../UndefinedTemplateVarTest.php | 39 +++++++++++++------ .../ConfigFileTests/file/ConfigVarTest.php | 4 +- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index 69b760189..dd03b40ee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,7 @@ jobs: - php: 7.3 - php: 7.4 - php: nightly + install: travis_retry composer config platform.php 7.4.0 && composer require phpunit/phpunit:^7.5 fast_finish: true allow_failures: - php: nightly @@ -34,10 +35,10 @@ services: - mysql before_script: - - mysql -e "create database IF NOT EXISTS test;" -uroot + - mysql -e "create database IF NOT EXISTS test;" -uroot before_install: - - phpenv config-rm xdebug.ini || return 0 + - phpenv config-rm xdebug.ini || return 0 script: - - ./phpunit.sh + - ./phpunit.sh diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index a23d6aa0b..64fb9c001 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -66,18 +66,33 @@ public function testErrorDisabledTplObject_2() */ public function testError() { - if (PHP_VERSION_ID >= 80000) { - $this->expectExceptionMessage("Undefined array key \"foo\""); - $this->expectException(PHPUnit_Framework_Error_Warning::class); - } elseif (PHP_VERSION_ID >= 56000) { - $this->expectExceptionMessage("Undefined index: foo"); - $this->expectException(PHPUnit_Framework_Error_Notice::class); - } else { - return; // skip this test + $exceptionThrown = false; + + try { + $e1 = error_reporting(); + $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); + $e2 = error_reporting(); + $this->assertEquals($e1, $e2); + } catch (Exception $e) { + + $exceptionThrown = true; + + if (PHP_VERSION_ID >= 80000) { + $this->assertStringStartsWith('Undefined array key', $e->getMessage()); + } else { + $this->assertStringStartsWith('Undefined index', $e->getMessage()); + } + + $this->assertTrue(in_array( + get_class($e), + array( + 'PHPUnit_Framework_Error_Warning', + 'PHPUnit_Framework_Error_Notice', + 'PHPUnit\Framework\Error\Warning', + 'PHPUnit\Framework\Error\Notice', + ) + )); } - $e1 = error_reporting(); - $this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl')); - $e2 = error_reporting(); - $this->assertEquals($e1, $e2); + $this->assertTrue($exceptionThrown); } } diff --git a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php index 24a2a0e89..41faf101d 100644 --- a/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php +++ b/tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php @@ -404,9 +404,9 @@ public function testConfigUndefinedNotice() } catch (Exception $e) { if (PHP_VERSION_ID >= 80000) { - $this->assertEquals('Undefined variable $foo', $e->getMessage()); + $this->assertStringStartsWith('Undefined variable', $e->getMessage()); } else { - $this->assertEquals('Undefined variable: foo', $e->getMessage()); + $this->assertStringStartsWith('Undefined variable', $e->getMessage()); } } } From 6f41b9bfc99660004112591749d643762f51a77c Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 13:22:45 +0200 Subject: [PATCH 07/10] Fixed a unit test that accidentally passed on phpunit < 7 because of sloppy string comparison. --- .../TagTests/TemplateFunction/CompileFunctionTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php index 31ea49f26..d2be82ca3 100644 --- a/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php +++ b/tests/UnitTests/TemplateSource/TagTests/TemplateFunction/CompileFunctionTest.php @@ -297,7 +297,7 @@ public function testExternalDefinedFunctionNocachedCall3($merge, $text) */ public function testExternalDefinedFunctionRecursion($text) { - $this->assertEquals('12345', $this->smarty->fetch('test_template_function_recursion2.tpl'), $text); + $this->assertEquals('012345', $this->smarty->fetch('test_template_function_recursion2.tpl'), $text); } /** From 8df47cf030f7ee7d353e72790c7ab2fe657426a2 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 13:30:41 +0200 Subject: [PATCH 08/10] changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e052a44c..00dd5d9df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed -- Travis unit tests now run for all php versions >= 5.3 +- Changed error handlers and handling of undefined constants for php8-compatibility (set $errcontext argument optional) https://github.com/smarty-php/smarty/issues/605 +- Changed expected error levels in unit tests for php8-compatibility +- Travis unit tests now run for all php versions >= 5.3, including php8 ### Fixed -- PHP5.3 compatability fixes +- PHP5.3 compatibility fixes ## [3.1.36] - 2020-04-14 From d1dcee0d9ee506c4030c89eb2b0601f597bd8b62 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 11 Sep 2020 13:56:51 +0200 Subject: [PATCH 09/10] run travis in xenial where possible for latest php versions. Fix unit tests from freakingo over inconsistent error messages in php8-beta. --- .travis.yml | 10 +++++----- CHANGELOG.md | 1 + .../UndefinedTemplateVar/UndefinedTemplateVarTest.php | 8 +------- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index dd03b40ee..728452f61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: php - -sudo: false - -dist: trusty +os: linux +dist: xenial install: - travis_retry composer require phpunit/phpunit:^7.5 @@ -13,8 +11,10 @@ jobs: dist: precise # PHP 5.3 is supported only on Precise. install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.4 + dist: trusty # PHP 5.4 is supported only on Trusty. install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.5 + dist: trusty # PHP 5.5 is supported only on Trusty. install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.6 install: travis_retry composer require phpunit/phpunit:^5.7 @@ -28,7 +28,7 @@ jobs: install: travis_retry composer config platform.php 7.4.0 && composer require phpunit/phpunit:^7.5 fast_finish: true allow_failures: - - php: nightly + - php: nightly # PHP 8 is still in beta services: - memcached diff --git a/CHANGELOG.md b/CHANGELOG.md index 00dd5d9df..27702e356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed error handlers and handling of undefined constants for php8-compatibility (set $errcontext argument optional) https://github.com/smarty-php/smarty/issues/605 - Changed expected error levels in unit tests for php8-compatibility - Travis unit tests now run for all php versions >= 5.3, including php8 +- Travis runs on Xenial where possible ### Fixed - PHP5.3 compatibility fixes diff --git a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php index 64fb9c001..289e73e63 100644 --- a/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php +++ b/tests/UnitTests/A_2/UndefinedTemplateVar/UndefinedTemplateVarTest.php @@ -76,13 +76,7 @@ public function testError() } catch (Exception $e) { $exceptionThrown = true; - - if (PHP_VERSION_ID >= 80000) { - $this->assertStringStartsWith('Undefined array key', $e->getMessage()); - } else { - $this->assertStringStartsWith('Undefined index', $e->getMessage()); - } - + $this->assertStringStartsWith('Undefined ', $e->getMessage()); $this->assertTrue(in_array( get_class($e), array( From f25dd94f9fc1d611ca6bd4269a7e266d2a86da7c Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Sat, 12 Sep 2020 21:15:49 +0200 Subject: [PATCH 10/10] Incorporated AnrDaemons suggestions, making composer figure out the required phpunit version instead of specifying it explicitly and removing a unneeded error supression (@). --- .travis.yml | 9 ++------- .../smarty_internal_compile_private_special_variable.php | 2 +- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 728452f61..a8a11dcbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,29 +3,24 @@ os: linux dist: xenial install: - - travis_retry composer require phpunit/phpunit:^7.5 + - travis_retry composer install jobs: include: - 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. - install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.4 dist: trusty # PHP 5.4 is supported only on Trusty. - install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.5 dist: trusty # PHP 5.5 is supported only on Trusty. - install: travis_retry composer require phpunit/phpunit:^4.8 - php: 5.6 - install: travis_retry composer require phpunit/phpunit:^5.7 - php: 7.0 - install: travis_retry composer require phpunit/phpunit:^6.5 - php: 7.1 - php: 7.2 - php: 7.3 - php: 7.4 - php: nightly - install: travis_retry composer config platform.php 7.4.0 && composer require phpunit/phpunit:^7.5 + install: travis_retry composer config platform.php 7.4.0 && composer install fast_finish: true allow_failures: - php: nightly # PHP 8 is still in beta diff --git a/libs/sysplugins/smarty_internal_compile_private_special_variable.php b/libs/sysplugins/smarty_internal_compile_private_special_variable.php index 92a3844b2..d29012d46 100644 --- a/libs/sysplugins/smarty_internal_compile_private_special_variable.php +++ b/libs/sysplugins/smarty_internal_compile_private_special_variable.php @@ -96,7 +96,7 @@ public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $ if (strpos($_index[ 1 ], '$') === false && strpos($_index[ 1 ], '\'') === false) { return "defined('{$_index[1]}') ? constant('{$_index[1]}') : null"; } else { - return "defined({$_index[1]}) ? @constant({$_index[1]}) : null"; + return "defined({$_index[1]}) ? constant({$_index[1]}) : null"; } // no break case 'config':