Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-10-10 02:15:04 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-10-10 02:15:04 +0400
commita001d3c9d42f8a06cb9e6272e897aace5e870747 (patch)
treea3e38eef7de606f592a49944fd221d46b417fe05 /plugins
parent5b79f746876e24e1171c5cbfc25c5cfb21e87e36 (diff)
refs #5940 fix tests:run as it worked based on groups before which did not really make sense. Testsuite and groups can be combined now if wanted. By default will execute all testsuites after another
Diffstat (limited to 'plugins')
-rw-r--r--plugins/CoreConsole/Commands/CodeCoverage.php9
-rw-r--r--plugins/CoreConsole/Commands/TestsRun.php90
2 files changed, 76 insertions, 23 deletions
diff --git a/plugins/CoreConsole/Commands/CodeCoverage.php b/plugins/CoreConsole/Commands/CodeCoverage.php
index ff668efdb1..6dbc2004c0 100644
--- a/plugins/CoreConsole/Commands/CodeCoverage.php
+++ b/plugins/CoreConsole/Commands/CodeCoverage.php
@@ -13,6 +13,7 @@ use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
@@ -23,6 +24,7 @@ class CodeCoverage extends ConsoleCommand
{
$this->setName('tests:coverage');
$this->setDescription('Run all phpunit tests and generate a combined code coverage');
+ $this->addOption('testsuite', null, InputOption::VALUE_REQUIRED, 'Run only a specific test suite, for instance UnitTests, IntegrationTests or SystemTests.');
$this->addArgument('group', InputArgument::OPTIONAL, 'Run only a specific test group. Separate multiple groups by comma, for instance core,plugins', '');
}
@@ -39,9 +41,14 @@ class CodeCoverage extends ConsoleCommand
$command = $this->getApplication()->find('tests:run');
$arguments = array(
'command' => 'tests:run',
- '--options' => sprintf('--coverage-php %s/tests/results/logs/%%group%%.cov', PIWIK_DOCUMENT_ROOT),
+ '--options' => sprintf('--coverage-php %s/tests/results/logs/%%suite%%%%group%%.cov', PIWIK_DOCUMENT_ROOT),
);
+ $suite = $input->getOption('testsuite');
+ if (!empty($suite)) {
+ $arguments['--testsuite'] = $suite;
+ }
+
$groups = $input->getArgument('group');
if (!empty($groups)) {
$arguments['group'] = $groups;
diff --git a/plugins/CoreConsole/Commands/TestsRun.php b/plugins/CoreConsole/Commands/TestsRun.php
index de32f0b534..da52369299 100644
--- a/plugins/CoreConsole/Commands/TestsRun.php
+++ b/plugins/CoreConsole/Commands/TestsRun.php
@@ -9,6 +9,7 @@
namespace Piwik\Plugins\CoreConsole\Commands;
+use Piwik\Common;
use Piwik\Profiler;
use Piwik\Plugin\ConsoleCommand;
use Symfony\Component\Console\Input\InputArgument;
@@ -24,12 +25,12 @@ class TestsRun extends ConsoleCommand
protected function configure()
{
$this->setName('tests:run');
- $this->setDescription('Run Piwik PHPUnit tests one group after the other');
+ $this->setDescription('Run Piwik PHPUnit tests one testsuite after the other');
$this->addArgument('group', InputArgument::OPTIONAL, 'Run only a specific test group. Separate multiple groups by comma, for instance core,plugins', '');
$this->addOption('options', 'o', InputOption::VALUE_OPTIONAL, 'All options will be forwarded to phpunit', '');
$this->addOption('xhprof', null, InputOption::VALUE_NONE, 'Profile using xhprof.');
$this->addOption('file', null, InputOption::VALUE_REQUIRED, 'Execute tests within this file. Should be a path relative to the tests/PHPUnit directory.');
- $this->addOption('suite', null, InputOption::VALUE_REQUIRED, 'Execute tests of a specific test suite, for instance UnitTests, IntegrationTests or SystemTests.');
+ $this->addOption('testsuite', null, InputOption::VALUE_REQUIRED, 'Execute tests of a specific test suite, for instance UnitTests, IntegrationTests or SystemTests.');
}
protected function execute(InputInterface $input, OutputInterface $output)
@@ -38,7 +39,6 @@ class TestsRun extends ConsoleCommand
$groups = $input->getArgument('group');
$groups = explode(",", $groups);
- $groups = array_map('ucfirst', $groups);
$groups = array_filter($groups, 'strlen');
$command = '../../vendor/phpunit/phpunit/phpunit';
@@ -82,7 +82,7 @@ class TestsRun extends ConsoleCommand
if (!empty($testFile)) {
$this->executeTestFile($testFile, $options, $command, $output);
} else {
- $suite = $input->getOption('suite');
+ $suite = $this->getTestsuite($input);
$this->executeTestGroups($suite, $groups, $options, $command, $output);
}
}
@@ -98,27 +98,26 @@ class TestsRun extends ConsoleCommand
private function executeTestGroups($suite, $groups, $options, $command, OutputInterface $output)
{
- if (empty($groups)) {
- $groups = $this->getTestsGroups();
- }
-
- foreach ($groups as $group) {
- $params = '--group ' . $group . ' ' . str_replace('%group%', $group, $options);
-
- if (!empty($suite)) {
- $params .= ' --testsuite ' . $suite;
+ if (empty($suite) && empty($groups)) {
+ foreach ($this->getTestsSuites() as $suite) {
+ if (Common::stringEndsWith($suite, 'Tests')) {
+ $this->executeTestGroups($suite, $groups, $options, $command, $output);
+ }
}
-
- $cmd = $this->getCommand($command, $params);
- $output->writeln('Executing command: <info>' . $cmd . '</info>');
- passthru($cmd);
- $output->writeln("");
+
+ return;
}
+
+ $params = $this->buildPhpUnitCliParams($suite, $groups, $options);
+ $cmd = $this->getCommand($command, $params);
+ $output->writeln('Executing command: <info>' . $cmd . '</info>');
+ passthru($cmd);
+ $output->writeln("");
}
- private function getTestsGroups()
+ private function getTestsSuites()
{
- return array('Core', 'Plugins', 'UI');
+ return array('unit', 'UnitTests', 'integration', 'IntegrationTests', 'system', 'SystemTests');
}
/**
@@ -128,7 +127,54 @@ class TestsRun extends ConsoleCommand
*/
private function getCommand($command, $params)
{
- $cmd = sprintf('cd %s/tests/PHPUnit && %s %s', PIWIK_DOCUMENT_ROOT, $command, $params);
- return $cmd;
+ return sprintf('cd %s/tests/PHPUnit && %s %s', PIWIK_DOCUMENT_ROOT, $command, $params);
+ }
+
+ private function buildPhpUnitCliParams($suite, $groups, $options)
+ {
+ $params = $options;
+
+ if (!empty($groups)) {
+ $groups = implode(',', $groups);
+ $params .= '--group ' . $groups . ' ';
+ } else {
+ $groups = '';
+ }
+
+ if (!empty($suite)) {
+ $params .= ' --testsuite ' . $suite;
+ } else {
+ $suite = '';
+ }
+
+ $params = str_replace('%suite%', $suite, $params);
+ $params = str_replace('%group%', $groups, $params);
+
+ return $params;
+ }
+
+ private function getTestsuite(InputInterface $input)
+ {
+ $suite = $input->getOption('testsuite');
+
+ if (empty($suite)) {
+ return;
+ }
+
+ $suite = ucfirst($suite);
+
+ if (Common::stringEndsWith($suite, 'tests')) {
+ $suite = str_replace('tests', 'Tests', $suite);
+ } elseif (strpos($suite, 'Tests') === false) {
+ $suite = $suite . 'Tests';
+ }
+
+ $availableSuites = $this->getTestsSuites();
+
+ if (!in_array($suite, $availableSuites)) {
+ throw new \InvalidArgumentException('Invalid testsuite specified. Use one of: ' . implode(', ', $availableSuites));
+ }
+
+ return $suite;
}
} \ No newline at end of file