Fix #20715: Adjust JSON helper error message assertions for PHP 8.6 compatibility in JsonTest class

This commit is contained in:
Wilmer Arambula
2026-01-20 19:09:50 -03:00
committed by GitHub
parent 114d1c8c46
commit eb75371da2
2 changed files with 21 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ Yii Framework 2 Change Log
------------------------
- Bug #20705: Replace `$this` with `self` in generics in Psalm annotations (mspirkov)
- Bug #20715: Adjust `JSON` helper error message assertions for `PHP 8.6` compatibility in `JsonTest` class (terabytesoftw)
2.0.54 January 09, 2026

View File

@@ -231,7 +231,17 @@ PHP
$json = "{'a': '1'}";
Json::decode($json);
} catch (InvalidArgumentException $e) {
$this->assertSame(Json::$jsonErrorMessages['JSON_ERROR_SYNTAX'], $e->getMessage());
if (PHP_VERSION_ID >= 80600) {
$this->assertStringContainsString(
Json::$jsonErrorMessages['JSON_ERROR_SYNTAX'],
$e->getMessage(),
);
} else {
$this->assertSame(
Json::$jsonErrorMessages['JSON_ERROR_SYNTAX'],
$e->getMessage(),
);
}
}
// unsupported type since PHP 5.5
@@ -241,10 +251,16 @@ PHP
Json::encode($data);
fclose($fp);
} catch (InvalidArgumentException $e) {
if (PHP_VERSION_ID >= 50500) {
$this->assertSame(Json::$jsonErrorMessages['JSON_ERROR_UNSUPPORTED_TYPE'], $e->getMessage());
if (PHP_VERSION_ID >= 80600) {
$this->assertStringContainsString(
Json::$jsonErrorMessages['JSON_ERROR_UNSUPPORTED_TYPE'],
$e->getMessage(),
);
} else {
$this->assertSame(Json::$jsonErrorMessages['JSON_ERROR_SYNTAX'], $e->getMessage());
$this->assertSame(
Json::$jsonErrorMessages['JSON_ERROR_UNSUPPORTED_TYPE'],
$e->getMessage(),
);
}
}
}