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 | declare(strict_types=1); |
||
3 | |||
4 | /** |
||
5 | * @author Yuriy Davletshin <[email protected]> |
||
6 | * @copyright 2015 Yuriy Davletshin |
||
7 | * @license MIT |
||
8 | */ |
||
9 | namespace PhpLab\Di; |
||
10 | |||
11 | use PhpLab\Di\Fake\{Component, Service}; |
||
12 | |||
13 | class ContainerWithServicesTest extends \PHPUnit_Framework_TestCase |
||
14 | { |
||
15 | protected $app; |
||
16 | |||
17 | public function setUp() |
||
18 | { |
||
19 | $this->app = new Container(); |
||
20 | $this->app->set('component', function () { |
||
21 | return new Component(function ($value) { |
||
22 | return '#' . $value; |
||
23 | }); |
||
24 | }); |
||
25 | } |
||
26 | |||
27 | public function testShouldGetPresettedComponent() |
||
28 | { |
||
29 | $service = $this->app->get('component'); |
||
30 | $this->assertInstanceOf('\PhpLab\Di\Fake\Component', $service); |
||
31 | } |
||
32 | |||
33 | public function testShouldThrowExceptionIfServiceDefinitionNotFound() |
||
34 | { |
||
35 | $this->setExpectedException('\PhpLab\Di\NotFoundException'); |
||
36 | $this->app->get('commonService'); |
||
37 | } |
||
38 | |||
39 | public function testShouldAssertWhatServiceDefinitionNotExists() |
||
40 | { |
||
41 | $result = $this->app->has('commonService'); |
||
42 | $this->assertFalse($result); |
||
43 | } |
||
44 | |||
45 | public function testShouldAssertWhatServiceDefinitionExists() |
||
46 | { |
||
47 | $this->app->set('commonService', function (Container $di) { |
||
48 | return new Service($di->get('component')); |
||
49 | }); |
||
50 | $result = $this->app->has('commonService'); |
||
51 | $this->assertTrue($result); |
||
52 | } |
||
53 | |||
54 | public function testShouldGetService() |
||
55 | { |
||
56 | $this->app->set('commonService', function (Container $di) { |
||
57 | return new Service($di->get('component')); |
||
58 | }); |
||
59 | $service = $this->app->get('commonService'); |
||
60 | $this->assertInstanceOf('\PhpLab\Di\Fake\Service', $service); |
||
61 | } |
||
62 | |||
63 | public function testShouldGetSameService() |
||
64 | { |
||
65 | $this->app->set('commonService', function (Container $di) { |
||
66 | return new Service($di->get('component')); |
||
67 | }); |
||
68 | $instance1 = $this->app->get('commonService'); |
||
69 | $instance2 = $this->app->get('commonService'); |
||
70 | $this->assertSame($instance1, $instance2); |
||
71 | } |
||
72 | |||
73 | |||
74 | public function testShouldCallMethodOfComponentFromService() |
||
75 | { |
||
76 | $this->app->set('commonService', function (Container $di) { |
||
77 | return new Service($di->get('component')); |
||
78 | }); |
||
79 | $service = $this->app->get('commonService'); |
||
80 | $result = $service->getComponent()->getResult('value'); |
||
81 | $this->assertEquals('#value', $result); |
||
82 | } |
||
83 | |||
84 | public function testShouldDefineServiceWithOptionalArgument() |
||
85 | { |
||
86 | $this->app->set('commonService', function (Container $di) { |
||
87 | return new Service($di->get('component'), 'xml'); |
||
88 | }); |
||
89 | $service = $this->app->get('commonService'); |
||
90 | $this->assertEquals('xml', $service->getFormat()); |
||
91 | } |
||
92 | |||
93 | public function testShouldDefineServiceWithSetterInjection() |
||
94 | { |
||
95 | $this->app->set('commonService', function (Container $di) { |
||
96 | $service = new Service($di->get('component')); |
||
97 | $service->setFormat('xml'); |
||
98 | |||
99 | return $service; |
||
100 | }); |
||
101 | $service = $this->app->get('commonService'); |
||
102 | $this->assertEquals('xml', $service->getFormat()); |
||
103 | } |
||
104 | |||
105 | public function testShouldGetServiceAfterChangeDefinition() |
||
106 | { |
||
107 | $this->app->set('commonService', function (Container $di) { |
||
108 | return new Service($di->get('component')); |
||
109 | }); |
||
110 | $this->app->set('commonService', function (Container $di) { |
||
111 | return new Service($di->get('component'), 'xml'); |
||
112 | }); |
||
113 | $service = $this->app->get('commonService'); |
||
114 | $this->assertEquals('xml', $service->getFormat()); |
||
115 | } |
||
116 | |||
117 | public function testShouldThrowExceptionIfChangeDefinitionAfterGettingService() |
||
118 | { |
||
119 | $this->setExpectedException('\PhpLab\Di\FrozenException'); |
||
120 | $this->app->set('commonService', function (Container $di) { |
||
121 | return new Service($di->get('component')); |
||
122 | }); |
||
123 | $service = $this->app->get('commonService'); |
||
0 ignored issues
–
show
|
|||
124 | $this->app->set('commonService', function (Container $di) { |
||
125 | return new Service($di->get('component'), 'xml'); |
||
126 | }); |
||
127 | } |
||
128 | |||
129 | public function testShouldThrowExceptionIfExtendServiceDefinitionNotFound() |
||
130 | { |
||
131 | $this->setExpectedException('\PhpLab\Di\NotFoundException'); |
||
132 | $this->app->extend('commonService', function ($service) { |
||
133 | $service->setFormat('xml'); |
||
134 | |||
135 | return $service; |
||
136 | }); |
||
137 | } |
||
138 | |||
139 | public function testShouldExtendServiseDefinition() |
||
140 | { |
||
141 | $this->app->set('commonService', function (Container $di) { |
||
142 | return new Service($di->get('component')); |
||
143 | }); |
||
144 | $this->app->extend('commonService', function ($service) { |
||
145 | $service->setFormat('xml'); |
||
146 | |||
147 | return $service; |
||
148 | }); |
||
149 | $service = $this->app->get('commonService'); |
||
150 | $this->assertEquals('xml', $service->getFormat()); |
||
151 | } |
||
152 | |||
153 | public function testShouldThrowExceptionIfExtendDefinitionAfterGettingService() |
||
154 | { |
||
155 | $this->setExpectedException('\PhpLab\Di\FrozenException'); |
||
156 | $this->app->set('commonService', function (Container $di) { |
||
157 | return new Service($di->get('component')); |
||
158 | }); |
||
159 | $service = $this->app->get('commonService'); |
||
0 ignored issues
–
show
$service is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
160 | $this->app->extend('commonService', function ($service) { |
||
161 | $service->setFormat('xml'); |
||
162 | |||
163 | return $service; |
||
164 | }); |
||
165 | } |
||
166 | |||
167 | public function testShouldRemoveServiceDefinition() |
||
168 | { |
||
169 | $this->app->set('commonService', function (Container $di) { |
||
170 | return new Service($di->get('component')); |
||
171 | }); |
||
172 | $this->app->remove('commonService'); |
||
173 | $result = $this->app->has('commonService'); |
||
174 | $this->assertFalse($result); |
||
175 | } |
||
176 | } |
||
177 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.