Skip to content

Commit 0062335

Browse files
committed
Removed the BC layers for Symfony 2.2 and older
1 parent 384c50d commit 0062335

File tree

2 files changed

+3
-86
lines changed

2 files changed

+3
-86
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"require": {
1818
"php": ">=5.3.1",
1919
"behat/mink": "~1.6@dev",
20-
"symfony/browser-kit": "~2.0",
21-
"symfony/dom-crawler": "~2.0"
20+
"symfony/browser-kit": "~2.3",
21+
"symfony/dom-crawler": "~2.3"
2222
},
2323

2424
"require-dev": {

src/BrowserKitDriver.php

+1-84
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Behat\Mink\Session;
1717
use Symfony\Component\BrowserKit\Client;
1818
use Symfony\Component\BrowserKit\Cookie;
19-
use Symfony\Component\BrowserKit\Request;
2019
use Symfony\Component\BrowserKit\Response;
2120
use Symfony\Component\DomCrawler\Crawler;
2221
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
@@ -25,8 +24,6 @@
2524
use Symfony\Component\DomCrawler\Field\InputFormField;
2625
use Symfony\Component\DomCrawler\Field\TextareaFormField;
2726
use Symfony\Component\DomCrawler\Form;
28-
use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;
29-
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;
3027
use Symfony\Component\HttpKernel\Client as HttpKernelClient;
3128

3229
/**
@@ -164,19 +161,7 @@ public function visit($url)
164161
*/
165162
public function getCurrentUrl()
166163
{
167-
if (method_exists($this->client, 'getInternalRequest')) {
168-
$request = $this->client->getInternalRequest();
169-
} else {
170-
// BC layer for BrowserKit 2.2.x and older
171-
$request = $this->client->getRequest();
172-
173-
if (null !== $request && !$request instanceof Request && !$request instanceof HttpFoundationRequest) {
174-
throw new DriverException(sprintf(
175-
'The BrowserKit client returned an unsupported request implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer.',
176-
get_class($request)
177-
));
178-
}
179-
}
164+
$request = $this->client->getInternalRequest();
180165

181166
if ($request === null) {
182167
throw new DriverException('Unable to access the request before visiting a page');
@@ -564,16 +549,6 @@ public function submitForm($xpath)
564549
*/
565550
protected function getResponse()
566551
{
567-
if (!method_exists($this->client, 'getInternalResponse')) {
568-
$implementationResponse = $this->client->getResponse();
569-
570-
if (null === $implementationResponse) {
571-
throw new DriverException('Unable to access the response before visiting a page');
572-
}
573-
574-
return $this->convertImplementationResponse($implementationResponse);
575-
}
576-
577552
$response = $this->client->getInternalResponse();
578553

579554
if (null === $response) {
@@ -583,64 +558,6 @@ protected function getResponse()
583558
return $response;
584559
}
585560

586-
/**
587-
* Gets the BrowserKit Response for legacy BrowserKit versions.
588-
*
589-
* Before 2.3.0, there was no Client::getInternalResponse method, and the
590-
* return value of Client::getResponse can be anything when the implementation
591-
* uses Client::filterResponse because of a bad choice done in BrowserKit and
592-
* kept for BC reasons (the Client::getInternalResponse method has been added
593-
* to solve it).
594-
*
595-
* This implementation supports client which don't rely Client::filterResponse
596-
* and clients which use an HttpFoundation Response (like the HttpKernel client).
597-
*
598-
* @param object $response the response specific to the BrowserKit implementation
599-
*
600-
* @return Response
601-
*
602-
* @throws DriverException If the response cannot be converted to a BrowserKit response
603-
*/
604-
private function convertImplementationResponse($response)
605-
{
606-
if ($response instanceof Response) {
607-
return $response;
608-
}
609-
610-
// due to a bug, the HttpKernel client implementation returns the HttpFoundation response
611-
// The conversion logic is copied from Symfony\Component\HttpKernel\Client::filterResponse
612-
if ($response instanceof HttpFoundationResponse) {
613-
$headers = $response->headers->all();
614-
if ($response->headers->getCookies()) {
615-
$cookies = array();
616-
foreach ($response->headers->getCookies() as $cookie) {
617-
$cookies[] = new Cookie(
618-
$cookie->getName(),
619-
$cookie->getValue(),
620-
$cookie->getExpiresTime(),
621-
$cookie->getPath(),
622-
$cookie->getDomain(),
623-
$cookie->isSecure(),
624-
$cookie->isHttpOnly()
625-
);
626-
}
627-
$headers['Set-Cookie'] = $cookies;
628-
}
629-
630-
// this is needed to support StreamedResponse
631-
ob_start();
632-
$response->sendContent();
633-
$content = ob_get_clean();
634-
635-
return new Response($content, $response->getStatusCode(), $headers);
636-
}
637-
638-
throw new DriverException(sprintf(
639-
'The BrowserKit client returned an unsupported response implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer.',
640-
get_class($response)
641-
));
642-
}
643-
644561
/**
645562
* Prepares URL for visiting.
646563
* Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().

0 commit comments

Comments
 (0)