1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\GraphQL\Controllers\Registry; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Psr\Container\ContainerInterface; |
7
|
|
|
use TheCodingMachine\GraphQL\Controllers\AbstractQueryProviderTest; |
8
|
|
|
use TheCodingMachine\GraphQL\Controllers\Fixtures\TestType; |
9
|
|
|
use TheCodingMachine\GraphQL\Controllers\Security\AuthorizationServiceInterface; |
10
|
|
|
|
11
|
|
|
class RegistryTest extends AbstractQueryProviderTest |
12
|
|
|
{ |
13
|
|
|
private function getContainer(): ContainerInterface |
14
|
|
|
{ |
15
|
|
|
return new class implements ContainerInterface { |
16
|
|
|
public function get($id) |
17
|
|
|
{ |
18
|
|
|
return 'foo'; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function has($id) |
22
|
|
|
{ |
23
|
|
|
return $id === 'foo'; |
24
|
|
|
} |
25
|
|
|
}; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testFromContainer() |
29
|
|
|
{ |
30
|
|
|
$registry = $this->buildRegistry($this->getContainer()); |
31
|
|
|
|
32
|
|
|
$this->assertTrue($registry->has('foo')); |
33
|
|
|
$this->assertFalse($registry->has('bar')); |
34
|
|
|
|
35
|
|
|
$this->assertSame('foo', $registry->get('foo')); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testInstantiate() |
39
|
|
|
{ |
40
|
|
|
$registry = $this->buildRegistry($this->getContainer()); |
41
|
|
|
|
42
|
|
|
$this->assertTrue($registry->has(TestType::class)); |
43
|
|
|
$type = $registry->get(TestType::class); |
44
|
|
|
$this->assertInstanceOf(TestType::class, $type); |
45
|
|
|
$this->assertSame($type, $registry->get(TestType::class)); |
46
|
|
|
$this->assertTrue($registry->has(TestType::class)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testNotFound() |
50
|
|
|
{ |
51
|
|
|
$registry = $this->buildRegistry($this->getContainer()); |
52
|
|
|
$this->expectException(NotFoundException::class); |
53
|
|
|
$registry->get('notfound'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/*public function testGetAuthorization() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$authorizationService = $this->createMock(AuthorizationServiceInterface::class); |
59
|
|
|
$registry = new Registry($this->getContainer(), $authorizationService); |
60
|
|
|
|
61
|
|
|
$this->assertSame($authorizationService, $registry->getAuthorizationService()); |
62
|
|
|
|
63
|
|
|
$registry = new Registry($this->getContainer()); |
64
|
|
|
|
65
|
|
|
$this->assertNull($registry->getAuthorizationService()); |
66
|
|
|
}*/ |
67
|
|
|
} |
68
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.