-
-
Notifications
You must be signed in to change notification settings - Fork 567
/
Copy pathUtilsTest.php
71 lines (59 loc) · 1.8 KB
/
UtilsTest.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php declare(strict_types=1);
namespace GraphQL\Tests;
use GraphQL\Utils\Utils;
use PHPUnit\Framework\TestCase;
final class UtilsTest extends TestCase
{
/** @dataProvider chrUtf8DataProvider */
public function testChrUtf8Generation(int $input, string $expected): void
{
$result = Utils::chr($input);
self::assertTrue(mb_check_encoding($result, 'UTF-8'));
self::assertSame($expected, $result);
}
/** @return iterable<array{input: int, expected: string}> */
public static function chrUtf8DataProvider(): iterable
{
yield 'alphabet' => [
'input' => 0x0061,
'expected' => 'a',
];
yield 'numeric' => [
'input' => 0x0030,
'expected' => '0',
];
yield 'between 128 and 256' => [
'input' => 0x00E9,
'expected' => 'é',
];
yield 'emoji' => [
'input' => 0x231A,
'expected' => '⌚',
];
}
/**
* @dataProvider printSafeJsonDataProvider
*
* @param mixed $value
*/
public function testPrintSafeJson(string $expected, $value): void
{
self::assertSame($expected, Utils::printSafeJson($value));
}
/** @return iterable<array{expected: string, value: mixed}> */
public static function printSafeJsonDataProvider(): iterable
{
yield 'stdClass' => [
'expected' => '{"foo":1}',
'value' => (object) ['foo' => 1],
];
yield 'invalid stdClass' => [
'expected' => "O:8:\"stdClass\":1:{s:12:\"invalid utf8\";s:2:\"\xB1\x31\";}",
'value' => (object) ['invalid utf8' => "\xB1\x31"],
];
yield 'empty string' => [
'expected' => '(empty string)',
'value' => '',
];
}
}