Skip to content

Commit

Permalink
Merge pull request #16 from pamil/phpspec-4
Browse files Browse the repository at this point in the history
Support for phpspec 4.0
  • Loading branch information
nidup authored Jul 10, 2017
2 parents 3381d13 + ef63b9f commit 3671abe
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: php
php: [7.0, 7.1]

before_script:
- composer selfupdate
- composer install --prefer-source
- composer install --prefer-dist

script:
- bin/phpspec run
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"phpspec/phpspec": "^3.0"
"phpspec/phpspec": "^4.0"
},
"autoload": {
"psr-0": {
Expand All @@ -23,7 +23,7 @@
"config": {
"bin-dir": "bin"
},
"minimum-stability": "stable",
"minimum-stability": "alpha",
"extra": {
"branch-alias": {
"dev-master": "3.0.x-dev",
Expand Down
16 changes: 9 additions & 7 deletions spec/Akeneo/Runner/Maintainer/SkipExampleMaintainerSpec.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace spec\Akeneo\Runner\Maintainer;

use Akeneo\Runner\Maintainer\SkipExampleMaintainer;
Expand All @@ -15,7 +17,7 @@
/**
* @mixin SkipExampleMaintainer
*/
class SkipExampleMaintainerSpec extends ObjectBehavior
final class SkipExampleMaintainerSpec extends ObjectBehavior
{
function it_is_a_maintainer()
{
Expand All @@ -27,14 +29,14 @@ function its_priority_is_75()
$this->getPriority()->shouldBe(75);
}

function it_supports_specification_that_has_doc_comment(
function it_supports_specification_that_has_require_doc_comment(
ExampleNode $example,
SpecificationNode $specification,
\ReflectionClass $refClass
) {
$example->getSpecification()->willReturn($specification);
$specification->getClassReflection()->willReturn($refClass);
$refClass->getDocComment()->willReturn('doc comment');
$refClass->getDocComment()->willReturn("/**\n * @require Foo\\Bar\n */");

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

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

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

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

function its_prepare_method_ignores_other_annotation(
Expand All @@ -104,11 +106,11 @@ function its_prepare_method_ignores_other_annotation(
Specification $context,
MatcherManager $matchers,
CollaboratorManager $collaborators
){
) {
$example->getSpecification()->willReturn($specification);
$specification->getClassReflection()->willReturn($refClass);
$refClass->getDocComment()->willReturn("/**\n * @author [email protected] \n */");

$this->shouldNotThrow('PhpSpec\Exception\Example\SkippingException')->duringPrepare($example, $context, $matchers, $collaborators);
$this->shouldNotThrow(SkippingException::class)->duringPrepare($example, $context, $matchers, $collaborators);
}
}
49 changes: 28 additions & 21 deletions src/Akeneo/Runner/Maintainer/SkipExampleMaintainer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Akeneo\Runner\Maintainer;

use PhpSpec\Runner\Maintainer\Maintainer;
Expand All @@ -9,45 +11,50 @@
use PhpSpec\Runner\CollaboratorManager;
use PhpSpec\Exception\Example\SkippingException;

class SkipExampleMaintainer implements Maintainer
final class SkipExampleMaintainer implements Maintainer
{
/**
* {@inheritdoc}
*/
public function supports(ExampleNode $example)
public function supports(ExampleNode $example): bool
{
return false !== $this->getDocComment($example);
return count($this->getRequirements($this->getDocComment($example))) > 0;
}

/**
* {@inheritdoc}
*/
public function prepare(ExampleNode $example, Specification $context,
MatcherManager $matchers, CollaboratorManager $collaborators)
{
if ($docComment = $this->getDocComment($example)) {
foreach ($this->getRequirements($docComment) as $requirement) {
if (!class_exists($requirement) && !interface_exists($requirement)) {
throw new SkippingException(
sprintf('"%s" is not available', $requirement)
);
}
public function prepare(
ExampleNode $example,
Specification $context,
MatcherManager $matchers,
CollaboratorManager $collaborators
) {
foreach ($this->getRequirements($this->getDocComment($example)) as $requirement) {
if (!class_exists($requirement) && !interface_exists($requirement)) {
throw new SkippingException(
sprintf('"%s" is not available', $requirement)
);
}
}
}

/**
* {@inheritdoc}
*/
public function teardown(ExampleNode $example, Specification $context,
MatcherManager $matchers, CollaboratorManager $collaborators)
{
public function teardown(
ExampleNode $example,
Specification $context,
MatcherManager $matchers,
CollaboratorManager $collaborators
) {

}

/**
* {@inheritdoc}
*/
public function getPriority()
public function getPriority(): int
{
return 75;
}
Expand All @@ -59,7 +66,7 @@ public function getPriority()
*
* @return array
*/
protected function getRequirements($docComment)
protected function getRequirements(string $docComment): array
{
return array_map(
function($tag) {
Expand Down Expand Up @@ -91,10 +98,10 @@ function($docline) {
*
* @param ExampleNode $example
*
* @return string|false
* @return string
*/
protected function getDocComment(ExampleNode $example)
protected function getDocComment(ExampleNode $example): string
{
return $example->getSpecification()->getClassReflection()->getDocComment();
return $example->getSpecification()->getClassReflection()->getDocComment() ?: '';
}
}
4 changes: 3 additions & 1 deletion src/Akeneo/SkipExampleExtension.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<?php

declare(strict_types=1);

namespace Akeneo;

use Akeneo\Runner;
use PhpSpec\Extension;
use PhpSpec\ServiceContainer;
use PhpSpec\ServiceContainer\IndexedServiceContainer;

class SkipExampleExtension implements Extension
final class SkipExampleExtension implements Extension
{
/**
* {@inheritdoc}
Expand Down

0 comments on commit 3671abe

Please sign in to comment.