Skip to content

Instantly share code, notes, and snippets.

@paulredmond
Created November 15, 2017 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulredmond/5c3463238bbe84c634074a9344c22fdf to your computer and use it in GitHub Desktop.
Save paulredmond/5c3463238bbe84c634074a9344c22fdf to your computer and use it in GitHub Desktop.
Bootstrap the Request instance in Lumen 5.5
<?php
namespace Tests;
use Illuminate\Http\Request;
use Laravel\Lumen\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
/**
* Creates the application.
*
* @return \Laravel\Lumen\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$uri = $app->make('config')->get('app.url', 'http://localhost');
$components = parse_url($uri);
$server = $_SERVER;
if (isset($components['path'])) {
$server = array_merge($server, [
'SCRIPT_FILENAME' => $components['path'],
'SCRIPT_NAME' => $components['path'],
]);
}
$app->instance('request', Request::create(
$uri, 'GET', [], [], [], $server
));
return $app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment