1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Kickbox Bundle. |
5
|
|
|
* |
6
|
|
|
* (c) Abdoul Ndiaye <[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 Andi\KickBoxBundle\Tests\DependencyInjection; |
13
|
|
|
|
14
|
|
|
use Andi\KickBoxBundle\DependencyInjection\AndiKickBoxExtension; |
15
|
|
|
use Andi\KickBoxBundle\Factory\ResponseFactory; |
16
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class AndiKickBoxExtension Test |
21
|
|
|
*/ |
22
|
|
|
class AndiKickBoxExtensionTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var AndiKickBoxExtension |
26
|
|
|
*/ |
27
|
|
|
protected $extension; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
protected function setUp() |
33
|
|
|
{ |
34
|
|
|
$this->extension = new AndiKickBoxExtension(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return ContainerBuilder |
39
|
|
|
*/ |
40
|
|
|
protected function getContainer() |
41
|
|
|
{ |
42
|
|
|
return new ContainerBuilder(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @dataProvider getConfigurations |
47
|
|
|
* |
48
|
|
|
* @param array $configs |
49
|
|
|
* @param bool $hasException |
50
|
|
|
*/ |
51
|
|
|
public function testLoad(array $configs, $hasException = false) |
52
|
|
|
{ |
53
|
|
|
$container = $this->getContainer(); |
54
|
|
|
|
55
|
|
|
if (true === $hasException) { |
56
|
|
|
$this->setExpectedException(InvalidConfigurationException::class); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$this->extension->load($configs, $container); |
60
|
|
|
|
61
|
|
|
$this->assertTrue($container->has('kickbox_client.name1')); |
62
|
|
|
|
63
|
|
|
$this->assertEquals('Andi\KickBoxBundle\Http\Client', $container->getParameter('kickbox.http.client.class')); |
64
|
|
|
$this->assertEquals('GuzzleHttp\Client', $container->getParameter('kickbox.guzzle.client.class')); |
65
|
|
|
$this->assertEquals( |
66
|
|
|
ResponseFactory::class, |
67
|
|
|
$container->getParameter('kickbox.http.response.factory.class') |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function getConfigurations() |
75
|
|
|
{ |
76
|
|
|
return [ |
77
|
|
|
[ |
78
|
|
|
[], |
79
|
|
|
true, |
80
|
|
|
], |
81
|
|
|
[ |
82
|
|
|
[ |
83
|
|
|
'andi_kick_box' => [ |
84
|
|
|
'api_keys' => [ |
85
|
|
|
'name1' => [ |
86
|
|
|
'' => 'my_key' |
87
|
|
|
] |
88
|
|
|
] |
89
|
|
|
] |
90
|
|
|
], |
91
|
|
|
true, |
92
|
|
|
], |
93
|
|
|
[ |
94
|
|
|
[ |
95
|
|
|
'andi_kick_box' => [ |
96
|
|
|
'api_keys' => [ |
97
|
|
|
'name1' => [ |
98
|
|
|
'key' => '' |
99
|
|
|
] |
100
|
|
|
] |
101
|
|
|
] |
102
|
|
|
], |
103
|
|
|
true, |
104
|
|
|
], |
105
|
|
|
[ |
106
|
|
|
[ |
107
|
|
|
'andi_kick_box' => [ |
108
|
|
|
'api_keys' => [ |
109
|
|
|
'name1' => [ |
110
|
|
|
'key' => 'my_key' |
111
|
|
|
] |
112
|
|
|
] |
113
|
|
|
] |
114
|
|
|
] |
115
|
|
|
] |
116
|
|
|
]; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|