Skip to content

Commit

Permalink
Register test command (#2657)
Browse files Browse the repository at this point in the history
* first approximation to register test

* register test

* register test

* register test

* register test

* Test_discovery

* Test_discovery

* Test_discovery

* Test_discovery

* Test_discovery

* Test debug command

* Test debug command

* annotations

* annotations

* annotations

* service @app.root
  • Loading branch information
novia713 authored and jmolivas committed Sep 9, 2016
1 parent 5c154c6 commit fe30430
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 23 deletions.
20 changes: 11 additions & 9 deletions config/services/drupal-console/test.yml
@@ -1,9 +1,11 @@
#services:
# test_debug:
# class: Drupal\Console\Command\Test\DebugCommand
# tags:
# - { name: console.command }
# test_run:
# class: Drupal\Console\Command\Test\RunCommand
# tags:
# - { name: console.command }
services:
test_debug:
class: Drupal\Console\Command\Test\DebugCommand
arguments: ['@test_discovery']
tags:
- { name: console.command }
test_run:
class: Drupal\Console\Command\Test\RunCommand
arguments: ['@app.root', '@test_discovery', '@module_handler', '@date.formatter']
tags:
- { name: console.command }
37 changes: 30 additions & 7 deletions src/Command/Test/DebugCommand.php
Expand Up @@ -13,25 +13,48 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Component\Serialization\Yaml;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Annotation\DrupalCommand;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Annotations\DrupalCommand;
use Drupal\Console\Style\DrupalStyle;
use Drupal\simpletest\TestDiscovery;

/**
* Class DebugCommand
* @package Drupal\Console\Command\Test
*/
class DebugCommand extends Command
{
use ContainerAwareCommandTrait;
use CommandTrait;

/**
* @DrupalCommand(
* extension = "test",
* extensionType = "module",
* dependencies = {
* “simpletest"
* }
* )
*/


/**
* @var TestDiscovery
*/
protected $test_discovery;


/**
* DebugCommand constructor.
* @param TestDiscovery $test_discovery
*/
public function __construct(
TestDiscovery $test_discovery
) {
$this->test_discovery = $test_discovery;
parent::__construct();
}


protected function configure()
{
$this
Expand All @@ -58,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new DrupalStyle($input, $output);
//Registers namespaces for disabled modules.
$this->getDrupalService('test_discovery')->registerTestNamespaces();
$this->test_discovery->registerTestNamespaces();

$testClass = $input->getOption('test-class');
$group = $input->getArgument('group');
Expand All @@ -72,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function testDetail(DrupalStyle $io, $test_class)
{
$testingGroups = $this->getDrupalService('test_discovery')->getTestClasses(null);
$testingGroups = $this->test_discovery->getTestClasses(null);

$testDetails = null;
foreach ($testingGroups as $testing_group => $tests) {
Expand All @@ -93,7 +116,7 @@ private function testDetail(DrupalStyle $io, $test_class)
if (is_subclass_of($testDetails['name'], 'PHPUnit_Framework_TestCase')) {
$testDetails['type'] = 'phpunit';
} else {
$testDetails = $this->getDrupalService('test_discovery')
$testDetails = $this->test_discovery
->getTestInfo($testDetails['name']);
$testDetails['type'] = 'simpletest';
}
Expand Down Expand Up @@ -123,7 +146,7 @@ private function testDetail(DrupalStyle $io, $test_class)

protected function testList(DrupalStyle $io, $group)
{
$testingGroups = $this->getDrupalService('test_discovery')
$testingGroups = $this->test_discovery
->getTestClasses(null);

if (empty($group)) {
Expand Down
63 changes: 56 additions & 7 deletions src/Command/Test/RunCommand.php
Expand Up @@ -13,21 +13,70 @@
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Component\Utility\Timer;
use Symfony\Component\Console\Command\Command;
use Drupal\Console\Command\Shared\ContainerAwareCommandTrait;
use Drupal\Console\Annotation\DrupalCommand;
use Drupal\Console\Command\Shared\CommandTrait;
use Drupal\Console\Annotations\DrupalCommand;
use Drupal\Console\Style\DrupalStyle;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\simpletest\TestDiscovery;
use Drupal\Core\Datetime\DateFormatter;

class RunCommand extends Command
{
use ContainerAwareCommandTrait;
use CommandTrait;

/**
* @DrupalCommand(
* extension = "test",
* extensionType = "module",
* dependencies = {
* “simpletest"
* }
* )
*/

/**
* @var string
*/
protected $appRoot;

/**
* @var TestDiscovery
*/
protected $test_discovery;


/**
* @var ModuleHandlerInterface
*/
protected $moduleHandler;


/**
* @var DateFormatter
*/
protected $dateFormatter;



/**
* RunCommand constructor.
* @param Site $site
* @param TestDiscovery $test_discovery
* @param ModuleHandlerInterface $moduleHandler
*/
public function __construct(
$appRoot,
TestDiscovery $test_discovery,
ModuleHandlerInterface $moduleHandler,
DateFormatter $dateFormatter
) {
$this->appRoot = $appRoot;
$this->test_discovery = $test_discovery;
$this->moduleHandler = $moduleHandler;
$this->dateFormatter = $dateFormatter;
parent::__construct();
}

protected function configure()
{
$this
Expand Down Expand Up @@ -63,7 +112,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new DrupalStyle($input, $output);

//Registers namespaces for disabled modules.
$this->getDrupalService('test_discovery')->registerTestNamespaces();
$this->test_discovery->registerTestNamespaces();

$testClass = $input->getArgument('test-class');
$testMethods = $input->getArgument('test-methods');
Expand Down Expand Up @@ -106,7 +155,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$end = Timer::stop('run-tests');

$io->simple(
$this->trans('commands.test.run.messages.test-duration') . ': ' . \Drupal::service('date.formatter')->formatInterval($end['time'] / 1000)
$this->trans('commands.test.run.messages.test-duration') . ': ' . $this->dateFormatter->formatInterval($end['time'] / 1000)
);
$io->simple(
$this->trans('commands.test.run.messages.test-pass') . ': ' . $test->results['#pass']
Expand All @@ -121,7 +170,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->trans('commands.test.run.messages.test-debug') . ': ' . $test->results['#debug']
);

$this->getModuleHandler()->invokeAll(
$this->moduleHandler->invokeAll(
'test_finished',
[$test->results]
);
Expand Down Expand Up @@ -158,7 +207,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$io->simple(
$this->trans('commands.test.run.messages.file') . ': ' . str_replace($this->getDrupalHelper()->getRoot(), '', $message->file)
$this->trans('commands.test.run.messages.file') . ': ' . str_replace($this->appRoot, '', $message->file)
);
$io->simple(
$this->trans('commands.test.run.messages.method') . ': ' . $message->function
Expand Down

0 comments on commit fe30430

Please sign in to comment.