Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e23f280

Browse files
committed
Minor cleanup + PHPDoc Update + require-dev cleanup
- Minor code improvements / cleanup - PHPDoc update - Cleanup require-dev
1 parent 1640c8a commit e23f280

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ documented in this file.
66
The format is based on [Keep a Changelog](http://keepachangelog.com/)
77
and this project adheres to [Semantic Versioning](http://semver.org/).
88

9+
## 4.x-dev
10+
11+
- Cleanup development dependencies
12+
- Minor code improvements
13+
914
## [4.2.0] - 2018-03-19
1015

1116
- Updated `phpunit/php-code-coverage` dependency from `~5.0` to `~6.0`.

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"phpunit/php-code-coverage": "~6.0"
3030
},
3131
"require-dev": {
32-
"bossa/phpspec2-expect": "^3.0",
3332
"escapestudios/symfony2-coding-standard": "^3.1",
3433
"squizlabs/php_codesniffer": "^3.2"
3534
},

spec/CodeCoverageExtensionSpec.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ function it_should_use_html_format_by_default()
2222
$this->load($container, []);
2323

2424
$options = $container->get('code_coverage.options');
25-
expect($options['format'])->toBe(array('html'));
25+
if ($options['format'] !== ['html']) {
26+
throw new Exception("Default format is not html");
27+
}
2628
}
2729

2830
function it_should_transform_format_into_array()
@@ -32,7 +34,10 @@ function it_should_transform_format_into_array()
3234
$this->load($container);
3335

3436
$options = $container->get('code_coverage.options');
35-
expect($options['format'])->toBe(array('html'));
37+
if ($options['format'] !== ['html']) {
38+
throw new Exception("Default format is not transformed to an array");
39+
}
40+
3641
}
3742

3843
function it_should_use_singular_output()
@@ -42,6 +47,10 @@ function it_should_use_singular_output()
4247
$this->load($container);
4348

4449
$options = $container->get('code_coverage.options');
45-
expect($options['output'])->toBe(array('foo' => 'test'));
50+
if ($options['output'] !== ['foo' => 'test']) {
51+
throw new Exception("Default format is not singular output");
52+
}
53+
54+
4655
}
4756
}

