Skip to content

Commit 17eb0be

Browse files
Added repair command
1 parent b9aa2f5 commit 17eb0be

4 files changed

Lines changed: 158 additions & 0 deletions

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/runConfigurations/Run.xml

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

src/task/node/Repair.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\flow\task\node;
4+
5+
use de\codenamephp\deployer\command\runner\iRunner;
6+
use de\codenamephp\deployer\command\runner\WithDeployerFunctions;
7+
use de\codenamephp\deployer\flow\command\factory\iFlowCommandFactory;
8+
use de\codenamephp\deployer\flow\command\factory\WithBinaryFromDeployer;
9+
use de\codenamephp\deployer\flow\task\AbstractFlowTask;
10+
11+
/**
12+
* Command that runs the repair command to bring nodes up to date (add new properties, set defaults, ...), fix structure, remove orphans etc.
13+
*
14+
* @see https://neos.readthedocs.io/en/stable/References/CommandReference.html#neos-contentrepository-node-repair
15+
*/
16+
final class Repair extends AbstractFlowTask {
17+
18+
public const NAME = 'flow:node:repair';
19+
20+
public function __construct(public string $nodeType = '',
21+
public string $workspace = '',
22+
public bool $dryRun = false,
23+
public bool $skipCleanup = false,
24+
/** @var array<string> */
25+
public array $skipChecks = [],
26+
/** @var array<string> */
27+
public array $onlyChecks = [],
28+
iFlowCommandFactory $commandFactory = new WithBinaryFromDeployer(),
29+
iRunner $commandRunner = new WithDeployerFunctions()) {
30+
parent::__construct($commandFactory, $commandRunner);
31+
}
32+
33+
public function getCommand() : string {
34+
return 'node:repair';
35+
}
36+
37+
public function getArguments() : array {
38+
$params = array_filter([
39+
'--node-type' => $this->nodeType,
40+
'--workspace' => $this->workspace,
41+
'--dry-run' => $this->dryRun,
42+
'--cleanup' => $this->skipCleanup,
43+
'--skip' => implode(',', $this->skipChecks),
44+
'--only' => implode(',', $this->onlyChecks),
45+
]);
46+
return array_map(static fn(string $name, string|bool $value) : string => is_string($value) ? sprintf('%s %s', $name, $value) : $name, array_keys($params), $params);
47+
}
48+
49+
public function getDescription() : string {
50+
return 'Repair inconsistent nodes';
51+
}
52+
53+
public function getName() : string {
54+
return self::NAME;
55+
}
56+
}

test/task/node/RepairTest.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace de\codenamephp\deployer\flow\test\task\node;
4+
5+
use de\codenamephp\deployer\command\runner\iRunner;
6+
use de\codenamephp\deployer\command\runner\WithDeployerFunctions;
7+
use de\codenamephp\deployer\flow\command\factory\iFlowCommandFactory;
8+
use de\codenamephp\deployer\flow\command\factory\WithBinaryFromDeployer;
9+
use de\codenamephp\deployer\flow\task\node\Repair;
10+
use PHPUnit\Framework\TestCase;
11+
12+
final class RepairTest extends TestCase {
13+
14+
private Repair $sut;
15+
16+
protected function setUp() : void {
17+
parent::setUp();
18+
19+
$this->sut = new Repair();
20+
}
21+
22+
public function testGetArguments() : void {
23+
self::assertEquals([], $this->sut->getArguments());
24+
}
25+
26+
public function testGetArguments_withNonDefaultValues() : void {
27+
$this->sut->nodeType = 'some node type';
28+
$this->sut->workspace = 'some workspace';
29+
$this->sut->dryRun = true;
30+
$this->sut->skipCleanup = true;
31+
$this->sut->skipChecks = ['check1', 'check2'];
32+
$this->sut->onlyChecks = ['check3', 'check4'];
33+
34+
self::assertEquals([
35+
'--node-type some node type',
36+
'--workspace some workspace',
37+
'--dry-run',
38+
'--cleanup',
39+
'--skip check1,check2',
40+
'--only check3,check4',
41+
], $this->sut->getArguments());
42+
}
43+
44+
public function testGetCommand() : void {
45+
self::assertEquals('node:repair', $this->sut->getCommand());
46+
}
47+
48+
public function testGetName() : void {
49+
self::assertEquals(Repair::NAME, $this->sut->getName());
50+
}
51+
52+
public function test__construct() : void {
53+
$this->sut = new Repair();
54+
55+
self::assertSame('', $this->sut->nodeType);
56+
self::assertSame('', $this->sut->workspace);
57+
self::assertFalse($this->sut->dryRun);
58+
self::assertFalse($this->sut->skipCleanup);
59+
self::assertSame([], $this->sut->skipChecks);
60+
self::assertSame([], $this->sut->onlyChecks);
61+
self::assertInstanceOf(WithBinaryFromDeployer::class, $this->sut->commandFactory);
62+
self::assertInstanceOf(WithDeployerFunctions::class, $this->sut->commandRunner);
63+
}
64+
65+
public function test__construct_withoutOptionalArguments() : void {
66+
$commandFactory = $this->createMock(iFlowCommandFactory::class);
67+
$commandRunner = $this->createMock(iRunner::class);
68+
69+
$this->sut = new Repair('some node type', 'some workspace', true, true, ['check1', 'check2'], ['check3', 'check4'], $commandFactory, $commandRunner);
70+
71+
self::assertSame('some node type', $this->sut->nodeType);
72+
self::assertSame('some workspace', $this->sut->workspace);
73+
self::assertTrue($this->sut->dryRun);
74+
self::assertTrue($this->sut->skipCleanup);
75+
self::assertSame(['check1', 'check2'], $this->sut->skipChecks);
76+
self::assertSame(['check3', 'check4'], $this->sut->onlyChecks);
77+
self::assertSame($commandFactory, $this->sut->commandFactory);
78+
self::assertSame($commandRunner, $this->sut->commandRunner);
79+
}
80+
81+
public function testGetDescription() : void {
82+
self::assertSame('Repair inconsistent nodes', $this->sut->getDescription());
83+
}
84+
}

0 commit comments

Comments
 (0)