Skip to content

Commit f97ea10

Browse files
committed
Add options: coverage, group and ignore-tests
1 parent 462f1c8 commit f97ea10

5 files changed

Lines changed: 99 additions & 4 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "stable",
2929
"require": {
3030
"php": ">=5.5.0",
31-
"phpunit/phpunit": ">=4.0",
31+
"phpunit/phpunit": ">=4.0 <6",
3232
"phpunit/php-code-coverage": ">=2.2",
3333
"squizlabs/php_codesniffer": "2.*",
3434
"symfony/console": "^3.2",

src/Phug/DevTool/Command/CheckCommand.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ protected function configure()
1313
{
1414
$this->setName('check')
1515
->addOption('report', null, InputOption::VALUE_NONE)
16+
->addOption('coverage-text', null, InputOption::VALUE_NONE, 'Display coverage info?')
17+
->addOption('coverage-html', null, InputOption::VALUE_OPTIONAL, 'Save coverage info as HTML?', false)
18+
->addOption('coverage-clover', null, InputOption::VALUE_OPTIONAL, 'Save coverage info as XML?', false)
19+
->addOption('group', null, InputOption::VALUE_OPTIONAL, 'Excute only a tests group?', false)
20+
->addOption('ignore-tests', null, InputOption::VALUE_NONE)
1621
->setDescription('Runs all necessary checks.')
1722
->setHelp('Runs all necessary checks');
1823
}
@@ -22,10 +27,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
2227
$app = $this->getApplication();
2328
$coverageFilePath = $app->getWorkingDirectory().'/coverage.xml';
2429

25-
if (($code = $app->runCommand('unit-tests:run', $output, [
30+
$args = [
2631
'--coverage-text' => true,
2732
'--coverage-clover' => $coverageFilePath,
28-
])) !== 0) {
33+
];
34+
35+
if ($input->getOption('coverage-text')) {
36+
$args[] = '--coverage-text';
37+
}
38+
39+
if ($path = $input->getOption('coverage-clover')) {
40+
$args['--coverage-clover'] = $path;
41+
}
42+
43+
if ($path = $input->getOption('coverage-html')) {
44+
$args['--coverage-html'] = $path;
45+
}
46+
47+
if ($group = $input->getOption('group')) {
48+
$args['--group'] = $group;
49+
}
50+
51+
if (($code = $app->runCommand('unit-tests:run', $output, $args)) !== 0) {
2952
return $code;
3053
}
3154

@@ -48,6 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4871

4972
if (version_compare(PHP_VERSION, '5.6.0') >= 0 && ($code = $app->runCommand('code-style:check', $output, [
5073
'--no-interaction',
74+
'--ignore-tests' => $input->getOption('ignore-tests'),
5175
])) !== 0) {
5276
return $code;
5377
}

src/Phug/DevTool/Command/CodeStyleCheckCommand.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Phug\DevTool\AbstractCommand;
66
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Input\InputOption;
78
use Symfony\Component\Console\Output\OutputInterface;
89
use Symfony\Component\Console\Question\ConfirmationQuestion;
910

@@ -12,6 +13,7 @@ class CodeStyleCheckCommand extends AbstractCommand
1213
protected function configure()
1314
{
1415
$this->setName('code-style:check')
16+
->addOption('ignore-tests', null, InputOption::VALUE_NONE)
1517
->setDescription('Runs code style checker (phpcs).')
1618
->setHelp('This command runs the code style checker');
1719
}
@@ -22,6 +24,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
2224
$args = [
2325
'--standard' => $this->getApplication()->getConfigFilePath('phpcs.xml'),
2426
];
27+
if ($input->getOption('ignore-tests')) {
28+
$args[] = '--ignore=*/tests/*';
29+
}
2530

2631
if (($code = $this->getApplication()->runCodeStyleChecker($args)) === 0) {
2732
$output->writeln('<fg=green>Code looks great. Go on!</>');

src/Phug/DevTool/Command/UnitTestsRunCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ protected function configure()
1313
{
1414
$this->setName('unit-tests:run')
1515
->addOption('coverage-text', null, InputOption::VALUE_NONE, 'Display coverage info?')
16-
->addOption('coverage-clover', null, InputOption::VALUE_OPTIONAL, 'Save coverage info?', false)
16+
->addOption('coverage-html', null, InputOption::VALUE_OPTIONAL, 'Save coverage info as HTML?', false)
17+
->addOption('coverage-clover', null, InputOption::VALUE_OPTIONAL, 'Save coverage info as XML?', false)
18+
->addOption('group', null, InputOption::VALUE_OPTIONAL, 'Excute only a tests group?', false)
1719
->setDescription('Runs unit tests (phpunit).')
1820
->setHelp('This command runs the unit tests');
1921
}
@@ -33,6 +35,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
3335
$args['--coverage-clover'] = $path;
3436
}
3537

38+
if ($path = $input->getOption('coverage-html')) {
39+
$args['--coverage-html'] = $path;
40+
}
41+
42+
if ($group = $input->getOption('group')) {
43+
$args['--group'] = $group;
44+
}
45+
3646
return $this->getApplication()->runUnitTests($args);
3747
}
3848
}

