5 * Contains \Drupal\Console\Command\Test\DebugCommand.
8 namespace Drupal\Console\Command\Test;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Component\Serialization\Yaml;
15 use Symfony\Component\Console\Command\Command;
16 use Drupal\Console\Core\Command\Shared\CommandTrait;
17 use Drupal\Console\Annotations\DrupalCommand;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\simpletest\TestDiscovery;
23 * extension = "simpletest",
24 * extensionType = "module",
27 class DebugCommand extends Command
34 protected $test_discovery;
37 * DebugCommand constructor.
39 * @param TestDiscovery $test_discovery
41 public function __construct(
42 TestDiscovery $test_discovery
44 $this->test_discovery = $test_discovery;
45 parent::__construct();
49 protected function configure()
52 ->setName('test:debug')
53 ->setDescription($this->trans('commands.test.debug.description'))
56 InputArgument::OPTIONAL,
57 $this->trans('commands.test.debug.options.group'),
63 InputOption::VALUE_OPTIONAL,
64 $this->trans('commands.test.debug.arguments.test-class')
71 protected function execute(InputInterface $input, OutputInterface $output)
73 $io = new DrupalStyle($input, $output);
74 //Registers namespaces for disabled modules.
75 $this->test_discovery->registerTestNamespaces();
77 $testClass = $input->getOption('test-class');
78 $group = $input->getArgument('group');
81 $this->testDetail($io, $testClass);
83 $this->testList($io, $group);
87 private function testDetail(DrupalStyle $io, $test_class)
89 $testingGroups = $this->test_discovery->getTestClasses(null);
92 foreach ($testingGroups as $testing_group => $tests) {
93 foreach ($tests as $key => $test) {
94 if ($test['name'] == $test_class) {
99 if ($testDetails !== null) {
106 $class = new \ReflectionClass($test['name']);
107 if (is_subclass_of($testDetails['name'], 'PHPUnit_Framework_TestCase')) {
108 $testDetails['type'] = 'phpunit';
110 $testDetails = $this->test_discovery
111 ->getTestInfo($testDetails['name']);
112 $testDetails['type'] = 'simpletest';
115 $io->comment($testDetails['name']);
118 foreach ($testDetails as $key => $value) {
119 $testInfo [] = [$key, $value];
122 $io->table([], $testInfo);
125 $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
126 $io->info($this->trans('commands.test.debug.messages.methods'));
127 foreach ($methods as $method) {
128 if ($method->class == $testDetails['name'] && strpos($method->name, 'test') === 0) {
129 $io->simple($method->name);
134 $io->error($this->trans('commands.test.debug.messages.not-found'));
138 protected function testList(DrupalStyle $io, $group)
140 $testingGroups = $this->test_discovery
141 ->getTestClasses(null);
144 $tableHeader = [$this->trans('commands.test.debug.messages.group')];
147 $this->trans('commands.test.debug.messages.class'),
148 $this->trans('commands.test.debug.messages.type')
154 $this->trans('commands.test.debug.messages.group'),
161 foreach ($testingGroups as $testing_group => $tests) {
163 $tableRows[] =[$testing_group];
167 if (!empty($group) && $group != $testing_group) {
171 foreach ($tests as $test) {
172 if (is_subclass_of($test['name'], 'PHPUnit_Framework_TestCase')) {
173 $test['type'] = 'phpunit';
175 $test['type'] = 'simpletest';
183 $io->table($tableHeader, $tableRows, 'compact');
188 $this->trans('commands.test.debug.messages.success-group'),
194 $this->trans('commands.test.debug.messages.success-groups')