14
14
use Behat \Mink \Exception \UnsupportedDriverActionException ;
15
15
use Symfony \Component \BrowserKit \Client ;
16
16
use Symfony \Component \BrowserKit \Cookie ;
17
- use Symfony \Component \BrowserKit \Request ;
18
17
use Symfony \Component \BrowserKit \Response ;
19
18
use Symfony \Component \DomCrawler \Crawler ;
20
19
use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
23
22
use Symfony \Component \DomCrawler \Field \InputFormField ;
24
23
use Symfony \Component \DomCrawler \Field \TextareaFormField ;
25
24
use Symfony \Component \DomCrawler \Form ;
26
- use Symfony \Component \HttpFoundation \Request as HttpFoundationRequest ;
27
- use Symfony \Component \HttpFoundation \Response as HttpFoundationResponse ;
28
25
use Symfony \Component \HttpKernel \Client as HttpKernelClient ;
29
26
30
27
/**
@@ -153,19 +150,7 @@ public function visit($url)
153
150
*/
154
151
public function getCurrentUrl ()
155
152
{
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 ();
169
154
170
155
if ($ request === null ) {
171
156
throw new DriverException ('Unable to access the request before visiting a page ' );
@@ -540,16 +525,6 @@ public function submitForm($xpath)
540
525
*/
541
526
protected function getResponse ()
542
527
{
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
-
553
528
$ response = $ this ->client ->getInternalResponse ();
554
529
555
530
if (null === $ response ) {
@@ -559,64 +534,6 @@ protected function getResponse()
559
534
return $ response ;
560
535
}
561
536
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
-
620
537
/**
621
538
* Prepares URL for visiting.
622
539
* Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().
0 commit comments