Skip to content

Commit 94954e8

Browse files
committed
Add PHPSPEC v6 support.
1 parent 6b5e799 commit 94954e8

File tree

5 files changed

+18
-19
lines changed

5 files changed

+18
-19
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
],
4040
"require": {
4141
"php": "^7.1",
42-
"phpspec/phpspec": "^4.2 || ^5.0",
42+
"phpspec/phpspec": "^4.2 || ^5.0 || ^6.0",
4343
"phpunit/php-code-coverage": "^5.0 || ^6.0 || ^7.0"
4444
},
4545
"require-dev": {

spec/Exception/NoCoverageDriverAvailableExceptionSpec.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception\NoCoverageDriverAvailableException;
88
use PhpSpec\ObjectBehavior;
9+
use RuntimeException;
910

1011
/**
1112
* @author Stéphane Hulard
@@ -14,7 +15,7 @@ class NoCoverageDriverAvailableExceptionSpec extends ObjectBehavior
1415
{
1516
public function it_is_initializable(): void
1617
{
17-
$this->shouldBeAnInstanceOf(\RuntimeException::class);
18+
$this->shouldBeAnInstanceOf(RuntimeException::class);
1819
$this->shouldHaveType(NoCoverageDriverAvailableException::class);
1920
}
2021
}

src/CodeCoverageExtension.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
declare(strict_types=1);
4-
53
/**
64
* This file is part of the friends-of-phpspec/phpspec-code-coverage package.
75
*
@@ -12,18 +10,24 @@
1210
* that was distributed with this source code.
1311
*/
1412

13+
declare(strict_types=1);
14+
1515
namespace FriendsOfPhpSpec\PhpSpec\CodeCoverage;
1616

1717
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Exception\NoCoverageDriverAvailableException;
1818
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\Listener\CodeCoverageListener;
1919
use PhpSpec\Extension;
2020
use PhpSpec\ServiceContainer;
21+
use RuntimeException;
2122
use SebastianBergmann\CodeCoverage\CodeCoverage;
2223
use SebastianBergmann\CodeCoverage\Filter;
2324
use SebastianBergmann\CodeCoverage\Report;
2425
use SebastianBergmann\CodeCoverage\Version;
2526
use Symfony\Component\Console\Input\InputOption;
2627

28+
use function count;
29+
use function is_array;
30+
2731
/**
2832
* Injects Code Coverage Event Subscriber into the EventDispatcher.
2933
* The Subscriber will add Code Coverage information before each example.
@@ -48,12 +52,8 @@ public function load(ServiceContainer $container, array $params = []): void
4852
$container->define('code_coverage', static function ($container) {
4953
try {
5054
$coverage = new CodeCoverage(null, $container->get('code_coverage.filter'));
51-
} catch (\RuntimeException $error) {
52-
throw new NoCoverageDriverAvailableException(
53-
'There is no available coverage driver to be used.',
54-
0,
55-
$error
56-
);
55+
} catch (RuntimeException $error) {
56+
throw new NoCoverageDriverAvailableException('There is no available coverage driver to be used.', 0, $error);
5757
}
5858

5959
return $coverage;
@@ -64,15 +64,13 @@ public function load(ServiceContainer $container, array $params = []): void
6464

6565
if (!isset($options['format'])) {
6666
$options['format'] = ['html'];
67-
} elseif (!\is_array($options['format'])) {
67+
} elseif (!is_array($options['format'])) {
6868
$options['format'] = (array) $options['format'];
6969
}
7070

71-
if (isset($options['output'])) {
72-
if (!\is_array($options['output']) && 1 === \count($options['format'])) {
73-
$format = $options['format'][0];
74-
$options['output'] = [$format => $options['output']];
75-
}
71+
if (isset($options['output']) && !is_array($options['output']) && 1 === count($options['format'])) {
72+
$format = $options['format'][0];
73+
$options['output'] = [$format => $options['output']];
7674
}
7775

7876
if (!isset($options['show_uncovered_files'])) {

src/Listener/CodeCoverageListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function afterSuite(SuiteEvent $event): void
9393

9494
foreach ($this->reports as $format => $report) {
9595
if ($this->io && $this->io->isVerbose()) {
96-
$this->io->writeln(\sprintf('Generating code coverage report in %s format ...', $format));
96+
$this->io->writeln(sprintf('Generating code coverage report in %s format ...', $format));
9797
}
9898

9999
if ($report instanceof Report\Text) {
@@ -123,7 +123,7 @@ public function beforeExample(ExampleEvent $event): void
123123
$name = $spec->getClassReflection()->getName();
124124
}
125125

126-
$name = \strtr('%spec%::%example%', [
126+
$name = strtr('%spec%::%example%', [
127127
'%spec%' => $name,
128128
'%example%' => $example->getFunctionReflection()->getName(),
129129
]);

src/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension;
1515

16-
\class_alias(
16+
class_alias(
1717
CodeCoverageExtension::class,
1818
'LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension'
1919
);

0 commit comments

Comments
 (0)