Skip to content

Commit

Permalink
Merge pull request Sylius#9373 from pamil/1.2-symfony4-part2
Browse files Browse the repository at this point in the history
Make application compatible with not-yet-released Mink release
  • Loading branch information
pamil committed May 1, 2018
2 parents f572661 + 8ea8d63 commit a0db3b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
"require-dev": {
"akeneo/phpspec-skip-example-extension": "^3.0",
"behat/behat": "^3.2",
"behat/mink": "^1.6",
"behat/mink-browserkit-driver": "^1.2",
"behat/mink": "^1.7@dev",
"behat/mink-browserkit-driver": "^1.3@dev",
"behat/mink-extension": "^2.2",
"behat/mink-selenium2-driver": "^1.3",
"friends-of-behat/context-service-extension": "^1.2",
Expand Down
28 changes: 21 additions & 7 deletions src/Sylius/Behat/Service/Setter/CookieSetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Behat\Service\Setter;

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Session;
use FriendsOfBehat\SymfonyExtension\Driver\SymfonyDriver;
use Symfony\Component\BrowserKit\Cookie;
Expand Down Expand Up @@ -44,7 +45,7 @@ public function __construct(Session $minkSession, array $minkParameters)
*/
public function setCookie($name, $value)
{
$this->prepareMinkSessionIfNeeded();
$this->prepareMinkSessionIfNeeded($this->minkSession);

$driver = $this->minkSession->getDriver();

Expand All @@ -59,16 +60,29 @@ public function setCookie($name, $value)
$this->minkSession->setCookie($name, $value);
}

private function prepareMinkSessionIfNeeded()
private function prepareMinkSessionIfNeeded(Session $session): void
{
if ($this->minkSession->getDriver() instanceof SymfonyDriver) {
return;
if ($this->shouldMinkSessionBePrepared($session)) {
$session->visit(rtrim($this->minkParameters['base_url'], '/') . '/');
}
}

if (false !== strpos($this->minkSession->getCurrentUrl(), $this->minkParameters['base_url'])) {
return;
private function shouldMinkSessionBePrepared(Session $session): bool
{
$driver = $session->getDriver();

if ($driver instanceof SymfonyDriver) {
return false;
}

if ($driver instanceof Selenium2Driver && $driver->getWebDriverSession() === null) {
return true;
}

if (false !== strpos($session->getCurrentUrl(), $this->minkParameters['base_url'])) {
return false;
}

$this->minkSession->visit(rtrim($this->minkParameters['base_url'], '/') . '/');
return true;
}
}

0 comments on commit a0db3b0

Please sign in to comment.