Skip to content

Commit

Permalink
Merge pull request #211 from tienvx/support-meta-data-in-path-generat…
Browse files Browse the repository at this point in the history
…e-command

Support meta data in path generate command
  • Loading branch information
tienvx committed Mar 24, 2019
2 parents 1230d76 + 43e624f commit 78ba358
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/Command/GeneratePathCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function configure()
->setDescription('Generate path from model.')
->setHelp('Generate path from model.')
->addArgument('model', InputArgument::REQUIRED, 'The model to generate.')
->addOption('generator', 'g', InputOption::VALUE_OPTIONAL, 'The generator to generate path from the model.', 'random');
->addOption('generator', 'g', InputOption::VALUE_OPTIONAL, 'The generator to generate path from the model.', 'random')
->addOption('meta-data', 'm', InputOption::VALUE_OPTIONAL, 'The meta data for the generator.');
}

public function setWorkflowRegistry(Registry $workflowRegistry)
Expand All @@ -70,6 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

$model = $input->getArgument('model');
$generatorName = $input->getOption('generator');
$metaData = $input->getOption('meta-data');
$generator = $this->generatorManager->getGenerator($generatorName);
$subject = $this->subjectManager->createSubject($model);
$subject->setTesting(true);
Expand All @@ -80,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$path->add(null, null, [$workflow->getDefinition()->getInitialPlace()]);

try {
foreach ($generator->getAvailableTransitions($workflow, $subject) as $transitionName) {
foreach ($generator->getAvailableTransitions($workflow, $subject, $metaData) as $transitionName) {
try {
if (!$generator->applyTransition($workflow, $subject, $transitionName)) {
throw new Exception(sprintf('Generator %s generated transition %s that can not be applied', $generatorName, $transitionName));
Expand Down
24 changes: 13 additions & 11 deletions tests/Command/GeneratePathCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Exception;
use Symfony\Component\Console\Tester\CommandTester;
use Tienvx\Bundle\MbtBundle\Generator\RandomGenerator;
use Tienvx\Bundle\MbtBundle\Graph\Path;

class GeneratePathCommandTest extends CommandTestCase
Expand Down Expand Up @@ -37,20 +36,23 @@ public function coverageData()
*/
public function testExecute($model, $generator, $transitionCoverage, $placeCoverage, $transitionCount, $placeCount)
{
$command = $this->application->find('mbt:path:generate');
$name = 'mbt:path:generate';
$input = [
'command' => $name,
'model' => $model,
'--generator' => $generator,
];
if ('random' === $generator) {
/** @var RandomGenerator $randomGenerator */
$randomGenerator = self::$container->get(RandomGenerator::class);
$randomGenerator->setTransitionCoverage($transitionCoverage);
$randomGenerator->setPlaceCoverage($placeCoverage);
$input['--meta-data'] = [
'maxPathLength' => 300,
'transitionCoverage' => $transitionCoverage,
'placeCoverage' => $placeCoverage,
];
}

$command = $this->application->find($name);
$commandTester = new CommandTester($command);
$commandTester->execute([
'command' => $command->getName(),
'model' => $model,
'--generator' => $generator,
]);
$commandTester->execute($input);

$output = $commandTester->getDisplay();
$path = Path::unserialize(json_decode($output, true));
Expand Down

0 comments on commit 78ba358

Please sign in to comment.