Skip to content

Commit edc5ce7

Browse files
author
Bastian Schwarz
committed
Implemented command
1 parent 3f2c9a5 commit edc5ce7

8 files changed

Lines changed: 274 additions & 1 deletion

File tree

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 130 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php-test-framework.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"psalm": "tools/psalm --threads=10 --long-progress",
3737
"composer-unused": "tools/composer-unused --no-progress --no-interaction",
3838
"composer-require-checker": "tools/composer-require-checker --no-interaction",
39-
"infection": "XDEBUG_MODE=coverage tools/infection --min-msi=95 --min-covered-msi=95 --threads=4 --no-progress --show-mutations",
39+
"infection": "XDEBUG_MODE=coverage tools/infection --min-msi=100 --min-covered-msi=100 --threads=4 --no-progress --show-mutations",
4040
"ci-all": [
4141
"@phpunit",
4242
"@psalm",
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\crontab\Command;
4+
5+
use de\codenamephp\deployer\command\iCommand;
6+
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;
7+
8+
/**
9+
* Interface for factories that create crontab commands, e.g. by getting the binary from deployer
10+
*
11+
* @psalm-api
12+
*/
13+
interface CrontabCommandFactoryInterface
14+
{
15+
/**
16+
* Implementations MUST make sure the command gets the correct binary (e.g. from deployer) and that all parameters are passed on correctly
17+
*
18+
* @param array<int, string> $options Array of arguments to pass to the command with numerical indexes so the arguments can be expanded, e.g. ['--production', '--fund=false']
19+
* @param string|null $file The file to use. Defaults to null which means the default crontab file will be used
20+
* @param bool $sudo Flag if the command should be executed as root
21+
* @param iRunConfiguration|null $runConfiguration The run configuration for the command. Defaults to an empty configuration
22+
* @return iCommand The command to run
23+
*/
24+
public function build(array $options = [], string $file = null, bool $sudo = false, iRunConfiguration $runConfiguration = null) : iCommand;
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\crontab\Command;
4+
5+
use de\codenamephp\deployer\base\functions\All;
6+
use de\codenamephp\deployer\base\functions\iGet;
7+
use de\codenamephp\deployer\command\Command;
8+
use de\codenamephp\deployer\command\iCommand;
9+
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;
10+
use de\codenamephp\deployer\command\runConfiguration\SimpleContainer;
11+
12+
/**
13+
* Gets the crontab binary from deployer and defaults to crontab if it is not set
14+
*
15+
* @psalm-api
16+
*/
17+
final class WithBinaryFromDeployer implements CrontabCommandFactoryInterface {
18+
19+
public function __construct(public iGet $deployer = new All()) {}
20+
21+
public function build(array $options = [], string $file = null, bool $sudo = false, iRunConfiguration $runConfiguration = null) : iCommand {
22+
return new Command(
23+
(string) $this->deployer->get('crontab:binary', 'crontab'),
24+
$options,
25+
[],
26+
$sudo,
27+
$runConfiguration ?? new SimpleContainer());
28+
}
29+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\crontab\test\Command;
4+
5+
use de\codenamephp\deployer\base\functions\All;
6+
use de\codenamephp\deployer\base\functions\iGet;
7+
use de\codenamephp\deployer\command\Command;
8+
use de\codenamephp\deployer\command\runConfiguration\iRunConfiguration;
9+
use de\codenamephp\deployer\command\runConfiguration\SimpleContainer;
10+
use de\codenamephp\deployer\crontab\Command\WithBinaryFromDeployer;
11+
use PHPUnit\Framework\TestCase;
12+
13+
final class WithBinaryFromDeployerTest extends TestCase {
14+
15+
public function test__construct() : void {
16+
$sut = new WithBinaryFromDeployer();
17+
18+
self::assertInstanceOf(All::class, $sut->deployer);
19+
}
20+
21+
public function test__construct_withOptionalArguments() : void {
22+
$deployer = $this->createMock(iGet::class);
23+
24+
$sut = new WithBinaryFromDeployer($deployer);
25+
26+
self::assertSame($deployer, $sut->deployer);
27+
}
28+
29+
public function testBuild() : void {
30+
$deployer = $this->createMock(iGet::class);
31+
$deployer->expects(self::once())->method('get')->with('crontab:binary', 'crontab')->willReturn('crontab');
32+
33+
$sut = new WithBinaryFromDeployer($deployer);
34+
35+
$command = $sut->build();
36+
37+
self::assertEquals(new Command('crontab', [], [], false, new SimpleContainer()), $command);
38+
}
39+
40+
public function testBuild_withOptionalArguments() : void {
41+
$deployer = $this->createMock(iGet::class);
42+
$deployer->expects(self::once())->method('get')->with('crontab:binary', 'crontab')->willReturn(null);
43+
44+
$sut = new WithBinaryFromDeployer($deployer);
45+
46+
$runConfiguration = $this->createMock(iRunConfiguration::class);
47+
48+
$command = $sut->build(['some', 'options'], 'someFile', true, $runConfiguration);
49+
50+
self::assertEquals(new Command('', ['some', 'options'], [], true, $runConfiguration), $command);
51+
}
52+
}

0 commit comments

Comments
 (0)