endtoend-test-psl/tests/Psl/Json/DecodeTest.php
2020-10-15 11:05:30 +02:00

47 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Psl\Json;
use PHPUnit\Framework\TestCase;
use Psl\Json;
final 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"
}');
static::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\"");
}
}