Skip to content

Commit 1cf9081

Browse files
author
Bastian Schwarz
committed
Implemented install task
1 parent 6847210 commit 1cf9081

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

src/Task/Install.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\crontab\Task;
4+
5+
use de\codenamephp\deployer\base\task\iTaskWithDescription;
6+
use de\codenamephp\deployer\base\task\iTaskWithName;
7+
use de\codenamephp\deployer\command\runner\iRunner;
8+
use de\codenamephp\deployer\command\runner\WithDeployerFunctions;
9+
use de\codenamephp\deployer\crontab\Command\CrontabCommandFactoryInterface;
10+
use de\codenamephp\deployer\crontab\Command\WithBinaryFromDeployer;
11+
12+
/**
13+
* Installs the given crontab file
14+
*
15+
* @psalm-api
16+
*/
17+
final class Install extends AbstractCrontabCommand implements iTaskWithName, iTaskWithDescription, HasOptionsInterface {
18+
19+
public const NAME = 'crontab:install';
20+
21+
public function __construct(
22+
public readonly string $file = '{{release_or_current_path}}/crontab',
23+
?string $user = null,
24+
CrontabCommandFactoryInterface $crontabCommandFactory = new WithBinaryFromDeployer(),
25+
iRunner $commandRunner = new WithDeployerFunctions()
26+
) {
27+
parent::__construct($user, $crontabCommandFactory, $commandRunner);
28+
}
29+
30+
public function getOptions() : array {
31+
return [$this->file];
32+
}
33+
34+
public function getDescription() : string {
35+
return 'Installs the given crontab file.';
36+
}
37+
38+
public function getName() : string {
39+
return self::NAME;
40+
}
41+
}

test/Task/InstallTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\crontab\test\Task;
4+
5+
use de\codenamephp\deployer\command\runner\iRunner;
6+
use de\codenamephp\deployer\command\runner\WithDeployerFunctions;
7+
use de\codenamephp\deployer\crontab\Command\CrontabCommandFactoryInterface;
8+
use de\codenamephp\deployer\crontab\Command\WithBinaryFromDeployer;
9+
use de\codenamephp\deployer\crontab\Task\Install;
10+
use PHPUnit\Framework\TestCase;
11+
12+
final class InstallTest extends TestCase {
13+
14+
public function testGetName() : void {
15+
self::assertSame(Install::NAME, (new Install())->getName());
16+
}
17+
18+
public function testGetOptions() : void {
19+
self::assertSame(['some file'], (new Install('some file'))->getOptions());
20+
}
21+
22+
public function testGetDescription() : void {
23+
self::assertSame('Installs the given crontab file.', (new Install())->getDescription());
24+
}
25+
26+
public function test__construct() : void {
27+
$sut = new Install();
28+
29+
self::assertSame('{{release_or_current_path}}/crontab', $sut->file);
30+
self::assertNull($sut->user);
31+
self::assertInstanceOf(WithBinaryFromDeployer::class, $sut->crontabCommandFactory);
32+
self::assertInstanceOf(WithDeployerFunctions::class, $sut->commandRunner);
33+
}
34+
public function test__construct_WithOptionalArguments() : void {
35+
$commandFactory = $this->createMock(CrontabCommandFactoryInterface::class);
36+
$commandRunner = $this->createMock(iRunner::class);
37+
38+
$sut = new Install('some file', 'some user', $commandFactory, $commandRunner);
39+
40+
self::assertSame('some file', $sut->file);
41+
self::assertSame('some user', $sut->user);
42+
self::assertSame($commandFactory, $sut->crontabCommandFactory);
43+
self::assertSame($commandRunner, $sut->commandRunner);
44+
}
45+
}

0 commit comments

Comments
 (0)