Completed
Pull Request — master (#47)
by David
03:13
created

BasicAutoWiringContainerTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 17
dl 0
loc 43
rs 10
c 0
b 0
f 0

10 Methods

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