doyolabs /
behat-code-coverage
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /* |
||||||
| 4 | * This file is part of the doyo/behat-coverage-extension project. |
||||||
| 5 | * |
||||||
| 6 | * (c) Anthonius Munthi <[email protected]> |
||||||
| 7 | * |
||||||
| 8 | * For the full copyright and license information, please view the LICENSE |
||||||
| 9 | * file that was distributed with this source code. |
||||||
| 10 | */ |
||||||
| 11 | |||||||
| 12 | declare(strict_types=1); |
||||||
| 13 | |||||||
| 14 | namespace Doyo\Behat\Coverage\Controller\Cli; |
||||||
| 15 | |||||||
| 16 | use Behat\Testwork\Cli\Controller; |
||||||
| 17 | use Doyo\Behat\Coverage\Bridge\Symfony\Event; |
||||||
| 18 | use Doyo\Behat\Coverage\Event\CoverageEvent; |
||||||
| 19 | use Doyo\Behat\Coverage\Event\ReportEvent; |
||||||
| 20 | use Symfony\Component\Console\Command\Command; |
||||||
| 21 | use Symfony\Component\Console\Input\InputInterface; |
||||||
| 22 | use Symfony\Component\Console\Input\InputOption; |
||||||
| 23 | use Symfony\Component\Console\Output\OutputInterface; |
||||||
| 24 | use Symfony\Component\Console\Style\StyleInterface; |
||||||
| 25 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
||||||
| 26 | |||||||
| 27 | /** |
||||||
| 28 | * Code Coverage Cli Controller. |
||||||
| 29 | * |
||||||
| 30 | * @author Anthonius Munthi <[email protected]> |
||||||
| 31 | */ |
||||||
| 32 | class CoverageController implements Controller, EventSubscriberInterface |
||||||
| 33 | { |
||||||
| 34 | /** |
||||||
| 35 | * @var StyleInterface|null |
||||||
| 36 | */ |
||||||
| 37 | private $style; |
||||||
| 38 | |||||||
| 39 | /** |
||||||
| 40 | * @var bool |
||||||
| 41 | */ |
||||||
| 42 | private $coverageEnabled = false; |
||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * CoverageController constructor. |
||||||
| 46 | * |
||||||
| 47 | * @param StyleInterface|null $style |
||||||
| 48 | */ |
||||||
| 49 | public function __construct(StyleInterface $style) |
||||||
| 50 | { |
||||||
| 51 | $this->style = $style; |
||||||
| 52 | } |
||||||
| 53 | |||||||
| 54 | /** |
||||||
| 55 | * {@inheritdoc} |
||||||
| 56 | */ |
||||||
| 57 | public function configure(Command $command) |
||||||
| 58 | { |
||||||
| 59 | $command->addOption('coverage', null, InputOption::VALUE_NONE, 'Collecting code coverage'); |
||||||
| 60 | } |
||||||
| 61 | |||||||
| 62 | public static function getSubscribedEvents() |
||||||
| 63 | { |
||||||
| 64 | return [ |
||||||
| 65 | ReportEvent::BEFORE_PROCESS => [ |
||||||
| 66 | ['validateEvent', 1000], |
||||||
| 67 | ['onBeforeReportProcess', 100], |
||||||
| 68 | ], |
||||||
| 69 | ReportEvent::AFTER_PROCESS => 'onAfterReportProcess', |
||||||
| 70 | CoverageEvent::BEFORE_REFRESH => ['validateEvent', 1000], |
||||||
| 71 | CoverageEvent::BEFORE_START => ['validateEvent', 1000], |
||||||
| 72 | CoverageEvent::BEFORE_STOP => ['validateEvent', 1000], |
||||||
| 73 | ]; |
||||||
| 74 | } |
||||||
| 75 | |||||||
| 76 | /** |
||||||
| 77 | * {@inheritdoc} |
||||||
| 78 | */ |
||||||
| 79 | public function execute(InputInterface $input, OutputInterface $output) |
||||||
| 80 | { |
||||||
| 81 | if ($input->hasParameterOption(['--coverage'])) { |
||||||
| 82 | $this->coverageEnabled = true; |
||||||
| 83 | } |
||||||
| 84 | } |
||||||
| 85 | |||||||
| 86 | public function validateEvent(Event $event) |
||||||
| 87 | { |
||||||
| 88 | if (!$this->coverageEnabled) { |
||||||
| 89 | $event->stopPropagation(); |
||||||
|
0 ignored issues
–
show
|
|||||||
| 90 | } |
||||||
| 91 | } |
||||||
| 92 | |||||||
| 93 | public function onBeforeReportProcess(ReportEvent $event) |
||||||
| 94 | { |
||||||
| 95 | $io = $this->style; |
||||||
| 96 | $io->section('behat coverage reports process started'); |
||||||
|
1 ignored issue
–
show
The method
section() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 97 | $event->setIO($io); |
||||||
|
0 ignored issues
–
show
It seems like
$io can also be of type null; however, parameter $io of Doyo\Behat\Coverage\Event\ReportEvent::setIO() does only seem to accept Symfony\Component\Console\Style\StyleInterface, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 98 | } |
||||||
| 99 | |||||||
| 100 | public function onAfterReportProcess(ReportEvent $event) |
||||||
| 101 | { |
||||||
| 102 | $exceptions = $event->getExceptions(); |
||||||
| 103 | $io = $event->getIO(); |
||||||
| 104 | if (0 === \count($exceptions)) { |
||||||
| 105 | $this->style->success('behat coverage reports process completed'); |
||||||
|
0 ignored issues
–
show
The method
success() does not exist on null.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. Loading history...
|
|||||||
| 106 | |||||||
| 107 | return; |
||||||
| 108 | } |
||||||
| 109 | |||||||
| 110 | $io->newLine(2); |
||||||
| 111 | $io->section('behat coverage reports process failed'); |
||||||
| 112 | foreach ($exceptions as $exception) { |
||||||
| 113 | $io->error($exception->getMessage()); |
||||||
| 114 | } |
||||||
| 115 | } |
||||||
| 116 | } |
||||||
| 117 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.