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\Listener; |
15
|
|
|
|
16
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\Session\SessionInterface; |
17
|
|
|
use Doyo\Behat\Coverage\Bridge\Exception\CacheException; |
18
|
|
|
use Doyo\Behat\Coverage\Event\CoverageEvent; |
19
|
|
|
use Doyo\Behat\Coverage\Event\ReportEvent; |
20
|
|
|
use SebastianBergmann\CodeCoverage\Filter; |
21
|
|
|
use spec\Doyo\Behat\Coverage\Listener\AbstractSessionCoverageListener; |
22
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
23
|
|
|
|
24
|
|
|
class LocalCoverageListener extends AbstractSessionCoverageListener implements EventSubscriberInterface |
25
|
|
|
{ |
26
|
7 |
|
public static function getSubscribedEvents() |
27
|
|
|
{ |
28
|
|
|
return [ |
29
|
7 |
|
CoverageEvent::REFRESH => 'onCoverageRefresh', |
30
|
|
|
CoverageEvent::START => 'onCoverageStarted', |
31
|
|
|
CoverageEvent::STOP => ['onCoverageStopped', 100], |
32
|
|
|
ReportEvent::BEFORE_PROCESS => 'onReportBeforeProcess', |
33
|
|
|
]; |
34
|
|
|
} |
35
|
|
|
|
36
|
6 |
|
public function onCoverageRefresh() |
37
|
|
|
{ |
38
|
6 |
|
$this->session->reset(); |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
public function onCoverageStarted(CoverageEvent $event) |
42
|
|
|
{ |
43
|
6 |
|
$session = $this->session; |
44
|
|
|
|
45
|
6 |
|
$session->setTestCase($event->getTestCase()); |
46
|
6 |
|
$session->save(); |
47
|
|
|
} |
48
|
|
|
|
49
|
6 |
|
public function onCoverageStopped(CoverageEvent $event) |
50
|
|
|
{ |
51
|
6 |
|
$session = $this->session; |
52
|
|
|
|
53
|
6 |
|
$session->refresh(); |
54
|
6 |
|
$event->updateCoverage($session->getData()); |
55
|
|
|
|
56
|
6 |
|
if ($session->hasExceptions()) { |
57
|
1 |
|
$message = implode("\n", $session->getExceptions()); |
58
|
1 |
|
throw new CacheException($message); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
5 |
|
public function onReportBeforeProcess(ReportEvent $event) |
63
|
|
|
{ |
64
|
5 |
|
$session = $this->session; |
65
|
5 |
|
$session->refresh(); |
66
|
|
|
|
67
|
5 |
|
if (!$session->hasExceptions()) { |
68
|
5 |
|
return; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
foreach ($session->getExceptions() as $exception) { |
72
|
|
|
$event->addException($exception); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|