-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #68 Better compatibility with Behat itself (pamil, alanpoulain)
This PR was merged into the 2.0 branch. Discussion ---------- Fixes #56. If passed context identifier is a Symfony service, it's handled by our custom logic. If it's not, it's handled by default Behat logic. Commits ------- cd79270 Add support for class resolvers 9e9529c Add tests for context initializers d74cd25 Add more sanity checks c54c581 Refactor our environment handler to decorate the original one 8a972b5 Apply suggestions from code review
- Loading branch information
Showing
13 changed files
with
333 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...gration_with_dependency_injection.feature → ...mink_integration/mink_integration.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 0 additions & 78 deletions
78
features/mink_integration/mink_integration_with_context_initializer.feature
This file was deleted.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
features/sanity_checks/class_resolvers_compatibility.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Feature: Class resolvers compatibility | ||
|
||
Scenario: Using class resolvers while handling context environment | ||
Given a working Symfony application with SymfonyExtension configured | ||
And a Behat configuration containing: | ||
""" | ||
default: | ||
extensions: | ||
FriendsOfBehat\ServiceContainerExtension: | ||
imports: | ||
- "tests/class_resolver.yml" | ||
suites: | ||
default: | ||
contexts: | ||
- class:resolved:context | ||
""" | ||
And a Behat services definition file "tests/class_resolver.yml" containing: | ||
""" | ||
services: | ||
App\Tests\CustomClassResolver: | ||
tags: ["context.class_resolver"] | ||
""" | ||
And a Behat service implementation file "tests/CustomClassResolver.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use Behat\Behat\Context\ContextClass\ClassResolver; | ||
final class CustomClassResolver implements ClassResolver | ||
{ | ||
public function supportsClass($contextClass): bool | ||
{ | ||
return $contextClass === 'class:resolved:context'; | ||
} | ||
public function resolveClass($contextClass): string | ||
{ | ||
return 'App\Tests\SomeContext'; | ||
} | ||
} | ||
""" | ||
And a feature file containing: | ||
""" | ||
Feature: | ||
Scenario: | ||
Then it should pass | ||
""" | ||
And a context file "tests/SomeContext.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use Behat\Behat\Context\Context; | ||
final class SomeContext implements Context { | ||
/** @Then it should pass */ | ||
public function itShouldPass(): void {} | ||
} | ||
""" | ||
When I run Behat | ||
Then it should pass |
56 changes: 56 additions & 0 deletions
56
features/sanity_checks/context_constructor_dependency_injection_compatibility.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
Feature: Context constructor dependency injection compatibility | ||
|
||
Scenario: Using context constructor dependency injection | ||
Given a working Symfony application with SymfonyExtension configured | ||
And a Behat configuration containing: | ||
""" | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- App\Tests\SomeContext: | ||
- "@App\\Foo" | ||
services: | ||
App\Foo: ~ | ||
""" | ||
And a class file "src/Foo.php" containing: | ||
""" | ||
<?php | ||
namespace App; | ||
final class Foo | ||
{ | ||
} | ||
""" | ||
And a feature file containing: | ||
""" | ||
Feature: | ||
Scenario: | ||
Then it should pass | ||
""" | ||
And a context file "tests/SomeContext.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use App\Foo; | ||
use Behat\Behat\Context\Context; | ||
final class SomeContext implements Context { | ||
public function __construct(Foo $foo) | ||
{ | ||
$this->foo = $foo; | ||
} | ||
/** @Then it should pass */ | ||
public function itShouldPass(): void | ||
{ | ||
assert($this->foo instanceof Foo); | ||
} | ||
} | ||
""" | ||
When I run Behat | ||
Then it should pass |
71 changes: 71 additions & 0 deletions
71
features/sanity_checks/context_initializer_compatibility.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Feature: Context initializer compatibility | ||
|
||
Scenario: Using class resolvers while handling context environment | ||
Given a working Symfony application with SymfonyExtension configured | ||
And a Behat configuration containing: | ||
""" | ||
default: | ||
extensions: | ||
FriendsOfBehat\ServiceContainerExtension: | ||
imports: | ||
- "tests/context_initializer.yml" | ||
suites: | ||
default: | ||
contexts: | ||
- App\Tests\SomeContext | ||
""" | ||
And a Behat services definition file "tests/context_initializer.yml" containing: | ||
""" | ||
services: | ||
App\Tests\CustomContextInitializer: | ||
tags: ["context.initializer"] | ||
""" | ||
And a Behat service implementation file "tests/CustomContextInitializer.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Context\Initializer\ContextInitializer; | ||
final class CustomContextInitializer implements ContextInitializer | ||
{ | ||
public function initializeContext(Context $context): void | ||
{ | ||
$context->makeItPass(true); | ||
} | ||
} | ||
""" | ||
And a feature file containing: | ||
""" | ||
Feature: | ||
Scenario: | ||
Then it should pass | ||
""" | ||
And a context file "tests/SomeContext.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use Behat\Behat\Context\Context; | ||
final class SomeContext implements Context { | ||
private $shouldPass = false; | ||
public function makeItPass(bool $shouldPass) | ||
{ | ||
$this->shouldPass = $shouldPass; | ||
} | ||
/** @Then it should pass */ | ||
public function itShouldPass(): void | ||
{ | ||
assert($this->shouldPass === true); | ||
} | ||
} | ||
""" | ||
When I run Behat | ||
Then it should pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.