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.

This commit is contained in:
Simon Wisselink
2020-09-11 12:55:43 +02:00
parent ca2be225d6
commit 7d48d8692f
3 changed files with 33 additions and 17 deletions

View File

@@ -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

View File

@@ -66,18 +66,33 @@ class UndefinedTemplateVarTest extends PHPUnit_Smarty
*/
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',
)
));
}
$this->assertTrue($exceptionThrown);
}
}

View File

@@ -404,9 +404,9 @@ class ConfigVarTest extends PHPUnit_Smarty
}
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());
}
}
}