1616use Behat \Mink \Session ;
1717use Symfony \Component \BrowserKit \Client ;
1818use Symfony \Component \BrowserKit \Cookie ;
19- use Symfony \Component \BrowserKit \Request ;
2019use Symfony \Component \BrowserKit \Response ;
2120use Symfony \Component \DomCrawler \Crawler ;
2221use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
2524use Symfony \Component \DomCrawler \Field \InputFormField ;
2625use Symfony \Component \DomCrawler \Field \TextareaFormField ;
2726use Symfony \Component \DomCrawler \Form ;
28- use Symfony \Component \HttpFoundation \Request as HttpFoundationRequest ;
29- use Symfony \Component \HttpFoundation \Response as HttpFoundationResponse ;
3027use 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