Skip to content

Commit 321df80

Browse files
Added task name and description interfaces to make it compatible with registerTask()
1 parent f84c239 commit 321df80

8 files changed

Lines changed: 69 additions & 5 deletions

File tree

.idea/runConfigurations/All.xml

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

src/task/AbstractFlowTask.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace de\codenamephp\deployer\flow\task;
44

5-
use de\codenamephp\deployer\base\task\iTask;
5+
use de\codenamephp\deployer\base\task\iTaskWithDescription;
6+
use de\codenamephp\deployer\base\task\iTaskWithName;
67
use de\codenamephp\deployer\command\runner\iRunner;
78
use de\codenamephp\deployer\command\runner\WithDeployerFunctions;
89
use de\codenamephp\deployer\flow\command\factory\iFlowCommandFactory;
@@ -13,7 +14,7 @@
1314
*
1415
* The flow command is created with the command factory using the command and arguments and run using the command runner
1516
*/
16-
abstract class AbstractFlowTask implements iTask {
17+
abstract class AbstractFlowTask implements iTaskWithName, iTaskWithDescription {
1718

1819
public function __construct(public iFlowCommandFactory $commandFactory = new WithBinaryFromDeployer(), public iRunner $commandRunner = new WithDeployerFunctions()) { }
1920

src/task/Generic.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
final class Generic extends AbstractFlowTask {
1515

1616
public function __construct(public string $command,
17+
public string $taskName,
1718
/** @var array<int,string> */
1819
public array $arguments = [],
20+
public string $taskDescription = '',
1921
iFlowCommandFactory $commandFactory = new WithBinaryFromDeployer(),
2022
iRunner $commandRunner = new WithDeployerFunctions()) {
2123
parent::__construct($commandFactory, $commandRunner);
@@ -28,4 +30,12 @@ public function getCommand() : string {
2830
public function getArguments() : array {
2931
return $this->arguments;
3032
}
33+
34+
public function getDescription() : string {
35+
return $this->taskDescription;
36+
}
37+
38+
public function getName() : string {
39+
return $this->taskName;
40+
}
3141
}

src/task/cache/Flush.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
final class Flush extends AbstractFlowTask {
1717

18+
public const NAME = 'flow:cache:flush';
19+
1820
public function __construct(public bool $force = false,
1921
iFlowCommandFactory $commandFactory = new WithBinaryFromDeployer(),
2022
iRunner $commandRunner = new WithDeployerFunctions()) {
@@ -28,4 +30,12 @@ public function getCommand() : string {
2830
public function getArguments() : array {
2931
return $this->force ? ['--force'] : [];
3032
}
33+
34+
public function getDescription() : string {
35+
return 'Flushes all configured caches.';
36+
}
37+
38+
public function getName() : string {
39+
return self::NAME;
40+
}
3141
}

src/task/cache/Warmup.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
*/
1212
final class Warmup extends AbstractFlowTask {
1313

14+
public const NAME = 'flow:cache:warmup';
15+
1416
public function getCommand() : string {
1517
return 'cache:warmup';
1618
}
1719

1820
public function getArguments() : array {
1921
return [];
2022
}
23+
24+
public function getDescription() : string {
25+
return 'Fills caches for the next request.';
26+
}
27+
28+
public function getName() : string {
29+
return self::NAME;
30+
}
2131
}

src/task/doctrine/Migrate.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
*/
1212
final class Migrate extends AbstractFlowTask {
1313

14+
public const NAME = 'flow:doctrine:migrate';
15+
1416
public function getCommand() : string {
1517
return 'doctrine:migrate';
1618
}
1719

1820
public function getArguments() : array {
1921
return [];
2022
}
23+
24+
public function getDescription() : string {
25+
return 'Runs the doctrine database migrations';
26+
}
27+
28+
public function getName() : string {
29+
return self::NAME;
30+
}
2131
}

src/task/resource/Publish.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,21 @@
1111
*/
1212
final class Publish extends AbstractFlowTask {
1313

14+
public const NAME = 'flow:resource:publish';
15+
1416
public function getCommand() : string {
1517
return 'resource:publish';
1618
}
1719

1820
public function getArguments() : array {
1921
return [];
2022
}
23+
24+
public function getDescription() : string {
25+
return 'Publish the resources to the public directory.';
26+
}
27+
28+
public function getName() : string {
29+
return self::NAME;
30+
}
2131
}

test/task/GenericTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,39 @@ final class GenericTest extends TestCase {
1616
protected function setUp() : void {
1717
parent::setUp();
1818

19-
$this->sut = new Generic('');
19+
$this->sut = new Generic('', '');
2020
}
2121

2222
public function test__construct() : void {
2323
$command = 'some command';
2424
$arguments = ['some', 'arguments'];
2525
$commandFactory = $this->createMock(iFlowCommandFactory::class);
2626
$commandRunner = $this->createMock(iRunner::class);
27+
$taskName = 'some task name';
28+
$taskDescription = 'some task description';
2729

28-
$this->sut = new Generic($command, $arguments, $commandFactory, $commandRunner);
30+
$this->sut = new Generic($command, $taskName, $arguments, $taskDescription, $commandFactory, $commandRunner);
2931

3032
self::assertSame($command, $this->sut->getCommand());
3133
self::assertSame($arguments, $this->sut->getArguments());
3234
self::assertSame($commandFactory, $this->sut->commandFactory);
3335
self::assertSame($commandRunner, $this->sut->commandRunner);
36+
self::assertSame($taskDescription, $this->sut->getDescription());
37+
self::assertSame($taskName, $this->sut->getName());
3438
}
3539

3640
public function test__construct_withoutOptionalArguments() : void {
3741
$command = 'some command';
42+
$taskName = 'some task name';
3843

39-
$this->sut = new Generic($command);
44+
$this->sut = new Generic($command, $taskName);
4045

4146
self::assertSame($command, $this->sut->getCommand());
4247
self::assertSame([], $this->sut->getArguments());
4348
self::assertInstanceOf(WithBinaryFromDeployer::class, $this->sut->commandFactory);
4449
self::assertInstanceOf(WithDeployerFunctions::class, $this->sut->commandRunner);
50+
self::assertSame($taskName, $this->sut->getName());
51+
self::assertSame('', $this->sut->getDescription());
4552
}
4653

4754
public function testGetCommand() : void {

0 commit comments

Comments
 (0)