-
Notifications
You must be signed in to change notification settings - Fork 25
/
RouteResolverTest.php
64 lines (52 loc) · 1.92 KB
/
RouteResolverTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Overblog\GraphiQLBundle\Tests\Config\GraphQLEndpoint;
use Overblog\GraphiQLBundle\Config\GraphQLEndpoint\GraphQLEndpointInvalidSchemaException;
use Overblog\GraphiQLBundle\Config\GraphQLEndpoint\RouteResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Routing\RouterInterface;
final class RouteResolverTest extends TestCase
{
/** @var RouterInterface|MockObject */
protected $router;
public function setUp(): void
{
$this->router = $this->createMock(RouterInterface::class);
}
/**
* @return RouteResolver
*/
private function subject(array $routeCollection)
{
return new RouteResolver(
$this->router,
$routeCollection
);
}
public function testInvalidRoute()
{
$routeResolver = $this->subject([]);
$this->expectException(GraphQLEndpointInvalidSchemaException::class);
$this->expectExceptionMessage('Schema "default" isn\'t valid for resolver "Overblog\GraphiQLBundle\Config\GraphQLEndpoint\RouteResolver"');
$routeResolver->getDefault();
}
public function testArrayRoutes()
{
$this->router->expects($this->exactly(3))
->method('generate')
->withConsecutive(
['route_schema_default'],
['route_schema_default'],
['route_schema_star_wars']
)
->willReturnOnConsecutiveCalls('/', '/', '/star-wars');
$routeCollection = [
'default' => ['route_schema_default'],
'starWars' => ['route_schema_star_wars'],
];
$routeResolver = $this->subject($routeCollection);
$this->assertEquals('/', $routeResolver->getDefault());
$this->assertEquals('/', $routeResolver->getBySchema('default'));
$this->assertEquals('/star-wars', $routeResolver->getBySchema('starWars'));
}
}