Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Prevent PHP warning by checking the type #413

Merged
merged 1 commit into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/Task/Neos/Flow/FlushCacheListTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ public function simulate(Node $node, Application $application, Deployment $deplo

protected function resolveOptions(OptionsResolver $resolver)
{
$resolver->setRequired('flushCacheList');
$resolver->setAllowedValues('flushCacheList', static function ($value) {
return trim($value) !== '';
});

$resolver->setNormalizer('flushCacheList', static function (Options $options, $value) {
return is_array($value) ? $value : explode(',', $value);
});
$resolver->setRequired('flushCacheList')
->setAllowedTypes('flushCacheList', ['array', 'string'])
->setNormalizer('flushCacheList', static function (Options $options, $value) {
return is_array($value) ? $value : explode(',', $value);
})
->setAllowedValues('flushCacheList', static function ($value) {
if (is_array($value)) {
return !empty($value);
}
if (is_string($value)) {
return trim($value) !== '';
}
return false;
});

$resolver->setDefault('phpBinaryPathAndFilename', 'php')
->setAllowedTypes('phpBinaryPathAndFilename', 'string');
Expand Down
24 changes: 22 additions & 2 deletions tests/Unit/Task/Neos/Flow/FlushCacheListTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,23 @@ public function noFlowApplicationGivenThrowsException()
/**
* @test
*/
public function requiredOptionFlushCacheListNotGivenThrowsException()
public function requiredOptionFlushCacheListWithEmptyStringThrowsException()
{
$this->expectException(InvalidConfigurationException::class);
$this->application = new Flow();
$this->task->execute($this->node, $this->application, $this->deployment, ['flushCacheList' => '']);
}

/**
* @test
*/
public function requiredOptionFlushCacheListWithEmptyArrayThrowsException()
{
$this->expectException(InvalidConfigurationException::class);
$this->application = new Flow();
$this->task->execute($this->node, $this->application, $this->deployment, ['flushCacheList' => []]);
}

/**
* @test
*/
Expand All @@ -51,13 +61,23 @@ public function tooLowFlowVersionThrowsException()
/**
* @test
*/
public function executeSuccessfully()
public function executeSuccessfullyWithString()
{
$this->application = new Flow();
$this->task->execute($this->node, $this->application, $this->deployment, ['flushCacheList' => 'list']);
$this->assertCommandExecuted(sprintf('cd /releases/%s && FLOW_CONTEXT=Production php ./flow neos.flow:cache:flushone \'--identifier\' \'list\'', $this->deployment->getReleaseIdentifier()));
}

/**
* @test
*/
public function executeSuccessfullyWithArray()
{
$this->application = new Flow();
$this->task->execute($this->node, $this->application, $this->deployment, ['flushCacheList' => ['list']]);
$this->assertCommandExecuted(sprintf('cd /releases/%s && FLOW_CONTEXT=Production php ./flow neos.flow:cache:flushone \'--identifier\' \'list\'', $this->deployment->getReleaseIdentifier()));
}

/**
* @return FlushCacheListTask
*/
Expand Down