Skip to content

Commit 74ffe69

Browse files
committed
Merge pull request #98 from stof/bump_symfony_deps
Removed the BC layers for Symfony 2.2 and older
2 parents 2a7a727 + abcdf72 commit 74ffe69

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.7@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
@@ -14,7 +14,6 @@
1414
use Behat\Mink\Exception\UnsupportedDriverActionException;
1515
use Symfony\Component\BrowserKit\Client;
1616
use Symfony\Component\BrowserKit\Cookie;
17-
use Symfony\Component\BrowserKit\Request;
1817
use Symfony\Component\BrowserKit\Response;
1918
use Symfony\Component\DomCrawler\Crawler;
2019
use Symfony\Component\DomCrawler\Field\ChoiceFormField;
@@ -23,8 +22,6 @@
2322
use Symfony\Component\DomCrawler\Field\InputFormField;
2423
use Symfony\Component\DomCrawler\Field\TextareaFormField;
2524
use Symfony\Component\DomCrawler\Form;
26-
use Symfony\Component\HttpFoundation\Request as HttpFoundationRequest;
27-
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;
2825
use Symfony\Component\HttpKernel\Client as HttpKernelClient;
2926

3027
/**
@@ -153,19 +150,7 @@ public function visit($url)
153150
*/
154151
public function getCurrentUrl()
155152
{
156-
if (method_exists($this->client, 'getInternalRequest')) {
157-
$request = $this->client->getInternalRequest();
158-
} else {
159-
// BC layer for BrowserKit 2.2.x and older
160-
$request = $this->client->getRequest();
161-
162-
if (null !== $request && !$request instanceof Request && !$request instanceof HttpFoundationRequest) {
163-
throw new DriverException(sprintf(
164-
'The BrowserKit client returned an unsupported request implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer.',
165-
get_class($request)
166-
));
167-
}
168-
}
153+
$request = $this->client->getInternalRequest();
169154

170155
if ($request === null) {
171156
throw new DriverException('Unable to access the request before visiting a page');
@@ -553,16 +538,6 @@ public function submitForm($xpath)
553538
*/
554539
protected function getResponse()
555540
{
556-
if (!method_exists($this->client, 'getInternalResponse')) {
557-
$implementationResponse = $this->client->getResponse();
558-
559-
if (null === $implementationResponse) {
560-
throw new DriverException('Unable to access the response before visiting a page');
561-
}
562-
563-
return $this->convertImplementationResponse($implementationResponse);
564-
}
565-
566541
$response = $this->client->getInternalResponse();
567542

568543
if (null === $response) {
@@ -572,64 +547,6 @@ protected function getResponse()
572547
return $response;
573548
}
574549

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

0 commit comments

Comments
 (0)