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

RegistryTest::testFromContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
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