1111use SystemCtl \SystemCtl ;
1212use SystemCtl \Unit \Service ;
1313use SystemCtl \Unit \Timer ;
14+ use SystemCtl \Unit \Socket ;
1415
1516/**
1617 * Class SystemCtlTest
@@ -135,6 +136,25 @@ public function itShouldCallCommandDispatcherWithListUnitsAndUnitPrefixOnTimerGe
135136 $ this ->assertEquals ($ unitName , $ timer ->getName ());
136137 }
137138
139+ /**
140+ * @test
141+ */
142+ public function itShouldCallCommandDispatcherWithListUnitsAndUnitPrefixOnSocketGetting ()
143+ {
144+ $ unitName = 'testSocket ' ;
145+ $ output = ' testSocket.socket Active running ' ;
146+ $ commandDispatcherStub = $ this ->buildCommandDispatcherStub ();
147+ $ commandDispatcherStub
148+ ->dispatch (...['list-units ' , $ unitName . '* ' ])
149+ ->willReturn ($ this ->buildCommandStub ($ output ));
150+
151+ $ systemctl = (new SystemCtl ())->setCommandDispatcher ($ commandDispatcherStub ->reveal ());
152+
153+ $ socket = $ systemctl ->getSocket ($ unitName );
154+ $ this ->assertInstanceOf (Socket::class, $ socket );
155+ $ this ->assertEquals ($ unitName , $ socket ->getName ());
156+ }
157+
138158 /**
139159 * @test
140160 */
@@ -152,6 +172,23 @@ public function itShouldThrowAnExeceptionIfNotTimerCouldBeFound()
152172 $ systemctl ->getTimer ($ unitName );
153173 }
154174
175+ /**
176+ * @test
177+ */
178+ public function itShouldThrowAnExceptionIfNoSocketCouldBeFound ()
179+ {
180+ $ unitName = 'testSocket ' ;
181+ $ commandDispatcherStub = $ this ->buildCommandDispatcherStub ();
182+ $ commandDispatcherStub
183+ ->dispatch (...['list-units ' , $ unitName . '* ' ])
184+ ->willReturn ($ this ->buildCommandStub ('' ));
185+
186+ $ systemctl = (new SystemCtl ())->setCommandDispatcher ($ commandDispatcherStub ->reveal ());
187+
188+ $ this ->expectException (UnitNotFoundException::class);
189+ $ systemctl ->getSocket ($ unitName );
190+ }
191+
155192 /**
156193 * @test
157194 */
0 commit comments