tests/Phug/DevTool/Command/UnitTestsRunCommandTest.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Phug\Test\DevTool;
44

5+
use Phug\DevTool\Application;
56
use Phug\DevTool\Command\UnitTestsRunCommand;
7+
use Symfony\Component\Console\Input\StringInput;
8+
use Symfony\Component\Console\Output\BufferedOutput;
69

710
/**
811
* Class UnitTestsRunCommandTest.
@@ -11,6 +14,18 @@
1114
*/
1215
class UnitTestsRunCommandTest extends \PHPUnit_Framework_TestCase
1316
{
17+
private static function remove($entity)
18+
{
19+
if (is_file($entity)) {
20+
return unlink($entity);
21+
}
22+
23+
foreach (scandir($entity) as $file) {
24+
if ($file !== '.' && $file !== '..') {
25+
self::remove($entity.'/'.$file);
26+
}
27+
}
28+
}
1429
/**
1530
* @covers ::configure
1631
*/
@@ -20,4 +35,45 @@ public function testConfigure()
2035

2136
self::assertSame('unit-tests:run', $unitTests->getName());
2237
}
38+
39+
/**
40+
* @group i
41+
* @covers ::execute
42+
*/
43+
public function testExecute()
44+
{
45+
$cwd = getcwd();
46+
$app = realpath(__DIR__.'/../../../app');
47+
chdir($app);
48+
foreach (glob(__DIR__.'/../../../app/vendor/bin/*') as $file) {
49+
chmod($file, 0777);
50+
}
51+
$coverageHtml = $app.DIRECTORY_SEPARATOR.'coverage';
52+
$coverageClover = $app.DIRECTORY_SEPARATOR.'coverage.xml';
53+
if (file_exists($coverageClover)) {
54+
unlink($coverageClover);
55+
}
56+
$input = new StringInput(
57+
'unit-tests:run'.
58+
' --coverage-text'.
59+
' --coverage-html='.escapeshellarg(addslashes($coverageHtml)).
60+
' --coverage-clover='.escapeshellarg(addslashes($coverageClover))
61+
);
62+
$buffer = new BufferedOutput();
63+
$app = new Application();
64+
$app->setAutoExit(false);
65+
$code = $app->run($input, $buffer);
66+
exit($buffer->fetch());
67+
self::assertTrue(file_exists($coverageHtml));
68+
self::assertTrue(file_exists($coverageClover));
69+
if (file_exists($coverageHtml)) {
70+
self::remove($coverageHtml);
71+
}
72+
if (file_exists($coverageClover)) {
73+
unlink($coverageClover);
74+
}
75+
chdir($cwd);
76+
77+
self::assertRegExp('/test/', $buffer->fetch());
78+
}
2379
}

0 commit comments

Comments
 (0)