|
| 1 | +<?php declare(strict_types=1); |
| 2 | + |
| 3 | +namespace de\codenamephp\deployer\crontab\test\Task; |
| 4 | + |
| 5 | +use de\codenamephp\deployer\command\iCommand; |
| 6 | +use de\codenamephp\deployer\command\runner\iRunner; |
| 7 | +use de\codenamephp\deployer\command\runner\WithDeployerFunctions; |
| 8 | +use de\codenamephp\deployer\crontab\Command\CrontabCommandFactoryInterface; |
| 9 | +use de\codenamephp\deployer\crontab\Command\WithBinaryFromDeployer; |
| 10 | +use de\codenamephp\deployer\crontab\Task\AbstractCrontabCommand; |
| 11 | +use de\codenamephp\deployer\crontab\Task\HasOptionsInterface; |
| 12 | +use Mockery; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | + |
| 15 | +final class AbstractCrontabCommandTest extends TestCase { |
| 16 | + |
| 17 | + use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
| 18 | + |
| 19 | + public function testGetOptionsWithUser() : void { |
| 20 | + $sut = $this->getMockForAbstractClass(AbstractCrontabCommand::class); |
| 21 | + |
| 22 | + self::assertSame([], $sut->getOptionsWithUser()); |
| 23 | + } |
| 24 | + |
| 25 | + public function testGetOptionsWithUser_withSetUser() : void { |
| 26 | + $sut = $this->getMockForAbstractClass(AbstractCrontabCommand::class, ['some user']); |
| 27 | + |
| 28 | + self::assertSame(['-u some user'], $sut->getOptionsWithUser()); |
| 29 | + } |
| 30 | + |
| 31 | + public function testGetOptionsWithUser_withSetUser_andOptions() : void { |
| 32 | + $sut = Mockery::mock(AbstractCrontabCommand::class, HasOptionsInterface::class, ['some user'])->makePartial(); |
| 33 | + $sut->allows('getOptions')->once()->andReturn(['some option']); |
| 34 | + |
| 35 | + self::assertSame(['some option', '-u some user'], $sut->getOptionsWithUser()); |
| 36 | + } |
| 37 | + |
| 38 | + public function test__construct() : void { |
| 39 | + $sut = $this->getMockForAbstractClass(AbstractCrontabCommand::class); |
| 40 | + |
| 41 | + self::assertNull($sut->user); |
| 42 | + self::assertInstanceOf(WithBinaryFromDeployer::class, $sut->crontabCommandFactory); |
| 43 | + self::assertInstanceOf(WithDeployerFunctions::class, $sut->commandRunner); |
| 44 | + } |
| 45 | + |
| 46 | + public function test__construct_withOptionalArguments() : void { |
| 47 | + $user = 'some user'; |
| 48 | + $crontabCommandFactory = $this->createMock(CrontabCommandFactoryInterface::class); |
| 49 | + $commandRunner = $this->createMock(iRunner::class); |
| 50 | + |
| 51 | + $sut = $this->getMockForAbstractClass(AbstractCrontabCommand::class, [$user, $crontabCommandFactory, $commandRunner]); |
| 52 | + |
| 53 | + self::assertSame($user, $sut->user); |
| 54 | + self::assertSame($crontabCommandFactory, $sut->crontabCommandFactory); |
| 55 | + self::assertSame($commandRunner, $sut->commandRunner); |
| 56 | + } |
| 57 | + |
| 58 | + public function test__invoke() : void { |
| 59 | + $user = 'some user'; |
| 60 | + $command = $this->createMock(iCommand::class); |
| 61 | + |
| 62 | + $crontabCommandFactory = $this->createMock(CrontabCommandFactoryInterface::class); |
| 63 | + $crontabCommandFactory->expects(self::once())->method('build')->with(['-u some user'])->willReturn($command); |
| 64 | + |
| 65 | + $commandRunner = $this->createMock(iRunner::class); |
| 66 | + $commandRunner->expects(self::once())->method('run')->with($command); |
| 67 | + |
| 68 | + $sut = $this->getMockForAbstractClass(AbstractCrontabCommand::class, [$user, $crontabCommandFactory, $commandRunner]); |
| 69 | + $sut->__invoke(); |
| 70 | + } |
| 71 | +} |
0 commit comments