1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LoopBackApiBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Théo FIDRY <[email protected]> |
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 Fidry\LoopBackApiBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Dunglas\ApiBundle\Api\Resource; |
15
|
|
|
use Fidry\LoopBackApiBundle\DependencyInjection\LoopBackApiExtension; |
16
|
|
|
use Fidry\LoopBackApiBundle\Tests\Prophecy\DependencyInjectionArgument; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
19
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @coversDefaultClass Fidry\LoopBackApiBundle\DependencyInjection\LoopBackApiExtension |
23
|
|
|
* |
24
|
|
|
* @author Théo FIDRY <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
class LoopBackApiExtensionTest extends \PHPUnit_Framework_TestCase |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @cover ::__construct |
30
|
|
|
*/ |
31
|
|
|
public function testConstruct() |
32
|
|
|
{ |
33
|
|
|
$extension = new LoopBackApiExtension(); |
34
|
|
|
$this->assertInstanceOf('Symfony\Component\DependencyInjection\Extension\ExtensionInterface', $extension); |
35
|
|
|
$this->assertInstanceOf( |
36
|
|
|
'Symfony\Component\DependencyInjection\Extension\ConfigurationExtensionInterface', |
37
|
|
|
$extension |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Tests the default configuration with all the extensions disabled. Expects no driver loaded. |
43
|
|
|
*/ |
44
|
|
|
public function testLoad() |
45
|
|
|
{ |
46
|
|
|
$containerBuilderProphecy = $this->getBaseDefaultContainerBuiderProphecy(); |
47
|
|
|
|
48
|
|
|
/* @var ContainerBuilder $containerBuilder */ |
49
|
|
|
$containerBuilder = $containerBuilderProphecy->reveal(); |
50
|
|
|
|
51
|
|
|
$extension = new LoopBackApiExtension(); |
52
|
|
|
|
53
|
|
|
$extension->load([], $containerBuilder); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Gets a Prophecy object for the ContainerBuilder which includes the mandatory called on the services included in |
58
|
|
|
* the default config. |
59
|
|
|
* |
60
|
|
|
* @return ObjectProphecy |
61
|
|
|
*/ |
62
|
|
|
private function getBaseDefaultContainerBuiderProphecy() |
63
|
|
|
{ |
64
|
|
|
$containerBuilderProphecy = $this->prophesize('Symfony\Component\DependencyInjection\ContainerBuilder'); |
65
|
|
|
|
66
|
|
|
$containerBuilderProphecy->setParameter('loopback_api.parameter.filter', 'filter')->shouldBeCalled(); |
67
|
|
|
$containerBuilderProphecy->setParameter('loopback_api.parameter.order_filter', 'order')->shouldBeCalled(); |
68
|
|
|
$containerBuilderProphecy->setParameter('loopback_api.parameter.search_filter', 'where')->shouldBeCalled(); |
69
|
|
|
|
70
|
|
|
$containerBuilderProphecy->hasExtension('http://symfony.com/schema/dic/services')->shouldBeCalled(); |
71
|
|
|
|
72
|
|
|
$containerBuilderProphecy |
73
|
|
|
->addResource(DependencyInjectionArgument::service(getcwd().'/src/Resources/config/services.xml')) |
74
|
|
|
->shouldBeCalled() |
75
|
|
|
; |
76
|
|
|
|
77
|
|
|
$containerBuilderProphecy |
78
|
|
|
->setDefinition( |
79
|
|
|
'loopback_api.resource', |
80
|
|
|
DependencyInjectionArgument::definition(Resource::class) |
81
|
|
|
) |
82
|
|
|
->shouldBeCalled() |
83
|
|
|
; |
84
|
|
|
|
85
|
|
|
$containerBuilderProphecy |
86
|
|
|
->setDefinition( |
87
|
|
|
'loopback_api.http.query_extractor.order_filter_query_extractor', |
88
|
|
|
DependencyInjectionArgument::definition('Fidry\LoopBackApiBundle\Http\Request\FilterQueryExtractor') |
89
|
|
|
) |
90
|
|
|
->shouldBeCalled() |
91
|
|
|
; |
92
|
|
|
$containerBuilderProphecy |
93
|
|
|
->setDefinition( |
94
|
|
|
'loopback_api.http.query_extractor.where_filter_query_extractor', |
95
|
|
|
DependencyInjectionArgument::definition('Fidry\LoopBackApiBundle\Http\Request\FilterQueryExtractor') |
96
|
|
|
) |
97
|
|
|
->shouldBeCalled() |
98
|
|
|
; |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
$containerBuilderProphecy |
102
|
|
|
->setDefinition( |
103
|
|
|
'loopback_api.filter.where_filter', |
104
|
|
|
DependencyInjectionArgument::definition('Fidry\LoopBackApiBundle\Filter\WhereFilter') |
105
|
|
|
) |
106
|
|
|
->shouldBeCalled() |
107
|
|
|
; |
108
|
|
|
$containerBuilderProphecy |
109
|
|
|
->setDefinition( |
110
|
|
|
'loopback_api.filter.order_filter', |
111
|
|
|
DependencyInjectionArgument::definition('Fidry\LoopBackApiBundle\Filter\OrderFilter') |
112
|
|
|
) |
113
|
|
|
->shouldBeCalled() |
114
|
|
|
; |
115
|
|
|
|
116
|
|
|
return $containerBuilderProphecy; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|