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