This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of the Superdesk Web Publisher Updater Bundle. |
||
5 | * |
||
6 | * Copyright 2015 Sourcefabric z.u. and contributors. |
||
7 | * |
||
8 | * For the full copyright and license information, please see the |
||
9 | * AUTHORS and LICENSE files distributed with this source code. |
||
10 | * |
||
11 | * @copyright 2015 Sourcefabric z.ú. |
||
12 | * @license http://www.superdesk.org/license |
||
13 | */ |
||
14 | namespace SWP\UpdaterBundle\Tests\DependencyInjection; |
||
15 | |||
16 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
17 | use SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension; |
||
18 | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
||
19 | |||
20 | class SWPUpdaterExtensionTest extends \PHPUnit_Framework_TestCase |
||
21 | { |
||
22 | /** |
||
23 | * @covers SWP\UpdaterBundle\SWPUpdaterBundle |
||
24 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
25 | * @covers SWP\UpdaterBundle\DependencyInjection\Configuration::getConfigTreeBuilder |
||
26 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
27 | */ |
||
28 | public function testLoad() |
||
29 | { |
||
30 | $curlOptions = array( |
||
31 | 'curl' => array( |
||
32 | '10203' => 'somehost:localhost', |
||
33 | ), |
||
34 | ); |
||
35 | |||
36 | $data = array( |
||
37 | 'swp_updater.version.class' => 'Acme\DemoBundle\Version\Version', |
||
38 | 'swp_updater.client.options' => $curlOptions, |
||
39 | ); |
||
40 | |||
41 | $container = $this->createContainer($data); |
||
42 | $loader = $this->createLoader(); |
||
43 | $config = $this->getConfig(); |
||
44 | |||
45 | $loader->load(array($config), $container); |
||
46 | |||
47 | $this->assertEquals('Acme\DemoBundle\Version\Version', $container->getParameter('swp_updater.version_class')); |
||
48 | $this->assertEquals(array('base_uri' => 'http://example.com'), $container->getParameter('swp_updater.client')); |
||
49 | $this->assertEquals($curlOptions, $container->getParameter('swp_updater.client.options')); |
||
50 | $this->assertEquals('Acme\DemoBundle\Version\Version', $container->getParameter('swp_updater.version.class')); |
||
51 | $this->assertEquals($container->getParameter('kernel.cache_dir'), $container->getParameter('swp_updater.temp_dir')); |
||
52 | $this->assertEquals($container->getParameter('kernel.root_dir').'/../', $container->getParameter('swp_updater.target_dir')); |
||
53 | $this->assertFalse($container->hasParameter('swp_updater.monolog_channel')); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
58 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
59 | */ |
||
60 | public function testLoadWhenTempDirAndTargetDirAreSet() |
||
61 | { |
||
62 | $container = $this->createContainer(); |
||
63 | $loader = $this->createLoader(); |
||
64 | $directories = array( |
||
65 | 'version_class' => 'Acme\DemoBundle\Version\Version', |
||
66 | 'temp_dir' => 'some/temp/dir', |
||
67 | 'target_dir' => 'some/target/dir', |
||
68 | ); |
||
69 | |||
70 | $config = $this->getConfig(); |
||
71 | $loader->load(array(array_merge($config, $directories)), $container); |
||
72 | $this->assertEquals( |
||
73 | $container->getParameter('kernel.root_dir').'/some/temp/dir', |
||
74 | $container->getParameter('swp_updater.temp_dir') |
||
75 | ); |
||
76 | |||
77 | $this->assertEquals( |
||
78 | 'some/target/dir', |
||
79 | $container->getParameter('swp_updater.target_dir') |
||
80 | ); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
85 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
86 | */ |
||
87 | View Code Duplication | public function testLoadIfMonologChannelDefined() |
|
0 ignored issues
–
show
|
|||
88 | { |
||
89 | $container = $this->createContainer(); |
||
90 | $loader = $this->createLoader(); |
||
91 | $config = $this->getConfig(); |
||
92 | $tempConfig = array( |
||
93 | 'version_class' => 'Acme\DemoBundle\Version\Version', |
||
94 | 'monolog_channel' => true, |
||
95 | ); |
||
96 | |||
97 | $loader->load(array(array_merge($config, $tempConfig)), $container); |
||
98 | $this->assertTrue($container->hasParameter('swp_updater.monolog_channel')); |
||
99 | $this->assertTrue($container->getParameter('swp_updater.monolog_channel')); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
104 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
105 | */ |
||
106 | public function testLoadWhenVersionClassIsRequired() |
||
107 | { |
||
108 | $container = $this->createContainer(); |
||
109 | $loader = $this->createLoader(); |
||
110 | |||
111 | $loader->load(array(array()), $container); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
116 | * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
||
117 | */ |
||
118 | public function testLoadWhenClientBaseUriIsRequiredAndCannotBeEmpty() |
||
119 | { |
||
120 | $container = $this->createContainer(); |
||
121 | $loader = $this->createLoader(); |
||
122 | |||
123 | $config = array( |
||
124 | 'version_class' => 'Acme\DemoBundle\Version\Version', |
||
125 | 'client' => array(), |
||
126 | ); |
||
127 | |||
128 | $loader->load(array($config), $container); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
133 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
134 | * @expectedException \LogicException |
||
135 | */ |
||
136 | public function testLoadWhenClientTypeIsNotSupported() |
||
137 | { |
||
138 | $container = $this->createContainer(); |
||
139 | $loader = $this->createLoader(); |
||
140 | |||
141 | $tempConfig = array( |
||
142 | 'client' => array( |
||
143 | 'type' => 'some_fake_name', |
||
144 | 'base_uri' => 'http://example.com', |
||
145 | ), |
||
146 | ); |
||
147 | |||
148 | $config = $this->getConfig(); |
||
149 | $loader->load(array(array_merge($config, $tempConfig)), $container); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
154 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
155 | * @expectedException \LogicException |
||
156 | */ |
||
157 | public function testLoadWhenGuzzleIsNotInstalledButUsed() |
||
158 | { |
||
159 | $container = $this->createContainer(); |
||
160 | $loader = $this->createLoader(); |
||
161 | |||
162 | $tempConfig = array( |
||
163 | 'client' => array( |
||
164 | 'type' => 'guzzle', |
||
165 | 'base_uri' => 'http://example.com', |
||
166 | ), |
||
167 | ); |
||
168 | |||
169 | $config = $this->getConfig(); |
||
170 | $loader->load(array(array_merge($config, $tempConfig)), $container); |
||
171 | |||
172 | $stub = $this->getMock('SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension', array('get')); |
||
173 | $stub->expects($this->at(0)) |
||
174 | ->method('get') |
||
175 | ->will($this->throwException(new \LogicException('error'))); |
||
176 | |||
177 | $this->assertFalse($stub->get()); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::load |
||
182 | * @covers SWP\UpdaterBundle\DependencyInjection\SWPUpdaterExtension::<private> |
||
183 | */ |
||
184 | View Code Duplication | public function testLoadForDefaultClient() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
185 | { |
||
186 | $container = $this->createContainer(); |
||
187 | $loader = $this->createLoader(); |
||
188 | $config = $this->getConfig(); |
||
189 | $tempConfig = array( |
||
190 | 'client' => array( |
||
191 | 'base_uri' => 'http://example.com', |
||
192 | ), |
||
193 | ); |
||
194 | |||
195 | $loader->load(array(array_merge($config, $tempConfig)), $container); |
||
196 | $this->assertEquals( |
||
197 | $container->getDefinition('swp_updater.client')->getClass(), |
||
198 | "SWP\UpdaterBundle\Client\DefaultClient" |
||
199 | ); |
||
200 | } |
||
201 | |||
202 | protected function createLoader() |
||
203 | { |
||
204 | return new SWPUpdaterExtension(); |
||
205 | } |
||
206 | |||
207 | protected function getConfig() |
||
208 | { |
||
209 | return array( |
||
210 | 'version_class' => 'Acme\DemoBundle\Version\Version', |
||
211 | 'client' => array( |
||
212 | 'base_uri' => 'http://example.com', |
||
213 | ), |
||
214 | ); |
||
215 | } |
||
216 | |||
217 | protected function createContainer(array $data = array()) |
||
218 | { |
||
219 | return new ContainerBuilder(new ParameterBag(array_merge(array( |
||
220 | 'kernel.cache_dir' => __DIR__, |
||
221 | 'kernel.root_dir' => __DIR__, |
||
222 | ), $data))); |
||
223 | } |
||
224 | } |
||
225 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.