From c04504ca8ec1fbf9d446e9d1ae9c5cfa61668414 Mon Sep 17 00:00:00 2001 From: Jan Kiesewetter Date: Fri, 26 Jun 2020 22:11:31 +0200 Subject: [PATCH] [BUGFIX] Prevent PHP warning by checking the type Resolves: #412 --- src/Task/Neos/Flow/FlushCacheListTask.php | 22 ++++++++++------- .../Task/Neos/Flow/FlushCacheListTaskTest.php | 24 +++++++++++++++++-- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/Task/Neos/Flow/FlushCacheListTask.php b/src/Task/Neos/Flow/FlushCacheListTask.php index 4ec7f114..a2113c80 100644 --- a/src/Task/Neos/Flow/FlushCacheListTask.php +++ b/src/Task/Neos/Flow/FlushCacheListTask.php @@ -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'); diff --git a/tests/Unit/Task/Neos/Flow/FlushCacheListTaskTest.php b/tests/Unit/Task/Neos/Flow/FlushCacheListTaskTest.php index 0f0fb3dc..94f0a3f0 100644 --- a/tests/Unit/Task/Neos/Flow/FlushCacheListTaskTest.php +++ b/tests/Unit/Task/Neos/Flow/FlushCacheListTaskTest.php @@ -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 */ @@ -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 */