Last active
January 19, 2019 20:27
-
-
Save Adroit11/3e1393cc7fbb4eb91e5c40196690561f to your computer and use it in GitHub Desktop.
libraryTestCase for DELETE
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"); | |
} | |
public function testDeleteLibrary() { | |
$id = 1; | |
$env = Environment::mock([ | |
'REQUEST_METHOD' => 'DELETE', | |
'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." deleted successfully"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment