endtoend-test-psl/tests/Psl/Json/DecodeTest.php
2020-09-11 01:24:28 +01:00

47 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Json;
use PHPUnit\Framework\TestCase;
use Psl\Json;
class DecodeTest extends TestCase
{
public function testDecode(): void
{
$actual = Json\decode('{
"name": "azjezz/psl",
"type": "library",
"description": "PHP Standard Library.",
"keywords": ["php", "std", "stdlib", "utility", "psl"],
"license": "MIT"
}');
self::assertSame([
'name' => 'azjezz/psl',
'type' => 'library',
'description' => 'PHP Standard Library.',
'keywords' => ['php', 'std', 'stdlib', 'utility', 'psl'],
'license' => 'MIT'
], $actual);
}
public function testDecodeThrowsForInvalidSyntax(): void
{
$this->expectException(Json\Exception\DecodeException::class);
$this->expectExceptionMessage('The decoded property name is invalid.');
Json\decode('{"\u0000": 1}', false);
}
public function testDecodeMalformedUTF8(): void
{
$this->expectException(Json\Exception\DecodeException::class);
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded.');
Json\decode("\"\xC1\xBF\"");
}
}