Fix bug preventing changes of Mink default session service
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
"behat/mink": "^1.7",
|
"behat/mink": "^1.7",
|
||||||
"behat/mink-browserkit-driver": "^1.3",
|
"behat/mink-browserkit-driver": "^1.3",
|
||||||
"behat/mink-extension": "^2.2",
|
"behat/mink-extension": "^2.2",
|
||||||
|
"behat/mink-selenium2-driver": "^1.3",
|
||||||
"friends-of-behat/service-container-extension": "^1.0",
|
"friends-of-behat/service-container-extension": "^1.0",
|
||||||
"phpstan/phpstan-shim": "^0.11",
|
"phpstan/phpstan-shim": "^0.11",
|
||||||
"sylius-labs/coding-standard": "^3.0",
|
"sylius-labs/coding-standard": "^3.0",
|
||||||
|
|||||||
70
features/mink_integration/switching_mink_sessions.feature
Normal file
70
features/mink_integration/switching_mink_sessions.feature
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
Feature: Switching Mink sessions
|
||||||
|
|
||||||
|
Scenario: Switching Mink sessions
|
||||||
|
Given a working Symfony application with SymfonyExtension configured
|
||||||
|
And a Behat configuration containing:
|
||||||
|
"""
|
||||||
|
default:
|
||||||
|
extensions:
|
||||||
|
Behat\MinkExtension:
|
||||||
|
base_url: "http://localhost:8080/"
|
||||||
|
default_session: symfony
|
||||||
|
javascript_session: selenium2
|
||||||
|
sessions:
|
||||||
|
symfony:
|
||||||
|
symfony: ~
|
||||||
|
selenium2:
|
||||||
|
selenium2: ~
|
||||||
|
|
||||||
|
|
||||||
|
suites:
|
||||||
|
default:
|
||||||
|
contexts:
|
||||||
|
- App\Tests\SomeContext
|
||||||
|
"""
|
||||||
|
And a feature file containing:
|
||||||
|
"""
|
||||||
|
Feature:
|
||||||
|
Scenario:
|
||||||
|
Then I should use Mink session with "FriendsOfBehat\SymfonyExtension\Driver\SymfonyDriver" as a driver
|
||||||
|
|
||||||
|
@javascript
|
||||||
|
Scenario:
|
||||||
|
Then I should use Mink session with "Behat\Mink\Driver\Selenium2Driver" as a driver
|
||||||
|
"""
|
||||||
|
And a context file "tests/SomeContext.php" containing:
|
||||||
|
"""
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests;
|
||||||
|
|
||||||
|
use Behat\Behat\Context\Context;
|
||||||
|
use Behat\Mink\Session;
|
||||||
|
|
||||||
|
final class SomeContext implements Context {
|
||||||
|
private $session;
|
||||||
|
|
||||||
|
public function __construct(Session $session)
|
||||||
|
{
|
||||||
|
$this->session = $session;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @Then I should use Mink session with :driver as a driver*/
|
||||||
|
public function shouldUseDriver(string $driverClass): void
|
||||||
|
{
|
||||||
|
var_dump(get_class($this->session));
|
||||||
|
var_dump(get_class($this->session->getDriver()));
|
||||||
|
assert($this->session->getDriver() instanceof $driverClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
And a YAML services file containing:
|
||||||
|
"""
|
||||||
|
services:
|
||||||
|
App\Tests\SomeContext:
|
||||||
|
public: true
|
||||||
|
arguments:
|
||||||
|
- '@behat.mink.default_session'
|
||||||
|
"""
|
||||||
|
When I run Behat
|
||||||
|
Then it should pass
|
||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace FriendsOfBehat\SymfonyExtension\Bundle\DependencyInjection;
|
namespace FriendsOfBehat\SymfonyExtension\Bundle\DependencyInjection;
|
||||||
|
|
||||||
use Behat\Behat\Context\Context;
|
use Behat\Behat\Context\Context;
|
||||||
|
use Behat\Mink\Mink;
|
||||||
use Behat\Mink\Session;
|
use Behat\Mink\Session;
|
||||||
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
|
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
@@ -51,10 +52,18 @@ final class FriendsOfBehatSymfonyExtensionExtension extends Extension implements
|
|||||||
|
|
||||||
private function registerMinkDefaultSession(ContainerBuilder $container): void
|
private function registerMinkDefaultSession(ContainerBuilder $container): void
|
||||||
{
|
{
|
||||||
$minkDefaultSessionDefinition = new Definition(Session::class, ['fob_symfony.mink.default_session']);
|
$minkDefinition = new Definition(Mink::class, ['mink']);
|
||||||
|
$minkDefinition->setPublic(true);
|
||||||
|
$minkDefinition->setLazy(true);
|
||||||
|
$minkDefinition->setFactory([new Reference('behat.service_container'), 'get']);
|
||||||
|
|
||||||
|
$container->setDefinition('behat.mink', $minkDefinition);
|
||||||
|
$container->setAlias(Mink::class, 'behat.mink');
|
||||||
|
|
||||||
|
$minkDefaultSessionDefinition = new Definition(Session::class);
|
||||||
$minkDefaultSessionDefinition->setPublic(true);
|
$minkDefaultSessionDefinition->setPublic(true);
|
||||||
$minkDefaultSessionDefinition->setLazy(true);
|
$minkDefaultSessionDefinition->setLazy(true);
|
||||||
$minkDefaultSessionDefinition->setFactory([new Reference('behat.service_container'), 'get']);
|
$minkDefaultSessionDefinition->setFactory([new Reference('behat.mink'), 'getSession']);
|
||||||
|
|
||||||
$container->setDefinition('behat.mink.default_session', $minkDefaultSessionDefinition);
|
$container->setDefinition('behat.mink.default_session', $minkDefaultSessionDefinition);
|
||||||
$container->setAlias(Session::class, 'behat.mink.default_session');
|
$container->setAlias(Session::class, 'behat.mink.default_session');
|
||||||
|
|||||||
Reference in New Issue
Block a user