-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathEncodeTest.php
More file actions
39 lines (33 loc) · 1.1 KB
/
EncodeTest.php
File metadata and controls
39 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php declare(strict_types=1);
namespace ExceptionalJSON\Tests;
use ExceptionalJSON\EncodeErrorException;
use PHPUnit\Framework\TestCase;
final class EncodeTest extends TestCase
{
const VALID_ENCODED = '{"string":"foo bar baz","array":[1,2,3],"bigint":"12345678901234567890"}';
const ASSOC_ARRAY = ["string" => "foo bar baz", "array" => [1,2,3], "bigint" => "12345678901234567890"];
const BIGINT_AS_STRING = "12345678901234567890";
public function testEncodeAssocArray()
{
$this->assertSame(
self::VALID_ENCODED,
\ExceptionalJSON\encode(self::ASSOC_ARRAY)
);
}
public function testEncodeBigIntegerString()
{
$this->assertSame(
'"' . self::BIGINT_AS_STRING . '"',
\ExceptionalJSON\encode(self::BIGINT_AS_STRING)
);
}
public function testEncodeNonUtf8String()
{
try {
\ExceptionalJSON\encode("\xB1\x31");
} catch (EncodeErrorException $e) {
$this->assertSame(5, $e->getCode());
$this->assertSame("\xB1\x31", $e->getValue());
}
}
}