diff --git a/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php b/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php index 6d01ec173..906246ff4 100644 --- a/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php +++ b/tests/php-unit-tests/unitary-tests/core/Log/DeprecatedCallsLogTest.php @@ -9,10 +9,30 @@ namespace Combodo\iTop\Test\UnitTest\Core\Log; use Combodo\iTop\Test\UnitTest\ItopTestCase; use DeprecatedCallsLog; +use PHPUnit\Framework\Error\Notice; +use PHPUnit\Framework\Error\Warning; class DeprecatedCallsLogTest extends ItopTestCase { + /** + * We are testing for a undefined offset error. This was throwing a Notice, but starting with PHP 8.0 it was converted to a Warning ! Also the message was changed :( + * + * @link https://www.php.net/manual/en/migration80.incompatible.php check "A number of notices have been converted into warnings:" + */ + private function SetUndefinedOffsetExceptionToExpect(): void { + if (version_compare(phpversion(), '8.0', '>=')) { + $sUndefinedOffsetExceptionClass = Warning::class; + $sUndefinedOffsetExceptionMessage = 'Undefined array key "tutu"'; + } + else { + $sUndefinedOffsetExceptionClass = Notice::class; + $sUndefinedOffsetExceptionMessage = 'Undefined index: tutu'; + } + $this->expectException($sUndefinedOffsetExceptionClass); + $this->expectExceptionMessage($sUndefinedOffsetExceptionMessage); + } + public function testPhpNoticeWithoutDeprecatedCallsLog(): void { - $this->expectNotice(); + $this->SetUndefinedOffsetExceptionToExpect(); $aArray = []; if ('toto' === $aArray['tutu']) { @@ -31,7 +51,7 @@ class DeprecatedCallsLogTest extends ItopTestCase { public function testPhpNoticeWithDeprecatedCallsLog(): void { $this->RequireOnceItopFile('core/log.class.inc.php'); DeprecatedCallsLog::Enable(); // will set error handler - $this->expectNotice(); + $this->SetUndefinedOffsetExceptionToExpect(); $aArray = []; if ('toto' === $aArray['tutu']) {