Skip to content

Commit 0cc5b7d

Browse files
committed
Fixing calls in FeatureTestCases.
1 parent cc0971b commit 0cc5b7d

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

system/Test/FeatureTestCase.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodeIgniter\HTTP\UserAgent;
77
use CodeIgniter\HTTP\IncomingRequest;
88
use Config\App;
9+
use Config\Services;
910

1011
/**
1112
* Class FeatureTestCase
@@ -20,13 +21,15 @@ class FeatureTestCase extends CIDatabaseTestCase
2021
/**
2122
* If present, will override application
2223
* routes when using call().
24+
*
2325
* @var \CodeIgniter\Router\RouteCollection
2426
*/
2527
protected $routes;
2628

2729
/**
2830
* Values to be set in the SESSION global
2931
* before running the test.
32+
*
3033
* @var array
3134
*/
3235
protected $session = [];
@@ -103,10 +106,20 @@ public function call(string $method, string $path, array $params = null)
103106

104107
$request = $this->populateGlobals($method, $request, $params);
105108

109+
// Make sure any other classes that might call the request
110+
// instance get the right one.
111+
Services::injectMock('request', $request);
112+
106113
$response = $this->app
107114
->setRequest($request)
108115
->run($this->routes, true);
109116

117+
// Clean up any open output buffers
118+
if (ob_get_level() > 0)
119+
{
120+
ob_end_clean();
121+
}
122+
110123
$featureResponse = new FeatureResponse($response);
111124

112125
return $featureResponse;
@@ -208,16 +221,16 @@ public function options(string $path, array $params = null)
208221
*
209222
* @param string $method
210223
* @param string|null $path
211-
* @param string|null $params
224+
* @param array|null $params
212225
*
213226
* @return \CodeIgniter\HTTP\IncomingRequest
214227
*/
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
216229
{
217230
$config = config(App::class);
218-
$uri = new URI($config->baseURL .'/'. trim($path, '/ '));
231+
$uri = new URI($config->baseURL . '/' . trim($path, '/ '));
219232

220-
$request = new IncomingRequest($config, clone($uri), $params, new UserAgent());
233+
$request = new IncomingRequest($config, clone($uri), $params, new UserAgent());
221234
$request->uri = $uri;
222235

223236
$request->setMethod($method);

0 commit comments

Comments
 (0)