[core] add custom error messages for stdlib_ex, and a test

This commit is contained in:
Shish
2024-02-05 13:25:18 +00:00
parent 51afc014a2
commit 92577d355f
2 changed files with 40 additions and 5 deletions

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace Shimmie2;
class StdLibExTest extends ShimmiePHPUnitTestCase
{
public function testJsonEncodeOk(): void
{
$this->assertEquals(
'{"a":1,"b":2,"c":3,"d":4,"e":5}',
json_encode_ex(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])
);
}
public function testJsonEncodeError(): void
{
$e = $this->assertException(\Exception::class, function() {
json_encode_ex("\xB1\x31");
});
$this->assertEquals(
"Malformed UTF-8 characters, possibly incorrectly encoded",
$e->getMessage()
);
}
}