Skip to content

Commit

Permalink
FEATURE: Add a test to check the result of a sub command
Browse files Browse the repository at this point in the history
  • Loading branch information
johannessteu authored Jul 29, 2020
2 parents 325eea2 + 84e8352 commit 45bd478
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions Classes/Test/SubCommandTest.php
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);
}
}

0 comments on commit 45bd478

Please sign in to comment.