Skip to content

Instantly share code, notes, and snippets.

@Adroit11
Last active January 19, 2019 15:17
Show Gist options
  • Save Adroit11/57bea05514debf62e406a6eec2cb43e6 to your computer and use it in GitHub Desktop.
Save Adroit11/57bea05514debf62e406a6eec2cb43e6 to your computer and use it in GitHub Desktop.
updated libraryTestCase file
<?php
use Library\App\LibraryRoute;
use Slim\Http\Environment;
use Slim\Http\Request;
use PHPUnit\Framework\TestCase;
class LibraryTestCase extends TestCase
{
protected $app;
public function setUp()
{
$this->app = (new LibraryRoute())->get();
}
public function testLibraryGet() {
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/',
]);
$req = Request::createFromEnvironment($env);
$this->app->getContainer()['request'] = $req;
$response = $this->app->run(true); //tells Slim to run the app instance and instead of return HTTP headers and body of the response it should return an object.
$this->assertSame($response->getStatusCode(), 200);
$this->assertSame((string)$response->getBody(), "Welcome to the Adroit Library Demo.");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment