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 ' );
@@ -553,16 +538,6 @@ public function submitForm($xpath)
553
538
*/
554
539
protected function getResponse ()
555
540
{
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
-
566
541
$ response = $ this ->client ->getInternalResponse ();
567
542
568
543
if (null === $ response ) {
@@ -572,64 +547,6 @@ protected function getResponse()
572
547
return $ response ;
573
548
}
574
549
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
-
633
550
/**
634
551
* Prepares URL for visiting.
635
552
* Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().
0 commit comments