Last active
January 19, 2019 20:27
-
-
Save Adroit11/143fa1bc7ee9c622c014b87d134f1abe to your computer and use it in GitHub Desktop.
Updated with post request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"); | |
} | |
public function testPostLibrary() { | |
$id = 1; | |
$env = Environment::mock([ | |
'REQUEST_METHOD' => 'POST', | |
'REQUEST_URI' => '/library/'.$id, | |
'CONTENT_TYPE' => 'application/x-www-form-urlencoded', | |
]); | |
$req = Request::createFromEnvironment($env)->withParsedBody([]); | |
$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"], "library ".$id." updated successfully"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment