-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Add a test to check the result of a sub command
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace t3n\Flow\HealthStatus\Test; | ||
|
||
use Neos\Flow\Annotations as Flow; | ||
use Neos\Flow\Configuration\Exception\InvalidConfigurationException; | ||
use Neos\Flow\Core\Booting\Exception\SubProcessException; | ||
use Neos\Flow\Core\Booting\Scripts; | ||
|
||
/** | ||
* This file is part of the t3n.Flow.HealthStatus package. | ||
* | ||
* (c) 2018 yeebase media GmbH | ||
* | ||
* This package is Open Source Software. For the full copyright and license | ||
* information, please view the LICENSE file which was distributed with this | ||
* source code. | ||
*/ | ||
class SubCommandTest extends AbstractTest | ||
{ | ||
/** | ||
* @Flow\InjectConfiguration(package="Neos.Flow") | ||
* | ||
* @var string[][] | ||
*/ | ||
protected $flowSettings; | ||
|
||
/** | ||
* @param mixed[] $options | ||
* | ||
* @throws InvalidConfigurationException | ||
*/ | ||
protected function validateOptions(array $options): void | ||
{ | ||
if (! isset($options['commandIdentifier'])) { | ||
throw new InvalidConfigurationException('The command identifier of the sub-command to execute must be provided', 1596028979); | ||
} | ||
} | ||
|
||
/** | ||
* @throws SubProcessException | ||
*/ | ||
public function test(): bool | ||
{ | ||
return $this->dispatchCommand( | ||
$this->options['commandIdentifier'], | ||
$this->options['commandArguments'] ?? [], | ||
$this->options['commandContext'] ?? '' | ||
); | ||
} | ||
|
||
/** | ||
* @param string $commandIdentifier the identifier of the flow command | ||
* @param string[] $commandArguments | ||
* @param string $commandContext the context the sub command runs in | ||
* | ||
* @throws SubProcessException | ||
*/ | ||
private function dispatchCommand(string $commandIdentifier, array $commandArguments = [], string $commandContext = ''): bool | ||
{ | ||
if (! empty($commandContext)) { | ||
$this->flowSettings['core']['context'] = $commandContext; | ||
} | ||
|
||
return Scripts::executeCommand($commandIdentifier, $this->flowSettings, true, $commandArguments); | ||
} | ||
} |