From 314e95242b0565c340bafc3bbb572fe7b62587d3 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Thu, 30 Jan 2014 19:19:10 +0100 Subject: [PATCH] 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().