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 ' );
@@ -540,16 +525,6 @@ public function submitForm($xpath)
540525 */
541526 protected function getResponse ()
542527 {
543- if (!method_exists ($ this ->client , 'getInternalResponse ' )) {
544- $ implementationResponse = $ this ->client ->getResponse ();
545-
546- if (null === $ implementationResponse ) {
547- throw new DriverException ('Unable to access the response before visiting a page ' );
548- }
549-
550- return $ this ->convertImplementationResponse ($ implementationResponse );
551- }
552-
553528 $ response = $ this ->client ->getInternalResponse ();
554529
555530 if (null === $ response ) {
@@ -559,64 +534,6 @@ protected function getResponse()
559534 return $ response ;
560535 }
561536
562- /**
563- * Gets the BrowserKit Response for legacy BrowserKit versions.
564- *
565- * Before 2.3.0, there was no Client::getInternalResponse method, and the
566- * return value of Client::getResponse can be anything when the implementation
567- * uses Client::filterResponse because of a bad choice done in BrowserKit and
568- * kept for BC reasons (the Client::getInternalResponse method has been added
569- * to solve it).
570- *
571- * This implementation supports client which don't rely Client::filterResponse
572- * and clients which use an HttpFoundation Response (like the HttpKernel client).
573- *
574- * @param object $response the response specific to the BrowserKit implementation
575- *
576- * @return Response
577- *
578- * @throws DriverException If the response cannot be converted to a BrowserKit response
579- */
580- private function convertImplementationResponse ($ response )
581- {
582- if ($ response instanceof Response) {
583- return $ response ;
584- }
585-
586- // due to a bug, the HttpKernel client implementation returns the HttpFoundation response
587- // The conversion logic is copied from Symfony\Component\HttpKernel\Client::filterResponse
588- if ($ response instanceof HttpFoundationResponse) {
589- $ headers = $ response ->headers ->all ();
590- if ($ response ->headers ->getCookies ()) {
591- $ cookies = array ();
592- foreach ($ response ->headers ->getCookies () as $ cookie ) {
593- $ cookies [] = new Cookie (
594- $ cookie ->getName (),
595- $ cookie ->getValue (),
596- $ cookie ->getExpiresTime (),
597- $ cookie ->getPath (),
598- $ cookie ->getDomain (),
599- $ cookie ->isSecure (),
600- $ cookie ->isHttpOnly ()
601- );
602- }
603- $ headers ['Set-Cookie ' ] = $ cookies ;
604- }
605-
606- // this is needed to support StreamedResponse
607- ob_start ();
608- $ response ->sendContent ();
609- $ content = ob_get_clean ();
610-
611- return new Response ($ content , $ response ->getStatusCode (), $ headers );
612- }
613-
614- throw new DriverException (sprintf (
615- 'The BrowserKit client returned an unsupported response implementation: %s. Please upgrade your BrowserKit package to 2.3 or newer. ' ,
616- get_class ($ response )
617- ));
618- }
619-
620537 /**
621538 * Prepares URL for visiting.
622539 * Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().
0 commit comments