6
6
use CodeIgniter \HTTP \UserAgent ;
7
7
use CodeIgniter \HTTP \IncomingRequest ;
8
8
use Config \App ;
9
+ use Config \Services ;
9
10
10
11
/**
11
12
* Class FeatureTestCase
@@ -20,13 +21,15 @@ class FeatureTestCase extends CIDatabaseTestCase
20
21
/**
21
22
* If present, will override application
22
23
* routes when using call().
24
+ *
23
25
* @var \CodeIgniter\Router\RouteCollection
24
26
*/
25
27
protected $ routes ;
26
28
27
29
/**
28
30
* Values to be set in the SESSION global
29
31
* before running the test.
32
+ *
30
33
* @var array
31
34
*/
32
35
protected $ session = [];
@@ -103,10 +106,20 @@ public function call(string $method, string $path, array $params = null)
103
106
104
107
$ request = $ this ->populateGlobals ($ method , $ request , $ params );
105
108
109
+ // Make sure any other classes that might call the request
110
+ // instance get the right one.
111
+ Services::injectMock ('request ' , $ request );
112
+
106
113
$ response = $ this ->app
107
114
->setRequest ($ request )
108
115
->run ($ this ->routes , true );
109
116
117
+ // Clean up any open output buffers
118
+ if (ob_get_level () > 0 )
119
+ {
120
+ ob_end_clean ();
121
+ }
122
+
110
123
$ featureResponse = new FeatureResponse ($ response );
111
124
112
125
return $ featureResponse ;
@@ -208,16 +221,16 @@ public function options(string $path, array $params = null)
208
221
*
209
222
* @param string $method
210
223
* @param string|null $path
211
- * @param string |null $params
224
+ * @param array |null $params
212
225
*
213
226
* @return \CodeIgniter\HTTP\IncomingRequest
214
227
*/
215
- protected function setupRequest (string $ method , string $ path = null , string $ params = null ): IncomingRequest
228
+ protected function setupRequest (string $ method , string $ path = null , array $ params = null ): IncomingRequest
216
229
{
217
230
$ config = config (App::class);
218
- $ uri = new URI ($ config ->baseURL .'/ ' . trim ($ path , '/ ' ));
231
+ $ uri = new URI ($ config ->baseURL . '/ ' . trim ($ path , '/ ' ));
219
232
220
- $ request = new IncomingRequest ($ config , clone ($ uri ), $ params , new UserAgent ());
233
+ $ request = new IncomingRequest ($ config , clone ($ uri ), $ params , new UserAgent ());
221
234
$ request ->uri = $ uri ;
222
235
223
236
$ request ->setMethod ($ method );
0 commit comments