diff --git a/config/services/drupal-console/test.yml b/config/services/drupal-console/test.yml index 52c8e942b..d36f8581e 100644 --- a/config/services/drupal-console/test.yml +++ b/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 } diff --git a/src/Command/Test/DebugCommand.php b/src/Command/Test/DebugCommand.php index 3c1fc56d7..b17f2bb44 100644 --- a/src/Command/Test/DebugCommand.php +++ b/src/Command/Test/DebugCommand.php @@ -13,9 +13,10 @@ 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 @@ -23,15 +24,37 @@ */ 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 @@ -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'); @@ -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) { @@ -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'; } @@ -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)) { diff --git a/src/Command/Test/RunCommand.php b/src/Command/Test/RunCommand.php index cc0bee4fc..76ab8f18e 100644 --- a/src/Command/Test/RunCommand.php +++ b/src/Command/Test/RunCommand.php @@ -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 @@ -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'); @@ -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'] @@ -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] ); @@ -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