Skip to content

Instantly share code, notes, and snippets.

@Adroit11
Created January 19, 2019 15:19
Show Gist options
  • Save Adroit11/9843f275f8adbd4ad6b32d182ad97e59 to your computer and use it in GitHub Desktop.
Save Adroit11/9843f275f8adbd4ad6b32d182ad97e59 to your computer and use it in GitHub Desktop.
updated library testcase to get all libraries
<?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);
$this->assertSame($response->getStatusCode(), 200);
$this->assertSame((string)$response->getBody(), "Welcome to the Adroit Library Demo.");
}
public function testGetAllLibraries() {
$env = Environment::mock([
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => '/library',
]);
$req = Request::createFromEnvironment($env);
$this->app->getContainer()['request'] = $req;
$response = $this->app->run(true);
$this->assertSame($response->getStatusCode(), 200);
$result = json_decode($response->getBody(), true);
$this->assertSame($result["message"], "Welcome, please pick a libray");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment