Browser integration

This commit is contained in:
Kamil Kokot
2020-04-04 22:07:00 +02:00
parent c9e5db9af9
commit 0f906e1156
2 changed files with 98 additions and 19 deletions

View File

@@ -22,6 +22,16 @@ Feature: BrowserKit integration
When I visit the page "/hello-world"
Then I should see "Hello world!" on the page
"""
Scenario: Injecting KernelBrowser manually
Given a YAML services file containing:
"""
services:
App\Tests\SomeContext:
public: true
arguments:
- '@test.client'
"""
And a context file "tests/SomeContext.php" containing:
"""
<?php
@@ -31,14 +41,13 @@ Feature: BrowserKit integration
use Behat\Behat\Context\Context;
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
use Psr\Container\ContainerInterface;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\BrowserKit\Client;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
final class SomeContext implements Context {
/** @var Client|AbstractBrowser */
/** @var KernelBrowser */
private $client;
public function __construct($client)
public function __construct(KernelBrowser $client)
{
$this->client = $client;
}
@@ -56,20 +65,10 @@ Feature: BrowserKit integration
}
}
"""
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
Scenario: Autowiring and autoconfiguring KernelBrowser client
Given a YAML services file containing:
"""
services:
@@ -77,10 +76,86 @@ Feature: BrowserKit integration
autowire: true
autoconfigure: true
bind:
$client: "@test.client"
App\Tests\SomeContext: ~
"""
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\Bundle\FrameworkBundle\KernelBrowser;
final class SomeContext implements Context {
/** @var KernelBrowser */
private $client;
public function __construct(KernelBrowser $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));
}
}
"""
When I run Behat
Then it should pass
Scenario: Autowiring and autoconfiguring HttpKernelBrowser client
Given a YAML services file containing:
"""
services:
_defaults:
autowire: true
autoconfigure: true
App\Tests\SomeContext: ~
"""
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\HttpKernel\HttpKernelBrowser;
final class SomeContext implements Context {
/** @var HttpKernelBrowser */
private $client;
public function __construct(HttpKernelBrowser $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));
}
}
"""
When I run Behat
Then it should pass