1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\Tdbm\GraphQL\Registry; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Psr\Container\ContainerInterface; |
7
|
|
|
use TheCodingMachine\GraphQL\Controllers\Security\AuthorizationServiceInterface; |
8
|
|
|
use TheCodingMachine\Tdbm\GraphQL\Fixtures\TestType; |
9
|
|
|
|
10
|
|
|
class RegistryTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private function getContainer(): ContainerInterface |
13
|
|
|
{ |
14
|
|
|
return new class implements ContainerInterface { |
15
|
|
|
public function get($id) |
16
|
|
|
{ |
17
|
|
|
return 'foo'; |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function has($id) |
21
|
|
|
{ |
22
|
|
|
return $id === 'foo'; |
23
|
|
|
} |
24
|
|
|
}; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testFromContainer() |
28
|
|
|
{ |
29
|
|
|
$registry = new Registry($this->getContainer()); |
|
|
|
|
30
|
|
|
|
31
|
|
|
$this->assertTrue($registry->has('foo')); |
32
|
|
|
$this->assertFalse($registry->has('bar')); |
33
|
|
|
|
34
|
|
|
$this->assertSame('foo', $registry->get('foo')); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testInstantiate() |
38
|
|
|
{ |
39
|
|
|
$registry = new Registry($this->getContainer()); |
|
|
|
|
40
|
|
|
|
41
|
|
|
$this->assertTrue($registry->has(TestType::class)); |
42
|
|
|
$type = $registry->get(TestType::class); |
43
|
|
|
$this->assertInstanceOf(TestType::class, $type); |
44
|
|
|
$this->assertSame($type, $registry->get(TestType::class)); |
45
|
|
|
$this->assertTrue($registry->has(TestType::class)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testNotFound() |
49
|
|
|
{ |
50
|
|
|
$registry = new Registry($this->getContainer()); |
|
|
|
|
51
|
|
|
$this->expectException(NotFoundException::class); |
52
|
|
|
$registry->get('notfound'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testGetAuthorization() |
56
|
|
|
{ |
57
|
|
|
$authorizationService = $this->createMock(AuthorizationServiceInterface::class); |
58
|
|
|
$registry = new Registry($this->getContainer(), $authorizationService); |
|
|
|
|
59
|
|
|
|
60
|
|
|
$this->assertSame($authorizationService, $registry->getAuthorizationService()); |
61
|
|
|
|
62
|
|
|
$registry = new Registry($this->getContainer()); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->assertNull($registry->getAuthorizationService()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.