Conditions | 19 |
Paths | 660 |
Total Lines | 115 |
Code Lines | 68 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
56 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
57 | { |
||
58 | $profiles = $input->getOption('profile'); |
||
59 | $testIds = $input->getOption('test-id'); |
||
60 | $showImplementation = (bool) $input->getOption('show-implementation'); |
||
61 | $showEnvironment = (bool) $input->getOption('show-environment'); |
||
62 | $showRemoteLogs = (bool) $input->getOption('show-remote-logs'); |
||
63 | $keepLogs = (bool) $input->getOption('keep-logs'); |
||
64 | $ignoreErrors = (bool) $input->getOption('ignore-errors'); |
||
65 | |||
66 | $retries = 5; |
||
67 | |||
68 | $counters = [ |
||
69 | 'executed' => [], |
||
70 | 'success' => [], |
||
71 | 'errors' => [], |
||
72 | ]; |
||
73 | |||
74 | foreach ($profiles as $profile) { |
||
75 | $tests = $this->testsProvider->getTests($profile); |
||
76 | $responseType = $this->testsProvider->getResponseTypeForProfile($profile); |
||
77 | |||
78 | $testInfo = new TestInfo($profile, $responseType); |
||
79 | |||
80 | if (! $keepLogs) { |
||
81 | $this->logsHelper->clearLogs($testInfo->getRoot(), $testInfo->getRpId()); |
||
82 | } |
||
83 | |||
84 | if (count($testIds)) { |
||
|
|||
85 | $tests = \array_filter($tests, static function (RpTestInterface $test) use ($testIds) { |
||
86 | foreach ($testIds as $testId) { |
||
87 | if (fnmatch($testId, $test->getTestId())) { |
||
88 | return true; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | return false; |
||
93 | //return \in_array($test->getTestId(), $testIds, true); |
||
94 | }); |
||
95 | } |
||
96 | |||
97 | foreach ($tests as $test) { |
||
98 | $testName = $test->getTestId() . ' @' . $testInfo->getProfile(); |
||
99 | $counters['executed'][] = $testName; |
||
100 | |||
101 | $startTime = new \DateTimeImmutable(); |
||
102 | $output->writeln("<comment>Test started at:</comment> <info>{$startTime->format(\DateTimeImmutable::RFC3339)}</info>", OutputInterface::VERBOSITY_DEBUG); |
||
103 | $output->writeln('Executing test ' . $testName . '...', OutputInterface::VERBOSITY_DEBUG); |
||
104 | |||
105 | $count = 0; |
||
106 | |||
107 | do { |
||
108 | $result = $this->testRunner->run($test, $testInfo); |
||
109 | } while (null !== $result->getException() && ++$count < $retries); |
||
110 | |||
111 | $output->writeln("<comment>Test:</comment> <info>$testName</info>", OutputInterface::VERBOSITY_NORMAL); |
||
112 | |||
113 | if ($count > 1) { |
||
114 | $output->writeln("<comment>Attempts:</comment> <info>$count</info>", OutputInterface::VERBOSITY_NORMAL); |
||
115 | } |
||
116 | |||
117 | if ($showEnvironment) { |
||
118 | $output->writeln(''); |
||
119 | $this->printEnvironment($result, $output); |
||
120 | } |
||
121 | |||
122 | if ($showImplementation) { |
||
123 | $output->writeln(''); |
||
124 | $this->printImplementation($result, $output); |
||
125 | } |
||
126 | |||
127 | |||
128 | if ($showRemoteLogs) { |
||
129 | $output->writeln(''); |
||
130 | $this->printRemoteLog($result, $output); |
||
131 | } |
||
132 | |||
133 | if ($exception = $result->getException()) { |
||
134 | $counters['errors'][] = $testName; |
||
135 | $output->writeln('<comment>Result:</comment> <error>Test failed!</error>', OutputInterface::VERBOSITY_NORMAL); |
||
136 | $output->writeln((string) $exception, OutputInterface::VERBOSITY_DEBUG); |
||
137 | } else { |
||
138 | $counters['success'][] = $testName; |
||
139 | $output->writeln('<comment>Result:</comment> <info>Test OK</info>', OutputInterface::VERBOSITY_NORMAL); |
||
140 | } |
||
141 | |||
142 | $this->printSeparator($output, OutputInterface::VERBOSITY_NORMAL); |
||
143 | |||
144 | if (! $ignoreErrors && $result->getException()) { |
||
145 | return 1; |
||
146 | } |
||
147 | } |
||
148 | } |
||
149 | |||
150 | $output->writeln('<info>--- SUMMARY ---</info>', OutputInterface::VERBOSITY_NORMAL); |
||
151 | $output->writeln(sprintf('<comment>Executed:</comment> <info>%d</info>', count($counters['executed'])), OutputInterface::VERBOSITY_NORMAL); |
||
152 | $output->writeln(sprintf('<comment>Success:</comment> <info>%d</info>', count($counters['success'])), OutputInterface::VERBOSITY_NORMAL); |
||
153 | $output->writeln(sprintf('<comment>Errors:</comment> <info>%d</info>', count($counters['errors'])), OutputInterface::VERBOSITY_NORMAL); |
||
154 | |||
155 | if (count($counters['errors'])) { |
||
156 | $this->printSeparator($output, OutputInterface::VERBOSITY_NORMAL); |
||
157 | $output->writeln('<info>Failed tests</info>', OutputInterface::VERBOSITY_NORMAL); |
||
158 | |||
159 | foreach ($counters['errors'] as $testName) { |
||
160 | $output->writeln(sprintf(' - <comment>%s</comment>', $testName), OutputInterface::VERBOSITY_NORMAL); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | |||
165 | |||
166 | if (count($counters['errors'])) { |
||
167 | return 1; |
||
168 | } |
||
169 | |||
170 | return 0; |
||
171 | } |
||
206 |