|
| 1 | +<?php declare(strict_types=1); |
| 2 | +/* |
| 3 | + * Copyright 2022 Bastian Schwarz <bastian@codename-php.de>. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +namespace de\codenamephp\deployer\command\test\service; |
| 19 | + |
| 20 | +use de\codenamephp\deployer\command\Command; |
| 21 | +use de\codenamephp\deployer\command\runner\iRunner; |
| 22 | +use de\codenamephp\deployer\command\runner\WithDeployerFunctions; |
| 23 | +use de\codenamephp\deployer\command\service\Systemctl; |
| 24 | +use PHPUnit\Framework\TestCase; |
| 25 | + |
| 26 | +final class SystemctlTest extends TestCase { |
| 27 | + |
| 28 | + private Systemctl $sut; |
| 29 | + |
| 30 | + protected function setUp() : void { |
| 31 | + parent::setUp(); |
| 32 | + |
| 33 | + $this->sut = new Systemctl(); |
| 34 | + } |
| 35 | + |
| 36 | + public function test__construct() : void { |
| 37 | + $this->sut = new Systemctl(); |
| 38 | + |
| 39 | + self::assertInstanceOf(WithDeployerFunctions::class, $this->sut->runner); |
| 40 | + } |
| 41 | + |
| 42 | + public function test__construct_withArguments() : void { |
| 43 | + $runner = $this->createMock(iRunner::class); |
| 44 | + |
| 45 | + $this->sut = new Systemctl($runner); |
| 46 | + |
| 47 | + self::assertSame($runner, $this->sut->runner); |
| 48 | + } |
| 49 | + |
| 50 | + public function testRun() : void { |
| 51 | + $command = new Command(binary: 'systemctl', arguments: ['restart', 'apache2'], sudo: true); |
| 52 | + |
| 53 | + $this->sut->runner = $this->createMock(iRunner::class); |
| 54 | + $this->sut->runner->expects(self::once())->method('run')->with($command)->willReturn('some output'); |
| 55 | + |
| 56 | + self::assertEquals('some output', $this->sut->run('apache2', 'restart')); |
| 57 | + } |
| 58 | +} |
0 commit comments