NodeIdResolverTest::testToGlobalId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Digia\Lumen\GraphQL\Tests\Fields;
4
5
use Digia\Lumen\GraphQL\Fields\NodeIdResolver;
6
use Digia\Lumen\GraphQL\Tests\TestCase;
7
8
class NodeIdResolverTest extends TestCase
9
{
10
11
    /**
12
     *
13
     */
14
    public function testIdFromGlobalId()
15
    {
16
        $globalId = base64_encode('Test:1');
17
18
        $id = NodeIdResolver::idFromGlobalId($globalId);
19
20
        $this->assertEquals('1', $id);
21
    }
22
23
    /**
24
     * @expectedException \Digia\Lumen\GraphQL\Exceptions\MalformedNodeIdException
25
     * @expectedExceptionMessage Node ID "Test1" is malformed.
26
     */
27
    public function testIdFromGlobalIdWithMalformedId()
28
    {
29
        NodeIdResolver::idFromGlobalId('Test1');
30
    }
31
32
    /**
33
     *
34
     */
35
    public function testTypeFromGlobalId()
36
    {
37
        $globalId = base64_encode('Test:1');
38
39
        $id = NodeIdResolver::typeFromGlobalId($globalId);
40
41
        $this->assertEquals('Test', $id);
42
    }
43
44
    /**
45
     *
46
     */
47
    public function testToGlobalId()
48
    {
49
        $globalId = NodeIdResolver::toGlobalId('Test', '1');
50
51
        $expected = base64_encode(implode(':', ['Test', '1']));
52
53
        $this->assertEquals($expected, $globalId);
54
    }
55
}
56