|
12 | 12 | use icanhazstring\SystemCtl\Unit\Service; |
13 | 13 | use icanhazstring\SystemCtl\Unit\Timer; |
14 | 14 | use icanhazstring\SystemCtl\Unit\Socket; |
| 15 | +use icanhazstring\SystemCtl\Unit\Scope; |
15 | 16 |
|
16 | 17 | /** |
17 | 18 | * Class SystemCtlTest |
@@ -155,6 +156,25 @@ public function itShouldCallCommandDispatcherWithListUnitsAndUnitPrefixOnSocketG |
155 | 156 | $this->assertEquals($unitName, $socket->getName()); |
156 | 157 | } |
157 | 158 |
|
| 159 | + /** |
| 160 | + * @test |
| 161 | + */ |
| 162 | + public function itShouldCallCommandDispatcherWithListUnitsAndUnitPrefixOnScopeGetting(): void |
| 163 | + { |
| 164 | + $unitName = 'testScope'; |
| 165 | + $output = ' testScope.scope Active running'; |
| 166 | + $commandDispatcherStub = $this->buildCommandDispatcherStub(); |
| 167 | + $commandDispatcherStub |
| 168 | + ->dispatch(...['list-units', $unitName . '*']) |
| 169 | + ->willReturn($this->buildCommandStub($output)); |
| 170 | + |
| 171 | + $systemctl = (new SystemCtl())->setCommandDispatcher($commandDispatcherStub->reveal()); |
| 172 | + |
| 173 | + $scope = $systemctl->getScope($unitName); |
| 174 | + $this->assertInstanceOf(Scope::class, $scope); |
| 175 | + $this->assertEquals($unitName, $scope->getName()); |
| 176 | + } |
| 177 | + |
158 | 178 | /** |
159 | 179 | * @test |
160 | 180 | */ |
@@ -189,6 +209,23 @@ public function itShouldThrowAnExceptionIfNoSocketCouldBeFound(): void |
189 | 209 | $systemctl->getSocket($unitName); |
190 | 210 | } |
191 | 211 |
|
| 212 | + /** |
| 213 | + * @test |
| 214 | + */ |
| 215 | + public function itShouldThrowAnExceptionIfNoScopeCouldBeFound(): void |
| 216 | + { |
| 217 | + $unitName = 'testScope'; |
| 218 | + $commandDispatcherStub = $this->buildCommandDispatcherStub(); |
| 219 | + $commandDispatcherStub |
| 220 | + ->dispatch(...['list-units', $unitName . '*']) |
| 221 | + ->willReturn($this->buildCommandStub('')); |
| 222 | + |
| 223 | + $systemctl = (new SystemCtl())->setCommandDispatcher($commandDispatcherStub->reveal()); |
| 224 | + |
| 225 | + $this->expectException(UnitNotFoundException::class); |
| 226 | + $systemctl->getScope($unitName); |
| 227 | + } |
| 228 | + |
192 | 229 | /** |
193 | 230 | * @test |
194 | 231 | */ |
|
0 commit comments