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\Error; |
13
|
|
|
|
14
|
|
|
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionLanguage; |
15
|
|
|
use Overblog\GraphQLBundle\Tests\DIContainerMockTrait; |
16
|
|
|
|
17
|
|
|
class ConfigExpressionProviderTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
use DIContainerMockTrait; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ExpressionLanguage |
23
|
|
|
*/ |
24
|
|
|
private $expressionLanguage; |
25
|
|
|
|
26
|
|
|
public function setUp() |
27
|
|
|
{ |
28
|
|
|
$this->expressionLanguage = new ExpressionLanguage(); |
29
|
|
|
$container = $this->getDIContainerMock(); |
30
|
|
|
$this->expressionLanguage->setContainer($container); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testService() |
34
|
|
|
{ |
35
|
|
|
$object = new \stdClass(); |
36
|
|
|
$container = $this->getDIContainerMock(['toto' => $object]); |
37
|
|
|
$this->expressionLanguage->setContainer($container); |
38
|
|
|
$this->assertEquals($object, $this->expressionLanguage->evaluate('service("toto")')); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testParameter() |
42
|
|
|
{ |
43
|
|
|
$container = $this->getDIContainerMock([], ['test' => 5]); |
44
|
|
|
$this->expressionLanguage->setContainer($container); |
45
|
|
|
$this->assertEquals(5, $this->expressionLanguage->evaluate('parameter("test")')); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testIsTypeOf() |
49
|
|
|
{ |
50
|
|
|
$this->assertTrue($this->expressionLanguage->evaluate(sprintf('isTypeOf("%s")', 'stdClass'), ['value' => new \stdClass()])); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testNewObject() |
54
|
|
|
{ |
55
|
|
|
$this->assertInstanceOf('stdClass', $this->expressionLanguage->evaluate(sprintf('newObject("%s")', 'stdClass'))); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testFromGlobalId() |
59
|
|
|
{ |
60
|
|
|
$this->assertEquals(['type' => 'User', 'id' => 15], $this->expressionLanguage->evaluate('fromGlobalId("VXNlcjoxNQ==")')); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testGlobalId() |
64
|
|
|
{ |
65
|
|
|
$this->assertEquals('VXNlcjoxNQ==', $this->expressionLanguage->evaluate('globalId(15, "User")')); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|