Skip to content

Commit 6e945e4

Browse files
authored
Merge pull request #15 from ptondereau/update-phpspec6
Add PHPSPEC v6 support.
2 parents 6b5e799 + 42ae667 commit 6e945e4

File tree

7 files changed

+24
-38
lines changed

7 files changed

+24
-38
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/CodeCoverageExtensionSpec.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace spec\FriendsOfPhpSpec\PhpSpec\CodeCoverage;
66

7+
use Exception;
78
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension;
89
use PhpSpec\ObjectBehavior;
910
use PhpSpec\ServiceContainer\IndexedServiceContainer;

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: 9 additions & 5 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,7 +52,7 @@ 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) {
55+
} catch (RuntimeException $error) {
5256
throw new NoCoverageDriverAvailableException(
5357
'There is no available coverage driver to be used.',
5458
0,
@@ -64,12 +68,12 @@ public function load(ServiceContainer $container, array $params = []): void
6468

6569
if (!isset($options['format'])) {
6670
$options['format'] = ['html'];
67-
} elseif (!\is_array($options['format'])) {
71+
} elseif (!is_array($options['format'])) {
6872
$options['format'] = (array) $options['format'];
6973
}
7074

7175
if (isset($options['output'])) {
72-
if (!\is_array($options['output']) && 1 === \count($options['format'])) {
76+
if (!is_array($options['output']) && 1 === count($options['format'])) {
7377
$format = $options['format'][0];
7478
$options['output'] = [$format => $options['output']];
7579
}

src/Exception/NoCoverageDriverAvailableException.php

Lines changed: 2 additions & 2 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.
75
*
@@ -12,6 +10,8 @@
1210
* that was distributed with this source code.
1311
*/
1412

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

1717
use RuntimeException;

src/Listener/CodeCoverageListener.php

Lines changed: 5 additions & 26 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,6 +10,8 @@
1210
* that was distributed with this source code.
1311
*/
1412

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

1717
use PhpSpec\Console\ConsoleIO;
@@ -34,18 +34,9 @@ class CodeCoverageListener implements EventSubscriberInterface
3434

3535
private $reports;
3636

37-
/**
38-
* @var bool
39-
*/
4037
private $skipCoverage;
4138

42-
/**
43-
* @param ConsoleIO $io
44-
* @param CodeCoverage $coverage
45-
* @param array $reports
46-
* @param bool $skipCoverage
47-
*/
48-
public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $reports, $skipCoverage = false)
39+
public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $reports, bool $skipCoverage = false)
4940
{
5041
$this->io = $io;
5142
$this->coverage = $coverage;
@@ -62,9 +53,6 @@ public function __construct(ConsoleIO $io, CodeCoverage $coverage, array $report
6253
$this->skipCoverage = $skipCoverage;
6354
}
6455

65-
/**
66-
* @param ExampleEvent $event
67-
*/
6856
public function afterExample(ExampleEvent $event): void
6957
{
7058
if ($this->skipCoverage) {
@@ -74,9 +62,6 @@ public function afterExample(ExampleEvent $event): void
7462
$this->coverage->stop();
7563
}
7664

77-
/**
78-
* @param SuiteEvent $event
79-
*/
8065
public function afterSuite(SuiteEvent $event): void
8166
{
8267
if ($this->skipCoverage) {
@@ -93,7 +78,7 @@ public function afterSuite(SuiteEvent $event): void
9378

9479
foreach ($this->reports as $format => $report) {
9580
if ($this->io && $this->io->isVerbose()) {
96-
$this->io->writeln(\sprintf('Generating code coverage report in %s format ...', $format));
81+
$this->io->writeln(sprintf('Generating code coverage report in %s format ...', $format));
9782
}
9883

9984
if ($report instanceof Report\Text) {
@@ -106,9 +91,6 @@ public function afterSuite(SuiteEvent $event): void
10691
}
10792
}
10893

109-
/**
110-
* @param ExampleEvent $event
111-
*/
11294
public function beforeExample(ExampleEvent $event): void
11395
{
11496
if ($this->skipCoverage) {
@@ -123,7 +105,7 @@ public function beforeExample(ExampleEvent $event): void
123105
$name = $spec->getClassReflection()->getName();
124106
}
125107

126-
$name = \strtr('%spec%::%example%', [
108+
$name = strtr('%spec%::%example%', [
127109
'%spec%' => $name,
128110
'%example%' => $example->getFunctionReflection()->getName(),
129111
]);
@@ -175,9 +157,6 @@ public static function getSubscribedEvents(): array
175157
];
176158
}
177159

178-
/**
179-
* @param array $options
180-
*/
181160
public function setOptions(array $options): void
182161
{
183162
$this->options = $options + $this->options;

src/bootstrap.php

Lines changed: 4 additions & 3 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
*
@@ -11,9 +9,12 @@
119
* For the full copyright and license information, please see the LICENSE file
1210
* that was distributed with this source code.
1311
*/
12+
13+
declare(strict_types=1);
14+
1415
use FriendsOfPhpSpec\PhpSpec\CodeCoverage\CodeCoverageExtension;
1516

16-
\class_alias(
17+
class_alias(
1718
CodeCoverageExtension::class,
1819
'LeanPHP\PhpSpec\CodeCoverage\CodeCoverageExtension'
1920
);

0 commit comments

Comments
 (0)