Last active
August 26, 2016 06:49
-
-
Save shahariaazam/8523437 to your computer and use it in GitHub Desktop.
Slim Test class
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 | |
require_once __DIR__ . '/../vendor/autoload.php'; | |
use Slim\Environment; | |
class RoutesTest extends PHPUnit_Framework_TestCase | |
{ | |
public function request($method, $path, $options = array()) | |
{ | |
// Capture STDOUT | |
ob_start(); | |
// Prepare a mock environment | |
Environment::mock(array_merge(array( | |
'REQUEST_METHOD' => $method, | |
'PATH_INFO' => $path, | |
'SERVER_NAME' => 'slim-test.dev', | |
), $options)); | |
$app = new \Slim\Slim(); | |
$this->app = $app; | |
$this->request = $app->request(); | |
$this->response = $app->response(); | |
// Return STDOUT | |
return ob_get_clean(); | |
} | |
public function get($path, $options = array()) | |
{ | |
$this->request('GET', $path, $options); | |
} | |
public function testIndex() | |
{ | |
$this->get('/'); | |
$this->assertEquals('200', $this->response->status()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am I missing something? it asserts everything even if routes are defined incorrectly, for example the following code
$this->get('/invalid */ route');
$this->assertEquals('200', $this->response->status());
outputs OK (1 test, 1 assertion)