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
|
|
|
|