5 * Contains \Drupal\Console\Command\Debug\TestCommand.
8 namespace Drupal\Console\Command\Debug;
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 Drupal\Console\Core\Command\Command;
16 use Drupal\Console\Annotations\DrupalCommand;
17 use Drupal\simpletest\TestDiscovery;
21 * extension = "simpletest",
22 * extensionType = "module",
25 class TestCommand extends Command
30 protected $test_discovery;
33 * TestCommand constructor.
35 * @param TestDiscovery $test_discovery
37 public function __construct(
38 TestDiscovery $test_discovery
40 $this->test_discovery = $test_discovery;
41 parent::__construct();
45 protected function configure()
48 ->setName('debug:test')
49 ->setDescription($this->trans('commands.debug.test.description'))
52 InputArgument::OPTIONAL,
53 $this->trans('commands.debug.test.options.group'),
59 InputOption::VALUE_OPTIONAL,
60 $this->trans('commands.debug.test.arguments.test-class')
68 protected function execute(InputInterface $input, OutputInterface $output)
70 //Registers namespaces for disabled modules.
71 $this->test_discovery->registerTestNamespaces();
73 $testClass = $input->getOption('test-class');
74 $group = $input->getArgument('group');
77 $this->testDetail($testClass);
79 $this->testList($group);
83 private function testDetail($test_class)
85 $testingGroups = $this->test_discovery->getTestClasses(null);
88 foreach ($testingGroups as $testing_group => $tests) {
89 foreach ($tests as $key => $test) {
90 if ($test['name'] == $test_class) {
95 if ($testDetails !== null) {
102 $class = new \ReflectionClass($test['name']);
103 if (is_subclass_of($testDetails['name'], 'PHPUnit_Framework_TestCase')) {
104 $testDetails['type'] = 'phpunit';
106 $testDetails = $this->test_discovery
107 ->getTestInfo($testDetails['name']);
108 $testDetails['type'] = 'simpletest';
111 $this->getIo()->comment($testDetails['name']);
114 foreach ($testDetails as $key => $value) {
115 $testInfo [] = [$key, $value];
118 $this->getIo()->table([], $testInfo);
121 $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC);
122 $this->getIo()->info($this->trans('commands.debug.test.messages.methods'));
123 foreach ($methods as $method) {
124 if ($method->class == $testDetails['name'] && strpos($method->name, 'test') === 0) {
125 $this->getIo()->simple($method->name);
130 $this->getIo()->error($this->trans('commands.debug.test.messages.not-found'));
134 protected function testList($group)
136 $testingGroups = $this->test_discovery
137 ->getTestClasses(null);
140 $tableHeader = [$this->trans('commands.debug.test.messages.group')];
143 $this->trans('commands.debug.test.messages.class'),
144 $this->trans('commands.debug.test.messages.type')
147 $this->getIo()->writeln(
150 $this->trans('commands.debug.test.messages.group'),
157 foreach ($testingGroups as $testing_group => $tests) {
159 $tableRows[] =[$testing_group];
163 if (!empty($group) && $group != $testing_group) {
167 foreach ($tests as $test) {
168 if (is_subclass_of($test['name'], 'PHPUnit_Framework_TestCase')) {
169 $test['type'] = 'phpunit';
171 $test['type'] = 'simpletest';
179 $this->getIo()->table($tableHeader, $tableRows, 'compact');
182 $this->getIo()->success(
184 $this->trans('commands.debug.test.messages.success-group'),
189 $this->getIo()->success(
190 $this->trans('commands.debug.test.messages.success-groups')