Completed
Push — 1.x ( c0eb13...fc9cf1 )
by David
12:33
created

RegistryTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 45
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ get() 0 4 1
A hp$0 ➔ has() 0 4 1
A getContainer() 0 14 1
A testFromContainer() 0 9 1
A testInstantiate() 0 10 1
A testNotFound() 0 6 1
1
<?php
2
3
namespace TheCodingMachine\Tdbm\GraphQL\Registry;
4
5
use PHPUnit\Framework\TestCase;
6
use Psr\Container\ContainerInterface;
7
use TheCodingMachine\Tdbm\GraphQL\Fixtures\TestType;
8
9
class RegistryTest extends TestCase
10
{
11
    private function getContainer(): ContainerInterface
12
    {
13
        return new class implements ContainerInterface {
14
            public function get($id)
15
            {
16
                return 'foo';
17
            }
18
19
            public function has($id)
20
            {
21
                return $id === 'foo';
22
            }
23
        };
24
    }
25
26
    public function testFromContainer()
27
    {
28
        $registry = new Registry($this->getContainer());
29
30
        $this->assertTrue($registry->has('foo'));
31
        $this->assertFalse($registry->has('bar'));
32
33
        $this->assertSame('foo', $registry->get('foo'));
34
    }
35
36
    public function testInstantiate()
37
    {
38
        $registry = new Registry($this->getContainer());
39
40
        $this->assertTrue($registry->has(TestType::class));
41
        $type = $registry->get(TestType::class);
42
        $this->assertInstanceOf(TestType::class, $type);
43
        $this->assertSame($type, $registry->get(TestType::class));
44
        $this->assertTrue($registry->has(TestType::class));
45
    }
46
47
    public function testNotFound()
48
    {
49
        $registry = new Registry($this->getContainer());
50
        $this->expectException(NotFoundException::class);
51
        $registry->get('notfound');
52
    }
53
}
54