forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestDebugCommand.php
More file actions
99 lines (83 loc) · 2.76 KB
/
Copy pathTestDebugCommand.php
File metadata and controls
99 lines (83 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @file
* Contains \Drupal\AppConsole\Command\TestDebugCommand.
*/
namespace Drupal\AppConsole\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Component\Serialization\Yaml;
class TestDebugCommand extends ContainerAwareCommand
{
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('test:debug')
->setDescription($this->trans('commands.test.debug.description'))
->addArgument('test-id', InputArgument::OPTIONAL,
$this->trans('commands.test.debug.arguments.resource-id'))
->addOption('group', '', InputOption::VALUE_OPTIONAL,
$this->trans('commands.test.debug.options.group'));
$this->addDependency('simpletest');
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$test_id = $input->getArgument('test-id');
$group = $input->getOption('group');
$table = $this->getHelperSet()->get('table');
$table->setlayout($table::LAYOUT_COMPACT);
if ($test_id) {
$this->getTestByID($output, $table, $test_id);
} else {
$this->getAllTests($output, $table, $group);
}
}
/**
* @param $output OutputInterface
* @param $table TableHelper
* @param $config_name String
*/
private function getTestByID($output, $table, $test_id)
{
$testing_groups = $this->getTestDiscovery()->getTestClasses(null);
foreach ($testing_groups as $testing_group => $tests) {
foreach ($tests as $key => $test) {
break;
}
}
$configurationEncoded = Yaml::encode($test);
$table->addRow([$configurationEncoded]);
$table->render($output);
}
/**
* @param $output OutputInterface
* @param $table TableHelper
* @param $config_name String
*/
protected function getAllTests($output, $table, $group)
{
$testing_groups = $this->getTestDiscovery()->getTestClasses(null);
$table->setHeaders(
[
$this->trans('commands.test.debug.messages.id'),
$this->trans('commands.test.debug.messages.group'),
]);
foreach ($testing_groups as $testing_group => $tests) {
if (!empty($group) && $group != $testing_group) {
continue;
}
foreach ($tests as $test) {
$table->addRow(array($test['name'], $test['group']));
}
}
$table->render($output);
}
}