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
|
|
|
public function testGetAuthorization() |
55
|
|
|
{ |
56
|
|
|
$authorizationService = $this->createMock(AuthorizationServiceInterface::class); |
57
|
|
|
$registry = new Registry($this->getContainer(), $authorizationService); |
58
|
|
|
|
59
|
|
|
$this->assertSame($authorizationService, $registry->getAuthorizationService()); |
60
|
|
|
|
61
|
|
|
$registry = new Registry($this->getContainer()); |
62
|
|
|
|
63
|
|
|
$this->assertNull($registry->getAuthorizationService()); |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
} |
69
|
|
|
|