1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the OverblogGraphQLBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Overblog <http://github.com/overblog/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Overblog\GraphQLBundle\Tests\Resolver; |
13
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\Resolver\ArgResolver; |
15
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
|
18
|
|
|
class ArgResolverTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** @var ContainerBuilder */ |
21
|
|
|
private static $container; |
22
|
|
|
|
23
|
|
|
/** @var ArgResolver */ |
24
|
|
|
private static $argResolver; |
25
|
|
|
|
26
|
|
|
public static function setUpBeforeClass() |
27
|
|
|
{ |
28
|
|
|
$container = new ContainerBuilder(); |
29
|
|
|
|
30
|
|
|
$mapping = [ |
31
|
|
|
'Toto' => ['id' => 'overblog_graphql.definition.custom_toto_arg', 'alias' => 'Toto'], |
32
|
|
|
'Tata' => ['id' => 'overblog_graphql.definition.custom_tata_arg', 'alias' => 'Tata'], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$container->setParameter('overblog_graphql.args_mapping', $mapping); |
36
|
|
|
|
37
|
|
|
foreach ($mapping as $alias => $options) { |
38
|
|
|
$container->setDefinition($options['id'], new Definition('stdClass')) |
39
|
|
|
->setProperty('name', $alias); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
self::$container = $container; |
43
|
|
|
self::$argResolver = new ArgResolver(self::$container); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testResolveKnownArg() |
47
|
|
|
{ |
48
|
|
|
$arg = self::$argResolver->resolve('Toto'); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf('stdClass', $arg); |
51
|
|
|
$this->assertEquals('Toto', $arg->name); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @expectedException \Overblog\GraphQLBundle\Resolver\UnresolvableException |
56
|
|
|
*/ |
57
|
|
|
public function testResolveUnknownArg() |
58
|
|
|
{ |
59
|
|
|
self::$argResolver->resolve('Fake'); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|