forked from FriendsOfBehat/SymfonyExtension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature FriendsOfBehat#82 Provide simple BrowserKit integration (pamil)
This PR was merged into the 2.1-dev branch. Discussion ---------- There's already a service for BrowserKit's client, this PR adds acceptance scenarios and autowires it. The architecture might need some rework after introducing Panther support. Commits ------- ab61dba Provide simple BrowserKit integration
- Loading branch information
Showing
4 changed files
with
99 additions
and
0 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
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
81 changes: 81 additions & 0 deletions
81
features/browserkit_integration/browserkit_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Feature: BrowserKit integration | ||
|
||
Background: | ||
Given a working Symfony application with SymfonyExtension configured | ||
And a Behat configuration containing: | ||
""" | ||
default: | ||
suites: | ||
default: | ||
contexts: | ||
- App\Tests\SomeContext | ||
""" | ||
And a feature file containing: | ||
""" | ||
Feature: | ||
Scenario: | ||
When I visit the page "/hello-world" | ||
Then I should see "Hello world!" on the page | ||
# Doubling the scenario to account for some weird error | ||
Scenario: | ||
When I visit the page "/hello-world" | ||
Then I should see "Hello world!" on the page | ||
""" | ||
And a context file "tests/SomeContext.php" containing: | ||
""" | ||
<?php | ||
namespace App\Tests; | ||
use Behat\Behat\Context\Context; | ||
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\BrowserKit\Client; | ||
final class SomeContext implements Context { | ||
private $client; | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
/** @When I visit the page :page */ | ||
public function visitPage(string $page): void | ||
{ | ||
$this->client->request('GET', $page); | ||
} | ||
/** @Then I should see :content on the page */ | ||
public function shouldSeeContentOnPage(string $content): void | ||
{ | ||
assert(false !== strpos($this->client->getResponse()->getContent(), $content)); | ||
} | ||
} | ||
""" | ||
|
||
Scenario: Injecting BrowserKit client | ||
Given a YAML services file containing: | ||
""" | ||
services: | ||
App\Tests\SomeContext: | ||
public: true | ||
arguments: | ||
- '@test.client' | ||
""" | ||
When I run Behat | ||
Then it should pass | ||
|
||
Scenario: Autowiring and autoconfiguring BrowserKit client | ||
Given a YAML services file containing: | ||
""" | ||
services: | ||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
App\Tests\SomeContext: ~ | ||
""" | ||
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