|
| 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; |
| 19 | + |
| 20 | +use de\codenamephp\deployer\command\Command; |
| 21 | +use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration; |
| 22 | +use PHPUnit\Framework\TestCase; |
| 23 | + |
| 24 | +final class CommandTest extends TestCase { |
| 25 | + |
| 26 | + private Command $sut; |
| 27 | + |
| 28 | + protected function setUp() : void { |
| 29 | + parent::setUp(); |
| 30 | + |
| 31 | + $this->sut = new Command(''); |
| 32 | + } |
| 33 | + |
| 34 | + public function test__construct() : void { |
| 35 | + $binary = 'some binary'; |
| 36 | + $runConfiguration = $this->createMock(iRunConfiguration::class); |
| 37 | + $arguments = ['test', '--test']; |
| 38 | + $envVars = ['some' => 'env']; |
| 39 | + |
| 40 | + $this->sut = new Command($binary, $runConfiguration, $arguments, $envVars, true); |
| 41 | + |
| 42 | + self::assertSame($binary, $this->sut->binary); |
| 43 | + self::assertSame($runConfiguration, $this->sut->runConfiguration); |
| 44 | + self::assertSame($arguments, $this->sut->arguments); |
| 45 | + self::assertSame($envVars, $this->sut->envVars); |
| 46 | + self::assertTrue($this->sut->sudo); |
| 47 | + } |
| 48 | + |
| 49 | + public function test__toString() : void { |
| 50 | + $this->sut->binary = 'some binary'; |
| 51 | + $this->sut->arguments = ['bla' => 'test', '--test']; |
| 52 | + $this->sut->envVars = ['some' => 'env', 'more' => 'vars']; |
| 53 | + $this->sut->sudo = true; |
| 54 | + |
| 55 | + self::assertEquals('some=env; more=vars; sudo some binary test --test', $this->sut->__toString()); |
| 56 | + } |
| 57 | + |
| 58 | + public function test__toString_withMinimalProperties() : void { |
| 59 | + $this->sut->binary = 'some binary'; |
| 60 | + |
| 61 | + self::assertEquals('some binary', $this->sut->__toString()); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGetRunConfiguration() : void { |
| 65 | + self::assertSame($this->sut->runConfiguration, $this->sut->getRunConfiguration()); |
| 66 | + } |
| 67 | +} |
0 commit comments