mirror of
https://github.com/danog/endtoend-test-psl.git
synced 2024-12-04 10:39:57 +01:00
47 lines
1.2 KiB
PHP
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\JsonDecodeException::class);
|
||
|
$this->expectExceptionMessage('The decoded property name is invalid.');
|
||
|
|
||
|
Json\decode('{"\u0000": 1}', false);
|
||
|
}
|
||
|
|
||
|
public function testDecodeMalformedUTF8(): void
|
||
|
{
|
||
|
$this->expectException(Json\Exception\JsonDecodeException::class);
|
||
|
$this->expectExceptionMessage('Malformed UTF-8 characters, possibly incorrectly encoded.');
|
||
|
|
||
|
Json\decode("\"\xC1\xBF\"");
|
||
|
}
|
||
|
}
|