spec/Listener/CodeCoverageListenerSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CodeCoverageListenerSpec extends ObjectBehavior
2121
* functional (integration) tests instead. This file is left for reference.
2222
*
2323
* @see https://github.com/leanphp/phpspec-code-coverage/issues/19
24+
*
2425
function let(ConsoleIO $io, CodeCoverage $coverage)
2526
{
2627
$this->beConstructedWith($io, $coverage, array());

src/CodeCoverageExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
/**
33
* This file is part of the leanphp/phpspec-code-coverage package
44
*
5+
* @author ek9 <[email protected]>
6+
* @license MIT
7+
*
58
* For the full copyright and license information, please see the LICENSE file
69
* that was distributed with this source code.
710
*
8-
* @license MIT
911
*/
1012
namespace LeanPHP\PhpSpec\CodeCoverage;
1113

1214
use LeanPHP\PhpSpec\CodeCoverage\Listener\CodeCoverageListener;
15+
use PhpSpec\Extension;
1316
use PhpSpec\ServiceContainer;
1417
use SebastianBergmann\CodeCoverage\CodeCoverage;
1518
use SebastianBergmann\CodeCoverage\Filter;
@@ -18,12 +21,12 @@
1821
use Symfony\Component\Console\Input\InputOption;
1922

2023
/**
21-
* Injects a Event Subscriber into the EventDispatcher.
24+
* Injects Code Coverage Event Subscriber into the EventDispatcher.
2225
* The Subscriber will add Code Coverage information before each example
2326
*
2427
* @author Henrik Bjornskov
2528
*/
26-
class CodeCoverageExtension implements \PhpSpec\Extension
29+
class CodeCoverageExtension implements Extension
2730
{
2831
/**
2932
* {@inheritDoc}
@@ -36,7 +39,6 @@ public function load(ServiceContainer $container, array $params = [])
3639
}
3740
}
3841

39-
4042
$container->define('code_coverage.filter', function () {
4143
return new Filter();
4244
});
@@ -119,7 +121,6 @@ public function load(ServiceContainer $container, array $params = [])
119121
$skipCoverage = true;
120122
}
121123

122-
123124
$listener = new CodeCoverageListener(
124125
$container->get('console.io'),
125126
$container->get('code_coverage'),

src/Listener/CodeCoverageListener.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
/**
33
* This file is part of the leanphp/phpspec-code-coverage package
44
*
5+
* @author ek9 <[email protected]>
6+
* @license MIT
7+
*
58
* For the full copyright and license information, please see the LICENSE file
69
* that was distributed with this source code.
710
*
8-
* @license MIT
911
*/
1012
namespace LeanPHP\PhpSpec\CodeCoverage\Listener;
1113

@@ -26,6 +28,7 @@ class CodeCoverageListener implements EventSubscriberInterface
2628
private $io;
2729
private $options;
2830
private $enabled;
31+
private $skipCoverage;
2932

3033
/**
3134
* @param ConsoleIO $io
@@ -47,7 +50,8 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
4750
'format' => array('html'),
4851
);
4952

50-
$this->enabled = !$skipCoverage && (extension_loaded('xdebug') || (PHP_SAPI === 'phpdbg'));
53+
$this->enabled = extension_loaded('xdebug') || (PHP_SAPI === 'phpdbg');
54+
$this->skipCoverage = $skipCoverage;
5155
}
5256

5357
/**
@@ -58,7 +62,7 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
5862
*/
5963
public function beforeSuite(SuiteEvent $event)
6064
{
61-
if (!$this->enabled) {
65+
if (!$this->enabled || $this->skipCoverage) {
6266
return;
6367
}
6468

@@ -87,7 +91,7 @@ public function beforeSuite(SuiteEvent $event)
8791
*/
8892
public function beforeExample(ExampleEvent $event)
8993
{
90-
if (!$this->enabled) {
94+
if (!$this->enabled || $this->skipCoverage) {
9195
return;
9296
}
9397

@@ -106,7 +110,7 @@ public function beforeExample(ExampleEvent $event)
106110
*/
107111
public function afterExample(ExampleEvent $event)
108112
{
109-
if (!$this->enabled) {
113+
if (!$this->enabled || $this->skipCoverage) {
110114
return;
111115
}
112116

@@ -118,9 +122,13 @@ public function afterExample(ExampleEvent $event)
118122
*/
119123
public function afterSuite(SuiteEvent $event)
120124
{
121-
if (!$this->enabled) {
125+
if (!$this->enabled || $this->skipCoverage) {
122126
if ($this->io && $this->io->isVerbose()) {
123-
$this->io->writeln('Did not detect Xdebug extension or phpdbg. No code coverage will be generated.');
127+
if (!$this->enabled) {
128+
$this->io->writeln('No code coverage will be generated as neither Xdebug nor phpdbg was detected.');
129+
} elseif ($this->skipCoverage) {
130+
$this->io->writeln('Skipping code coverage generation');
131+
}
124132
}
125133

126134
return;
@@ -155,13 +163,13 @@ public function setOptions(array $options)
155163
/**
156164
* {@inheritDoc}
157165
*/
158-
public static function getSubscribedEvents()
166+
public static function getSubscribedEvents(): array
159167
{
160-
return array(
161-
'beforeExample' => array('beforeExample', -10),
162-
'afterExample' => array('afterExample', -10),
163-
'beforeSuite' => array('beforeSuite', -10),
164-
'afterSuite' => array('afterSuite', -10),
165-
);
168+
return [
169+
'beforeExample' => ['beforeExample', -10],
170+
'afterExample' => ['afterExample', -10],
171+
'beforeSuite' => ['beforeSuite', -10],
172+
'afterSuite' => ['afterSuite', -10],
173+
];
166174
}
167175
}

0 commit comments

Comments
 (0)