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

UtilsTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 21
c 2
b 0
f 0
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A chrUtf8DataProvider() 0 18 1
A testChrUtf8Generation() 0 5 1
A testAssignThrowsExceptionOnMissingRequiredKey() 0 8 1
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