@@ -34,16 +34,23 @@ class EventListener implements EventSubscriberInterface
3434 */
3535 private $ reportService ;
3636
37+ /**
38+ * @var bool
39+ */
40+ private $ skipCoverage ;
41+
3742 /**
3843 * Constructor
3944 *
4045 * @param CodeCoverage $coverage
4146 * @param \LeanPHP\Behat\CodeCoverage\Service\ReportService $reportService
47+ * @param boolean $skipCoverage
4248 */
43- public function __construct (CodeCoverage $ coverage , ReportService $ reportService )
49+ public function __construct (CodeCoverage $ coverage , ReportService $ reportService, $ skipCoverage = false )
4450 {
4551 $ this ->coverage = $ coverage ;
4652 $ this ->reportService = $ reportService ;
53+ $ this ->skipCoverage = $ skipCoverage ;
4754 }
4855
4956 /**
@@ -68,6 +75,10 @@ public static function getSubscribedEvents()
6875 */
6976 public function beforeExercise (ExerciseCompleted $ event )
7077 {
78+ if ($ this ->skipCoverage ) {
79+ return ;
80+ }
81+
7182 $ this ->coverage ->clear ();
7283 }
7384
@@ -78,6 +89,10 @@ public function beforeExercise(ExerciseCompleted $event)
7889 */
7990 public function beforeScenario (ScenarioTested $ event )
8091 {
92+ if ($ this ->skipCoverage ) {
93+ return ;
94+ }
95+
8196 $ node = $ event ->getScenario ();
8297 $ id = $ event ->getFeature ()->getFile ().': ' .$ node ->getLine ();
8398
@@ -91,6 +106,10 @@ public function beforeScenario(ScenarioTested $event)
91106 */
92107 public function afterScenario (ScenarioTested $ event )
93108 {
109+ if ($ this ->skipCoverage ) {
110+ return ;
111+ }
112+
94113 $ this ->coverage ->stop ();
95114 }
96115
@@ -101,6 +120,10 @@ public function afterScenario(ScenarioTested $event)
101120 */
102121 public function afterExercise (ExerciseCompleted $ event )
103122 {
123+ if ($ this ->skipCoverage ) {
124+ return ;
125+ }
126+
104127 $ this ->reportService ->generateReport ($ this ->coverage );
105128 }
106129}
0 commit comments