11<?php
22
3- namespace SystemCtl \Test ;
3+ namespace SystemCtl \Test \ Integration ;
44
55use PHPUnit \Framework \TestCase ;
66use Symfony \Component \Process \Process ;
1313
1414class SystemCtlTest extends TestCase
1515{
16- /**
17- * @param string $output
18- * @return \PHPUnit_Framework_MockObject_MockObject|SystemCtl
19- */
20- private function buildSystemCtlMock ($ output )
21- {
22-
23- $ process = $ this ->getMockBuilder (Process::class)
24- ->disableOriginalConstructor ()
25- ->setMethods (['getOutput ' ])
26- ->getMock ();
27-
28- $ process ->method ('getOutput ' )->willReturn ($ output );
29-
30- $ processBuilder = $ this ->getMockBuilder (ProcessBuilder::class)
31- ->disableOriginalConstructor ()
32- ->setMethods (['getProcess ' ])
33- ->getMock ();
34-
35- $ processBuilder ->method ('getProcess ' )->willReturn ($ process );
36-
37- $ systemctl = $ this ->getMockBuilder (SystemCtl::class)
38- ->setMethods (['getProcessBuilder ' ])
39- ->getMock ();
40-
41- $ systemctl ->method ('getProcessBuilder ' )->willReturn ($ processBuilder );
42-
43- return $ systemctl ;
44- }
45-
4616 public function testListUnitsWithAvailableUnits ()
4717 {
4818 $ output = <<<EOT
@@ -55,7 +25,7 @@ public function testListUnitsWithAvailableUnits()
5525 systemd-ask-password-wall.path loaded active waiting
5626 acpid.service loaded active running
5727 beanstalkd.service loaded active running
58- console-setup.service loaded active exited
28+ console-setup.service loaded active exited
5929 cron.service loaded active running
6030EOT ;
6131 $ systemctl = $ this ->buildSystemCtlMock ($ output );
@@ -75,7 +45,7 @@ public function testListUnitsWithSupportedUnits()
7545 systemd-ask-password-wall.path loaded active waiting
7646 acpid.service loaded active running
7747 beanstalkd.service loaded active running
78- console-setup.service loaded active exited
48+ console-setup.service loaded active exited
7949 cron.service loaded active running
8050EOT ;
8151 $ systemctl = $ this ->buildSystemCtlMock ($ output );
@@ -97,16 +67,6 @@ public function testCreateUnitFromUnsupportedSuffixShouldRaiseException()
9767 SystemCtl::unitFromSuffix ('unsupported ' , 'FailUnit ' );
9868 }
9969
100- public function testGetServiceWithName ()
101- {
102- $ output = 'testService.service Active Running ' ;
103- $ systemctl = $ this ->buildSystemCtlMock ($ output );
104-
105- $ service = $ systemctl ->getService ('testService ' );
106- $ this ->assertInstanceOf (Service::class, $ service );
107- $ this ->assertEquals ('testService ' , $ service ->getName ());
108- }
109-
11070 public function testGetServices ()
11171 {
11272 $ output = <<<EOT
@@ -115,7 +75,7 @@ public function testGetServices()
11575 awesomeservice.service Active running
11676 nonservice.timer Active running
11777PLACEHOLDER STUFF
118-
78+
11979EOT ;
12080
12181 $ systemctl = $ this ->buildSystemCtlMock ($ output );
@@ -124,15 +84,6 @@ public function testGetServices()
12484 $ this ->assertCount (2 , $ services );
12585 }
12686
127- public function testGetTimerWithName ()
128- {
129- $ systemctl = new SystemCtl ();
130-
131- $ timer = $ systemctl ->getTimer ('testTimer ' );
132- $ this ->assertInstanceOf (Timer::class, $ timer );
133- $ this ->assertEquals ('testTimer ' , $ timer ->getName ());
134- }
135-
13687 public function testGetTimers ()
13788 {
13889 $ output = <<<EOT
@@ -161,4 +112,33 @@ public function testSetBinaryShouldChangeCommand()
161112 $ processBuilder = $ systemCtl ->getProcessBuilder ();
162113 $ this ->assertEquals ("'/usr/sbin/systemctl' " , $ processBuilder ->getProcess ()->getCommandLine ());
163114 }
115+
116+ /**
117+ * @param string $output
118+ * @return \PHPUnit_Framework_MockObject_MockObject|SystemCtl
119+ */
120+ private function buildSystemCtlMock ($ output )
121+ {
122+ $ process = $ this ->getMockBuilder (Process::class)
123+ ->disableOriginalConstructor ()
124+ ->setMethods (['getOutput ' ])
125+ ->getMock ();
126+
127+ $ process ->method ('getOutput ' )->willReturn ($ output );
128+
129+ $ processBuilder = $ this ->getMockBuilder (ProcessBuilder::class)
130+ ->disableOriginalConstructor ()
131+ ->setMethods (['getProcess ' ])
132+ ->getMock ();
133+
134+ $ processBuilder ->method ('getProcess ' )->willReturn ($ process );
135+
136+ $ systemctl = $ this ->getMockBuilder (SystemCtl::class)
137+ ->setMethods (['getProcessBuilder ' ])
138+ ->getMock ();
139+
140+ $ systemctl ->method ('getProcessBuilder ' )->willReturn ($ processBuilder );
141+
142+ return $ systemctl ;
143+ }
164144}
0 commit comments