16
16
use Behat \Mink \Session ;
17
17
use Symfony \Component \BrowserKit \Client ;
18
18
use Symfony \Component \BrowserKit \Cookie ;
19
- use Symfony \Component \BrowserKit \Request ;
20
19
use Symfony \Component \BrowserKit \Response ;
21
20
use Symfony \Component \DomCrawler \Crawler ;
22
21
use Symfony \Component \DomCrawler \Field \ChoiceFormField ;
25
24
use Symfony \Component \DomCrawler \Field \InputFormField ;
26
25
use Symfony \Component \DomCrawler \Field \TextareaFormField ;
27
26
use Symfony \Component \DomCrawler \Form ;
28
- use Symfony \Component \HttpFoundation \Request as HttpFoundationRequest ;
29
- use Symfony \Component \HttpFoundation \Response as HttpFoundationResponse ;
30
27
use Symfony \Component \HttpKernel \Client as HttpKernelClient ;
31
28
32
29
/**
@@ -164,19 +161,7 @@ public function visit($url)
164
161
*/
165
162
public function getCurrentUrl ()
166
163
{
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 ();
180
165
181
166
if ($ request === null ) {
182
167
throw new DriverException ('Unable to access the request before visiting a page ' );
@@ -564,16 +549,6 @@ public function submitForm($xpath)
564
549
*/
565
550
protected function getResponse ()
566
551
{
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
-
577
552
$ response = $ this ->client ->getInternalResponse ();
578
553
579
554
if (null === $ response ) {
@@ -583,64 +558,6 @@ protected function getResponse()
583
558
return $ response ;
584
559
}
585
560
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
-
644
561
/**
645
562
* Prepares URL for visiting.
646
563
* Removes "*.php/" from urls and then passes it to BrowserKitDriver::visit().
0 commit comments