Files
kimai/src/AppBundle/Command/RunUnitTestsCommand.php
Kevin Papst f8b390cbe2 Developer improvements, PhpCs, PhpUnit #42 (#43)
* improved dev fixtures with more diversity, more data, better testcases, user avatars #42
* added customer stats to dashboard, fixed column length for 3 widgets #42
* fixed empty alias - display empty message for new user #42
* unified-ui for "new" toolbar icon #42
* use kimai2_ as database prefix #42
* added customer stats to dashboard, fixed column length for 3 widgets #42
* fix long project/customer names in "currently active" navbar flyout" #42
* added services config for dev environment #42
* added command to run unit tests #42
* added command to run integration tests #42
* added command to run code sniffer #42
* added phpcs and phpunit to composer #42
* created tests directory #42
* fixed code sniffer warnings #42
* added function to switch result type from Pagerfanta to QueryBuilder #42
* dramatically reduced database calls by using custom joined query #42
* added command to install kimai dependencies #42
* added dev:reset command #42
2018-01-07 15:11:03 +01:00

95 lines
2.2 KiB
PHP

<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace AppBundle\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Command used to run all unit tests.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class RunUnitTestsCommand extends Command
{
/**
* @var string
*/
protected $rootDir;
/**
* RunCodeSnifferCommand constructor.
* @param $rootDir
*/
public function __construct($rootDir)
{
$this->rootDir = realpath($rootDir . '/../');
parent::__construct();
}
/**
* @inheritdoc
*/
protected function configure()
{
$this
->setName('kimai:dev:test-unit')
->setDescription('Run all unit tests')
->setHelp('This command will execute all unit tests. Skips all tests with "@group integration" annotation.')
;
}
/**
* @inheritdoc
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$this->executeTests($io, '/tests/AppBundle');
$this->executeTests($io, '/tests/TimesheetBundle');
}
/**
* @param $directory
* @return string
*/
protected function createPhpunitCmdLine($directory)
{
return $this->rootDir . '/bin/phpunit --exclude-group integration ' . $directory;
}
/**
* @param string $directory
*/
protected function executeTests(SymfonyStyle $io, $directory)
{
$directory = $this->rootDir . $directory;
$exitCode = 0;
ob_start();
passthru($this->createPhpunitCmdLine($directory), $exitCode);
$result = ob_get_clean();
$io->write($result);
if ($exitCode > 0) {
$io->error('Found problems while running tests at: ' . $directory);
} else {
$io->success('All tests performed good at: ' . $directory);
}
}
}