Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for php8.0.0beta3 #608

Merged
merged 10 commits into from
Sep 12, 2020
27 changes: 14 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
language: php
os: linux
dist: xenial

sudo: false

dist: trusty
install:
- travis_retry composer install

matrix:
jobs:
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
dist: trusty # PHP 5.4 is supported only on Trusty.
- php: 5.5
dist: trusty # PHP 5.5 is supported only on Trusty.
- php: 5.6
- php: 7.0
- 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
install: travis_retry composer config platform.php 7.4.0 && composer install
fast_finish: true
allow_failures:
- php: nightly
- php: nightly # PHP 8 is still in beta

services:
- memcached
- 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

install:
- travis_retry composer install
- phpenv config-rm xdebug.ini || return 0

script:
- ./phpunit.sh
- ./phpunit.sh
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ 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
- Travis runs on Xenial where possible

### Fixed
- PHP5.3 compatability fixes
- PHP5.3 compatibility fixes

## [3.1.36] - 2020-04-14

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link

Choose a reason for hiding this comment

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

return "defined('{$_index[1]}') ? constant('{$_index[1]}') : null";
change to
return "(defined('{$_index[1]}') ? constant('{$_index[1]}') : null)";
??

Copy link
Contributor

Choose a reason for hiding this comment

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

I missed the fact that this is a code generation, in which case the braces may be necessary, given the fact the resulting expression may be used in ambiguous context..

} else {
return "@constant({$_index[1]})";
return "defined({$_index[1]}) ? constant({$_index[1]}) : null";
}
// no break
case 'config':
Expand Down
2 changes: 1 addition & 1 deletion libs/sysplugins/smarty_internal_errorhandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,51 +24,69 @@ 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_NOTICE);
$this->smarty->setErrorReporting(E_ALL & ~E_WARNING & ~E_NOTICE);
wisskid marked this conversation as resolved.
Show resolved Hide resolved
$this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl'));
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
}

/**
* 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_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();
$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_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();
$this->assertEquals($e1, $e2);
}

/**
* Throw E_NOTICE message
*
* @expectedException PHPUnit_Framework_Error_Notice
* @expectedExceptionMessage Undefined index: foo
* Throw Error message
*/
public function testE_Notice()
public function testError()
{
$e1 = error_reporting();
$this->assertEquals('undefined = ', $this->smarty->fetch('001_main.tpl'));
$e2 = error_reporting();
$this->assertEquals($e1, $e2);
$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;
$this->assertStringStartsWith('Undefined ', $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',
)
));
}
$this->assertTrue($exceptionThrown);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion tests/UnitTests/ConfigFileTests/file/ConfigVarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->assertStringStartsWith('Undefined variable', $e->getMessage());
} else {
$this->assertStringStartsWith('Undefined variable', $e->getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}'));
}
Expand All @@ -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}'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down