1414use Behat \Mink \Exception \UnsupportedDriverActionException ;
1515use Symfony \Component \BrowserKit \Client ;
1616use Symfony \Component \BrowserKit \Cookie ;
17- use Symfony \Component \BrowserKit \Request ;
1817use Symfony \Component \BrowserKit \Response ;
1918use Symfony \Component \DomCrawler \Crawler ;
2019use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
2322use Symfony \Component \DomCrawler \Field \InputFormField ;
2423use Symfony \Component \DomCrawler \Field \TextareaFormField ;
2524use Symfony \Component \DomCrawler \Form ;
26- use Symfony \Component \HttpFoundation \Request as HttpFoundationRequest ;
27- use Symfony \Component \HttpFoundation \Response as HttpFoundationResponse ;
2825use 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