1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Doyo\PhpSpec\CodeCoverage\Listener; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use Doyo\PhpSpec\CodeCoverage\ProcessorInterface; |
8
|
|
|
use Doyo\Behat\Coverage\Bridge\CodeCoverage\TestCase; |
9
|
|
|
use Doyo\PhpSpec\CodeCoverage\Event\CoverageEvent; |
10
|
|
|
use Doyo\Symfony\Bridge\EventDispatcher\EventDispatcher; |
11
|
|
|
use Doyo\Symfony\Bridge\EventDispatcher\EventDispatcherInterface; |
12
|
|
|
use PhpSpec\Console\ConsoleIO; |
13
|
|
|
use PhpSpec\Event\ExampleEvent; |
14
|
|
|
use PhpSpec\Event\SuiteEvent; |
15
|
|
|
use PhpSpec\Loader\Node\ExampleNode; |
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
17
|
|
|
|
18
|
|
|
class CoverageListener implements EventSubscriberInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var ProcessorInterface $processor |
22
|
|
|
*/ |
23
|
|
|
private $processor; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var ConsoleIO |
27
|
|
|
*/ |
28
|
|
|
private $consoleIO; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var EventDispatcherInterface |
32
|
|
|
*/ |
33
|
|
|
private $dispatcher; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* CoverageListener constructor. |
37
|
|
|
* @param ProcessorInterface $processor |
38
|
|
|
* @param ConsoleIO $consoleIO |
39
|
|
|
*/ |
40
|
5 |
|
public function __construct( |
41
|
|
|
EventDispatcher $dispatcher, |
42
|
|
|
ProcessorInterface $processor, |
43
|
|
|
ConsoleIO $consoleIO |
44
|
|
|
) |
45
|
|
|
{ |
46
|
5 |
|
$this->dispatcher = $dispatcher; |
|
|
|
|
47
|
5 |
|
$this->processor = $processor; |
48
|
5 |
|
$this->consoleIO = $consoleIO; |
49
|
|
|
} |
50
|
|
|
|
51
|
1 |
|
public static function getSubscribedEvents() |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
1 |
|
'beforeExample' => ['beforeExample', -10], |
55
|
|
|
'afterExample' => ['afterExample', -10], |
56
|
|
|
'afterSuite' => ['afterSuite', -10] |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
public function beforeExample(ExampleEvent $suiteEvent) |
61
|
|
|
{ |
62
|
1 |
|
$example = $suiteEvent->getExample(); |
63
|
1 |
|
$processor = $this->processor; |
64
|
|
|
|
65
|
1 |
|
$name = strtr('%spec%::%example%', [ |
66
|
1 |
|
'%spec%' => $example->getSpecification()->getTitle(), |
67
|
1 |
|
'%example%' => $example->getFunctionReflection()->getName(), |
68
|
|
|
]); |
69
|
1 |
|
$testCase = new TestCase($name); |
70
|
|
|
|
71
|
1 |
|
$processor->setCurrentTestCase($testCase); |
72
|
1 |
|
$processor->start($testCase); |
73
|
|
|
} |
74
|
|
|
|
75
|
9 |
|
public function afterExample(ExampleEvent $exampleEvent) |
76
|
|
|
{ |
77
|
9 |
|
$processor = $this->processor; |
78
|
9 |
|
$result = $exampleEvent->getResult(); |
79
|
9 |
|
$testCase = $processor->getCurrentTestCase(); |
80
|
|
|
|
81
|
|
|
$map = [ |
82
|
9 |
|
ExampleEvent::PASSED => TestCase::RESULT_PASSED, |
83
|
9 |
|
ExampleEvent::SKIPPED => TestCase::RESULT_SKIPPED, |
84
|
9 |
|
ExampleEvent::FAILED => TestCase::RESULT_FAILED, |
85
|
9 |
|
ExampleEvent::BROKEN => TestCase::RESULT_ERROR, |
86
|
9 |
|
ExampleEvent::PENDING => TestCase::RESULT_SKIPPED, |
87
|
|
|
]; |
88
|
|
|
|
89
|
9 |
|
$result = $map[$result]; |
90
|
9 |
|
$testCase->setResult($result); |
91
|
9 |
|
$processor->addTestCase($testCase); |
92
|
9 |
|
$processor->stop(); |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
public function afterSuite() |
96
|
|
|
{ |
97
|
1 |
|
$processor = $this->processor; |
98
|
1 |
|
$consoleIO = $this->consoleIO; |
99
|
1 |
|
$dispatcher = $this->dispatcher; |
100
|
1 |
|
$event = new CoverageEvent($processor, $consoleIO); |
101
|
|
|
|
102
|
1 |
|
$dispatcher->dispatch($event, CoverageEvent::REPORT); |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..