Merge branch '2.1'
* 2.1: Browser integration
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -9,6 +9,7 @@ use Behat\Mink\Mink;
|
||||
use Behat\Mink\Session;
|
||||
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
|
||||
use FriendsOfBehat\SymfonyExtension\ServiceContainer\SymfonyExtension;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Component\BrowserKit\Client;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
@@ -16,6 +17,7 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\HttpKernel\HttpKernelBrowser;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
|
||||
final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements CompilerPassInterface
|
||||
@@ -73,11 +75,13 @@ final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements
|
||||
|
||||
private function provideBrowserKitIntegration(ContainerBuilder $container): void
|
||||
{
|
||||
if (!class_exists(Client::class) || !$container->has('test.client')) {
|
||||
if (!$container->has('test.client')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$container->setAlias(Client::class, 'test.client');
|
||||
foreach ([Client::class, KernelBrowser::class, HttpKernelBrowser::class] as $class) {
|
||||
$container->setAlias($class, 'test.client');
|
||||
}
|
||||
}
|
||||
|
||||
private function provideMinkIntegration(ContainerBuilder $container): void
|
||||
|
||||
Reference in New Issue
Block a user