From bb0b46fedc97c195805795ad0dcf3eb9e4957c39 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 28 Dec 2013 11:40:04 +0100 Subject: [PATCH 1/3] Updated the driver for the Mink 2.0 API --- composer.json | 2 +- src/Behat/Mink/Driver/BrowserKitDriver.php | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index c0c5df9..a73d17f 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": ">=5.3.1", - "behat/mink": "~1.6@dev", + "behat/mink": "dev-2-architecture-changes", "symfony/browser-kit": "~2.0", "symfony/dom-crawler": "~2.0" }, diff --git a/src/Behat/Mink/Driver/BrowserKitDriver.php b/src/Behat/Mink/Driver/BrowserKitDriver.php index f27ea6b..3ace1fb 100644 --- a/src/Behat/Mink/Driver/BrowserKitDriver.php +++ b/src/Behat/Mink/Driver/BrowserKitDriver.php @@ -10,10 +10,8 @@ namespace Behat\Mink\Driver; -use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\DriverException; use Behat\Mink\Exception\UnsupportedDriverActionException; -use Behat\Mink\Session; use Symfony\Component\BrowserKit\Client; use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\BrowserKit\Request; @@ -36,7 +34,6 @@ */ class BrowserKitDriver extends CoreDriver { - private $session; private $client; /** @@ -74,14 +71,6 @@ public function getClient() return $this->client; } - /** - * {@inheritdoc} - */ - public function setSession(Session $session) - { - $this->session = $session; - } - /** * Tells driver to remove hostname from URL. * @@ -351,7 +340,7 @@ public function find($xpath) $elements = array(); foreach ($nodes as $i => $node) { - $elements[] = new NodeElement(sprintf('(%s)[%d]', $xpath, $i + 1), $this->session); + $elements[] = sprintf('(%s)[%d]', $xpath, $i + 1); } return $elements; From 314e95242b0565c340bafc3bbb572fe7b62587d3 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 30 Jan 2014 19:19:10 +0100 Subject: [PATCH 2/3] Removed the BC layers for Symfony 2.2 and older --- composer.json | 4 +- src/Behat/Mink/Driver/BrowserKitDriver.php | 85 +--------------------- 2 files changed, 3 insertions(+), 86 deletions(-) diff --git a/composer.json b/composer.json index a73d17f..6c10069 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,8 @@ "require": { "php": ">=5.3.1", "behat/mink": "dev-2-architecture-changes", - "symfony/browser-kit": "~2.0", - "symfony/dom-crawler": "~2.0" + "symfony/browser-kit": "~2.3", + "symfony/dom-crawler": "~2.3" }, "require-dev": { diff --git a/src/Behat/Mink/Driver/BrowserKitDriver.php b/src/Behat/Mink/Driver/BrowserKitDriver.php index 3ace1fb..b5f46f0 100644 --- a/src/Behat/Mink/Driver/BrowserKitDriver.php +++ b/src/Behat/Mink/Driver/BrowserKitDriver.php @@ -14,7 +14,6 @@ use Behat\Mink\Exception\UnsupportedDriverActionException; use Symfony\Component\BrowserKit\Client; use Symfony\Component\BrowserKit\Cookie; -use Symfony\Component\BrowserKit\Request; use Symfony\Component\BrowserKit\Response; use Symfony\Component\DomCrawler\Crawler; use Symfony\Component\DomCrawler\Field\ChoiceFormField; @@ -23,8 +22,6 @@ use Symfony\Component\DomCrawler\Field\InputFormField; use Symfony\Component\DomCrawler\Field\TextareaFormField; use Symfony\Component\DomCrawler\Form; -use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest; -use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse; use Symfony\Component\HttpKernel\Client as HttpKernelClient; /** @@ -153,19 +150,7 @@ public function visit($url) */ public function getCurrentUrl() { - if (method_exists($this->client, 'getInternalRequest')) { - $request = $this->client->getInternalRequest(); - } else { - // BC layer for BrowserKit 2.2.x and older - $request = $this->client->getRequest(); - - if (null !== $request && !$request instanceof Request && !$request instanceof HttpFoundationRequest) { - throw new DriverException(sprintf( - 'The BrowserKit client returned an unsupported request implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer.', - get_class($request) - )); - } - } + $request = $this->client->getInternalRequest(); if ($request === null) { throw new DriverException('Unable to access the request before visiting a page'); @@ -553,16 +538,6 @@ public function submitForm($xpath) */ protected function getResponse() { - if (!method_exists($this->client, 'getInternalResponse')) { - $implementationResponse = $this->client->getResponse(); - - if (null === $implementationResponse) { - throw new DriverException('Unable to access the response before visiting a page'); - } - - return $this->convertImplementationResponse($implementationResponse); - } - $response = $this->client->getInternalResponse(); if (null === $response) { @@ -572,64 +547,6 @@ protected function getResponse() return $response; } - /** - * Gets the BrowserKit Response for legacy BrowserKit versions. - * - * Before 2.3.0, there was no Client::getInternalResponse method, and the - * return value of Client::getResponse can be anything when the implementation - * uses Client::filterResponse because of a bad choice done in BrowserKit and - * kept for BC reasons (the Client::getInternalResponse method has been added - * to solve it). - * - * This implementation supports client which don't rely Client::filterResponse - * and clients which use an HttpFoundation Response (like the HttpKernel client). - * - * @param object $response the response specific to the BrowserKit implementation - * - * @return Response - * - * @throws DriverException If the response cannot be converted to a BrowserKit response - */ - private function convertImplementationResponse($response) - { - if ($response instanceof Response) { - return $response; - } - - // due to a bug, the HttpKernel client implementation returns the HttpFoundation response - // The conversion logic is copied from Symfony\Component\HttpKernel\Client::filterResponse - if ($response instanceof HttpFoundationResponse) { - $headers = $response->headers->all(); - if ($response->headers->getCookies()) { - $cookies = array(); - foreach ($response->headers->getCookies() as $cookie) { - $cookies[] = new Cookie( - $cookie->getName(), - $cookie->getValue(), - $cookie->getExpiresTime(), - $cookie->getPath(), - $cookie->getDomain(), - $cookie->isSecure(), - $cookie->isHttpOnly() - ); - } - $headers['Set-Cookie'] = $cookies; - } - - // this is needed to support StreamedResponse - ob_start(); - $response->sendContent(); - $content = ob_get_clean(); - - return new Response($content, $response->getStatusCode(), $headers); - } - - throw new DriverException(sprintf( - 'The BrowserKit client returned an unsupported response implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer.', - get_class($response) - )); - } - /** * Prepares URL for visiting. * Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit(). From ebd9dcdbd144e83b5829c02e468fb0aeb8e3fc7b Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Fri, 2 May 2014 11:38:50 +0200 Subject: [PATCH 3/3] Removed the deprecated url altering --- src/Behat/Mink/Driver/BrowserKitDriver.php | 51 +--------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/src/Behat/Mink/Driver/BrowserKitDriver.php b/src/Behat/Mink/Driver/BrowserKitDriver.php index b5f46f0..0b375ed 100644 --- a/src/Behat/Mink/Driver/BrowserKitDriver.php +++ b/src/Behat/Mink/Driver/BrowserKitDriver.php @@ -39,8 +39,6 @@ class BrowserKitDriver extends CoreDriver private $forms = array(); private $serverParameters = array(); private $started = false; - private $removeScriptFromUrl = false; - private $removeHostFromUrl = false; /** * Initializes BrowserKit driver. @@ -68,38 +66,6 @@ public function getClient() return $this->client; } - /** - * Tells driver to remove hostname from URL. - * - * @param Boolean $remove - * - * @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead. - */ - public function setRemoveHostFromUrl($remove = true) - { - trigger_error( - 'setRemoveHostFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.', - E_USER_DEPRECATED - ); - $this->removeHostFromUrl = (bool) $remove; - } - - /** - * Tells driver to remove script name from URL. - * - * @param Boolean $remove - * - * @deprecated Deprecated as of 1.2, to be removed in 2.0. Pass the base url in the constructor instead. - */ - public function setRemoveScriptFromUrl($remove = true) - { - trigger_error( - 'setRemoveScriptFromUrl() is deprecated as of 1.2 and will be removed in 2.0. Pass the base url in the constructor instead.', - E_USER_DEPRECATED - ); - $this->removeScriptFromUrl = (bool) $remove; - } - /** * {@inheritdoc} */ @@ -141,7 +107,7 @@ public function reset() */ public function visit($url) { - $this->client->request('GET', $this->prepareUrl($url), array(), array(), $this->serverParameters); + $this->client->request('GET', $url, array(), array(), $this->serverParameters); $this->forms = array(); } @@ -547,21 +513,6 @@ protected function getResponse() return $response; } - /** - * Prepares URL for visiting. - * Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit(). - * - * @param string $url - * - * @return string - */ - protected function prepareUrl($url) - { - $replacement = ($this->removeHostFromUrl ? '' : '$1') . ($this->removeScriptFromUrl ? '' : '$2'); - - return preg_replace('#(https?\://[^/]+)(/[^/\.]+\.php)?#', $replacement, $url); - } - /** * Returns form field from XPath query. *