Skip to content

Commit

Permalink
Add dev:tests:run parameter to pass arguments to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
schmengler committed Sep 26, 2017
1 parent 0c0393d commit 8cfd414
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
Expand All @@ -22,10 +23,16 @@ class DevTestsRunCommand extends Command
*/
const INPUT_ARG_TYPE = 'type';

/**
* PHPUnit arguments parameter
*/
const INPUT_OPT_COMMAND_ARGUMENTS = 'arguments';
const INPUT_OPT_COMMAND_ARGUMENTS_SHORT = 'c';

/**
* command name
*/
const COMMAND_NAME = 'dev:tests:run';
const COMMAND_NAME = 'dev:tests:run';

/**
* Maps types (from user input) to phpunit test names
Expand Down Expand Up @@ -56,6 +63,13 @@ protected function configure()
'Type of test to run. Available types: ' . implode(', ', array_keys($this->types)),
'default'
);
$this->addOption(
self::INPUT_OPT_COMMAND_ARGUMENTS,
self::INPUT_OPT_COMMAND_ARGUMENTS_SHORT,
InputOption::VALUE_REQUIRED,
'Additional arguments for PHPUnit. Example: "-c\'--filter=MyTest\'" (no spaces)',
''
);

parent::configure();
}
Expand Down Expand Up @@ -87,6 +101,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
$dirName = realpath(BP . '/dev/tests/' . $dir);
chdir($dirName);
$command = PHP_BINARY . ' ' . BP . '/' . $vendorDir . '/phpunit/phpunit/phpunit ' . $options;
if ($commandArguments = $input->getOption(self::INPUT_OPT_COMMAND_ARGUMENTS)) {
$command .= ' ' . $commandArguments;
}
$message = $dirName . '> ' . $command;
$output->writeln(['', str_pad("---- {$message} ", 70, '-'), '']);
passthru($command, $returnVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,20 @@ public function testExecuteBadType()
$commandTester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'bad']);
$this->assertContains('Invalid type: "bad"', $commandTester->getDisplay());
}

public function testPassArgumentsToPHPUnit()
{
$commandTester = new CommandTester($this->command);
$commandTester->execute(
[
DevTestsRunCommand::INPUT_ARG_TYPE => 'unit',
'-' . DevTestsRunCommand::INPUT_OPT_COMMAND_ARGUMENTS_SHORT => '--list-suites',
]
);
$this->assertContains(
'phpunit --list-suites',
$commandTester->getDisplay(),
'Parameters should be passed to PHPUnit'
);
}
}

0 comments on commit 8cfd414

Please sign in to comment.