55namespace Codeception \Lib \Connector ;
66
77use Codeception \Configuration ;
8- use Codeception \Lib \Connector \Mezzio \ResponseCollector ;
98use Exception ;
109use Interop \Container \ContainerInterface ;
11- use Symfony \Component \BrowserKit \AbstractBrowser as Client ;
12- use Symfony \Component \BrowserKit \Response ;
13- use Symfony \Component \BrowserKit \Request as BrowserKitRequest ;
1410use Laminas \Diactoros \ServerRequest ;
15- use Mezzio \Application ;
1611use Laminas \Diactoros \UploadedFile ;
12+ use Mezzio \Application ;
13+ use Symfony \Component \BrowserKit \AbstractBrowser as Client ;
14+ use Symfony \Component \BrowserKit \Request as BrowserKitRequest ;
15+ use Symfony \Component \BrowserKit \Response ;
1716
1817class Mezzio extends Client
1918{
19+ private Application $ application ;
2020
21- /**
22- * @var Application
23- */
24- private $ application ;
25- /**
26- * @var ResponseCollector
27- */
28- private $ responseCollector ;
29-
30- /**
31- * @var ContainerInterface
32- */
33- private $ container ;
21+ private ContainerInterface $ container ;
3422
35- /**
36- * @var array Configuration of the module
37- */
38- private $ config ;
23+ private array $ config ;
3924
4025 /**
4126 * @param BrowserKitRequest $request
@@ -65,15 +50,13 @@ public function doRequest($request)
6550 //required by WhoopsErrorHandler
6651 $ serverParams ['SCRIPT_NAME ' ] = 'Codeception ' ;
6752 }
68-
53+
6954 $ cookies = $ request ->getCookies ();
7055 $ headers = $ this ->extractHeaders ($ request );
7156
7257 //set cookie header because dflydev/fig-cookies reads cookies from header
7358 if (!empty ($ cookies )) {
74- $ headers ['cookie ' ] = implode ('; ' , array_map (function ($ key , $ value ) {
75- return "$ key= $ value " ;
76- }, array_keys ($ cookies ), $ cookies ));
59+ $ headers ['cookie ' ] = implode ('; ' , array_map (fn ($ key , $ value ) => "$ key= $ value " , array_keys ($ cookies ), $ cookies ));
7760 }
7861
7962 $ mezzioRequest = new ServerRequest (
@@ -99,15 +82,7 @@ public function doRequest($request)
9982 $ application = $ this ->application ;
10083 }
10184
102- if (method_exists ($ application , 'handle ' )) {
103- // Mezzio v3
104- $ response = $ application ->handle ($ mezzioRequest );
105- } else {
106- //Older versions
107- $ application ->run ($ mezzioRequest );
108- $ response = $ this ->responseCollector ->getResponse ();
109- $ this ->responseCollector ->clearResponse ();
110- }
85+ $ response = $ application ->handle ($ mezzioRequest );
11186
11287 chdir ($ cwd );
11388
@@ -189,30 +164,9 @@ public function initApplication(): Application
189164
190165 $ this ->application = $ app ;
191166
192- $ this ->initResponseCollector ();
193-
194167 return $ app ;
195168 }
196169
197- private function initResponseCollector (): void
198- {
199- if (!method_exists ($ this ->application , 'getEmitter ' )) {
200- //Does not exist in Mezzio v3
201- return ;
202- }
203-
204- /**
205- * @var Mezzio\Emitter\EmitterStack
206- */
207- $ emitterStack = $ this ->application ->getEmitter ();
208- while (!$ emitterStack ->isEmpty ()) {
209- $ emitterStack ->pop ();
210- }
211-
212- $ this ->responseCollector = new ResponseCollector ;
213- $ emitterStack ->unshift ($ this ->responseCollector );
214- }
215-
216170 public function getContainer (): ContainerInterface
217171 {
218172 return $ this ->container ;
@@ -221,7 +175,6 @@ public function getContainer(): ContainerInterface
221175 public function setApplication (Application $ application ): void
222176 {
223177 $ this ->application = $ application ;
224- $ this ->initResponseCollector ();
225178 }
226179
227180 public function setConfig (array $ config ): void
0 commit comments