1 | <?php |
||
27 | class ServiceTest extends TestCase |
||
28 | { |
||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | private $commandFilename; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | private $callCountFilename; |
||
38 | |||
39 | /** |
||
40 | * @var int |
||
41 | */ |
||
42 | private $callCount = 1; |
||
43 | |||
44 | protected function setUp() |
||
48 | |||
49 | protected function tearDown() |
||
60 | |||
61 | /** |
||
62 | * @covers \SystemCtl\Service::__toString |
||
63 | */ |
||
64 | public function testServiceName() |
||
72 | |||
73 | /** |
||
74 | * @covers \SystemCtl\Service::isRunning |
||
75 | */ |
||
76 | public function testIsRunning() |
||
85 | |||
86 | /** |
||
87 | * @covers \SystemCtl\Service::isRunning |
||
88 | */ |
||
89 | public function testIsNotRunning() |
||
98 | |||
99 | /** |
||
100 | * @covers \SystemCtl\Service::isRunning |
||
101 | * @covers \SystemCtl\CommandFailedException |
||
102 | */ |
||
103 | public function testCheckInvalidServiceThrowsException() |
||
113 | |||
114 | /** |
||
115 | * @covers \SystemCtl\Service::isRunning |
||
116 | * @covers \SystemCtl\Service::start |
||
117 | */ |
||
118 | public function testStart() |
||
130 | |||
131 | /** |
||
132 | * @covers \SystemCtl\Service::isRunning |
||
133 | * @covers \SystemCtl\Service::start |
||
134 | */ |
||
135 | public function testStartAlreadyRunning() |
||
146 | |||
147 | /** |
||
148 | * @covers \SystemCtl\Service::isRunning |
||
149 | * @covers \SystemCtl\Service::start |
||
150 | * @covers \SystemCtl\CommandFailedException |
||
151 | */ |
||
152 | public function testStartInvalidServiceThrowsException() |
||
163 | |||
164 | /** |
||
165 | * @covers \SystemCtl\Service::isRunning |
||
166 | * @covers \SystemCtl\Service::stop |
||
167 | */ |
||
168 | public function testStop() |
||
180 | |||
181 | /** |
||
182 | * @covers \SystemCtl\Service::isRunning |
||
183 | * @covers \SystemCtl\Service::stop |
||
184 | */ |
||
185 | public function testStopWhenNotRunning() |
||
196 | |||
197 | /** |
||
198 | * @covers \SystemCtl\Service::isRunning |
||
199 | * @covers \SystemCtl\Service::stop |
||
200 | * @covers \SystemCtl\CommandFailedException |
||
201 | */ |
||
202 | public function testStopInvalidServiceThrowsException() |
||
213 | |||
214 | /** |
||
215 | * @covers \SystemCtl\Service::restart |
||
216 | */ |
||
217 | public function testRestart() |
||
228 | |||
229 | /** |
||
230 | * @covers \SystemCtl\Service::isRunning |
||
231 | * @covers \SystemCtl\Service::restart |
||
232 | * @covers \SystemCtl\CommandFailedException |
||
233 | */ |
||
234 | public function testRestartInvalidServiceThrowsException() |
||
244 | |||
245 | /** |
||
246 | * @covers \SystemCtl\Service::isRunning |
||
247 | * @covers \SystemCtl\Service::restart |
||
248 | * @covers \SystemCtl\CommandFailedException |
||
249 | */ |
||
250 | public function testExceptionHasProcess() |
||
265 | |||
266 | /** |
||
267 | * Returns a service instance with a mocked systemctl command. |
||
268 | * |
||
269 | * @param string $name Service name |
||
270 | * |
||
271 | * @return Service |
||
272 | */ |
||
273 | private function getMockedService($name) |
||
295 | |||
296 | /** |
||
297 | * Adds an expected call to the systemctl command. |
||
298 | * |
||
299 | * @param string[] $arguments List of expected arguments |
||
300 | * @param int $exitCode Exit code which the command should return |
||
301 | */ |
||
302 | private function expectCall(array $arguments, $exitCode) |
||
323 | |||
324 | /** |
||
325 | * Sets no more expected calls to the systemctl command. |
||
326 | */ |
||
327 | private function expectNoOtherCalls() |
||
333 | } |
||
334 |