I was using Slim 3 and am now migrating to Slim 4.
I was able to execute PHP Unit Tests in Slim 3 and try to rewrite them to Slim 4. Here is a simplified code snippet:
use \PHPUnit\Framework\TestCase;
use \RestApp;
use \Slim\Psr7\Environment;
use \Slim\Psr7\Request;
class RestAppTest extends TestCase {
private $app;
public function setUp() {
$this->app = new RestApp();
}
public function testFunctionality() {
$env = Environment::mock([
'REQUEST_METHOD' => 'POST',
'REQUEST_URI' => '/v1/Users'
]);
$req = Request::createFromEnvironment($env);
$attributes = array();
...
$req = $req->withParsedBody($attributes);
$this->app->getApp()->getContainer()['request'] = $req;
$response = $this->app->run(true);
$this->assertSame($response->getStatusCode(), 201);
....
}
}
Unfortunately, Request::createFromEnvironment($env); is not available any more on \Slim\Psr7\Request. How am I able to create a \Slim\Psr7\Request from the environment?