Passed
Push — master ( 986482...835c8a )
by Vladimir
10:20
created

UtilsTest::testChrUtf8Generation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Tests;
6
7
use GraphQL\Utils\Utils;
8
use InvalidArgumentException;
9
use PHPUnit\Framework\TestCase;
10
use stdClass;
11
use function mb_check_encoding;
12
13
class UtilsTest extends TestCase
14
{
15
    public function testAssignThrowsExceptionOnMissingRequiredKey() : void
16
    {
17
        $object              = new stdClass();
18
        $object->requiredKey = 'value';
19
20
        $this->expectException(InvalidArgumentException::class);
21
        $this->expectExceptionMessage('Key requiredKey is expected to be set and not to be null');
22
        Utils::assign($object, [], ['requiredKey']);
23
    }
24
25
    /**
26
     * @param int    $input
27
     * @param string $expected
28
     *
29
     * @dataProvider    chrUtf8DataProvider
30
     */
31
    public function testChrUtf8Generation($input, $expected) : void
32
    {
33
        $result = Utils::chr($input);
34
        self::assertTrue(mb_check_encoding($result, 'UTF-8'));
35
        self::assertEquals($expected, $result);
36
    }
37
38
    public function chrUtf8DataProvider()
39
    {
40
        return [
41
            'alphabet' => [
42
                'input' => 0x0061,
43
                'expected' => 'a',
44
            ],
45
            'numeric' => [
46
                'input' => 0x0030,
47
                'expected' => '0',
48
            ],
49
            'between 128 and 256' => [
50
                'input' => 0x00E9,
51
                'expected' => 'é',
52
            ],
53
            'emoji' => [
54
                'input' => 0x231A,
55
                'expected' => '⌚',
56
            ],
57
        ];
58
    }
59
}
60