Skip to content

Commit 3671abe

Browse files
authored
Merge pull request #16 from pamil/phpspec-4
Support for phpspec 4.0
2 parents 3381d13 + ef63b9f commit 3671abe

5 files changed

Lines changed: 43 additions & 33 deletions

File tree

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ language: php
33
php: [7.0, 7.1]
44

55
before_script:
6-
- composer selfupdate
7-
- composer install --prefer-source
6+
- composer install --prefer-dist
87

98
script:
109
- bin/phpspec run

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"phpspec/phpspec": "^3.0"
16+
"phpspec/phpspec": "^4.0"
1717
},
1818
"autoload": {
1919
"psr-0": {
@@ -23,7 +23,7 @@
2323
"config": {
2424
"bin-dir": "bin"
2525
},
26-
"minimum-stability": "stable",
26+
"minimum-stability": "alpha",
2727
"extra": {
2828
"branch-alias": {
2929
"dev-master": "3.0.x-dev",

spec/Akeneo/Runner/Maintainer/SkipExampleMaintainerSpec.php

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

3+
declare(strict_types=1);
4+
35
namespace spec\Akeneo\Runner\Maintainer;
46

57
use Akeneo\Runner\Maintainer\SkipExampleMaintainer;
@@ -15,7 +17,7 @@
1517
/**
1618
* @mixin SkipExampleMaintainer
1719
*/
18-
class SkipExampleMaintainerSpec extends ObjectBehavior
20+
final class SkipExampleMaintainerSpec extends ObjectBehavior
1921
{
2022
function it_is_a_maintainer()
2123
{
@@ -27,14 +29,14 @@ function its_priority_is_75()
2729
$this->getPriority()->shouldBe(75);
2830
}
2931

30-
function it_supports_specification_that_has_doc_comment(
32+
function it_supports_specification_that_has_require_doc_comment(
3133
ExampleNode $example,
3234
SpecificationNode $specification,
3335
\ReflectionClass $refClass
3436
) {
3537
$example->getSpecification()->willReturn($specification);
3638
$specification->getClassReflection()->willReturn($refClass);
37-
$refClass->getDocComment()->willReturn('doc comment');
39+
$refClass->getDocComment()->willReturn("/**\n * @require Foo\\Bar\n */");
3840

3941
$this->supports($example)->shouldBe(true);
4042
}
@@ -79,7 +81,7 @@ function its_prepare_method_does_not_throw_exception_when_specification_requires
7981
$specification->getClassReflection()->willReturn($refClass);
8082
$refClass->getDocComment()->willReturn("/**\n * @require Akeneo\Runner\Maintainer\SkipExampleMaintainer\n */");
8183

82-
$this->shouldNotThrow('PhpSpec\Exception\Example\SkippingException')->duringPrepare($example, $context, $matchers, $collaborators);
84+
$this->shouldNotThrow(SkippingException::class)->duringPrepare($example, $context, $matchers, $collaborators);
8385
}
8486

8587
function its_prepare_method_does_not_throw_exception_when_specification_requires_an_existing_interface(
@@ -94,7 +96,7 @@ function its_prepare_method_does_not_throw_exception_when_specification_requires
9496
$specification->getClassReflection()->willReturn($refClass);
9597
$refClass->getDocComment()->willReturn("/**\n * @require PhpSpec\Runner\Maintainer\Maintainer\n */");
9698

97-
$this->shouldNotThrow('PhpSpec\Exception\Example\SkippingException')->duringPrepare($example, $context, $matchers, $collaborators);
99+
$this->shouldNotThrow(SkippingException::class)->duringPrepare($example, $context, $matchers, $collaborators);
98100
}
99101

100102
function its_prepare_method_ignores_other_annotation(
@@ -104,11 +106,11 @@ function its_prepare_method_ignores_other_annotation(
104106
Specification $context,
105107
MatcherManager $matchers,
106108
CollaboratorManager $collaborators
107-
){
109+
) {
108110
$example->getSpecification()->willReturn($specification);
109111
$specification->getClassReflection()->willReturn($refClass);
110112
$refClass->getDocComment()->willReturn("/**\n * @author foo@example.com \n */");
111113

112-
$this->shouldNotThrow('PhpSpec\Exception\Example\SkippingException')->duringPrepare($example, $context, $matchers, $collaborators);
114+
$this->shouldNotThrow(SkippingException::class)->duringPrepare($example, $context, $matchers, $collaborators);
113115
}
114116
}

src/Akeneo/Runner/Maintainer/SkipExampleMaintainer.php

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

3+
declare(strict_types=1);
4+
35
namespace Akeneo\Runner\Maintainer;
46

57
use PhpSpec\Runner\Maintainer\Maintainer;
@@ -9,45 +11,50 @@
911
use PhpSpec\Runner\CollaboratorManager;
1012
use PhpSpec\Exception\Example\SkippingException;
1113

12-
class SkipExampleMaintainer implements Maintainer
14+
final class SkipExampleMaintainer implements Maintainer
1315
{
1416
/**
1517
* {@inheritdoc}
1618
*/
17-
public function supports(ExampleNode $example)
19+
public function supports(ExampleNode $example): bool
1820
{
19-
return false !== $this->getDocComment($example);
21+
return count($this->getRequirements($this->getDocComment($example))) > 0;
2022
}
2123

2224
/**
2325
* {@inheritdoc}
2426
*/
25-
public function prepare(ExampleNode $example, Specification $context,
26-
MatcherManager $matchers, CollaboratorManager $collaborators)
27-
{
28-
if ($docComment = $this->getDocComment($example)) {
29-
foreach ($this->getRequirements($docComment) as $requirement) {
30-
if (!class_exists($requirement) && !interface_exists($requirement)) {
31-
throw new SkippingException(
32-
sprintf('"%s" is not available', $requirement)
33-
);
34-
}
27+
public function prepare(
28+
ExampleNode $example,
29+
Specification $context,
30+
MatcherManager $matchers,
31+
CollaboratorManager $collaborators
32+
) {
33+
foreach ($this->getRequirements($this->getDocComment($example)) as $requirement) {
34+
if (!class_exists($requirement) && !interface_exists($requirement)) {
35+
throw new SkippingException(
36+
sprintf('"%s" is not available', $requirement)
37+
);
3538
}
3639
}
3740
}
3841

3942
/**
4043
* {@inheritdoc}
4144
*/
42-
public function teardown(ExampleNode $example, Specification $context,
43-
MatcherManager $matchers, CollaboratorManager $collaborators)
44-
{
45+
public function teardown(
46+
ExampleNode $example,
47+
Specification $context,
48+
MatcherManager $matchers,
49+
CollaboratorManager $collaborators
50+
) {
51+
4552
}
4653

4754
/**
4855
* {@inheritdoc}
4956
*/
50-
public function getPriority()
57+
public function getPriority(): int
5158
{
5259
return 75;
5360
}
@@ -59,7 +66,7 @@ public function getPriority()
5966
*
6067
* @return array
6168
*/
62-
protected function getRequirements($docComment)
69+
protected function getRequirements(string $docComment): array
6370
{
6471
return array_map(
6572
function($tag) {
@@ -91,10 +98,10 @@ function($docline) {
9198
*
9299
* @param ExampleNode $example
93100
*
94-
* @return string|false
101+
* @return string
95102
*/
96-
protected function getDocComment(ExampleNode $example)
103+
protected function getDocComment(ExampleNode $example): string
97104
{
98-
return $example->getSpecification()->getClassReflection()->getDocComment();
105+
return $example->getSpecification()->getClassReflection()->getDocComment() ?: '';
99106
}
100107
}

src/Akeneo/SkipExampleExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Akeneo;
46

57
use Akeneo\Runner;
68
use PhpSpec\Extension;
79
use PhpSpec\ServiceContainer;
810
use PhpSpec\ServiceContainer\IndexedServiceContainer;
911

10-
class SkipExampleExtension implements Extension
12+
final class SkipExampleExtension implements Extension
1113
{
1214
/**
1315
* {@inheritdoc}

0 commit comments

Comments
 (0)