Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Slim Test class
require_once __DIR__ . '/../vendor/autoload.php';
use Slim\Environment;
class RoutesTest extends PHPUnit_Framework_TestCase
public function request($method, $path, $options = array())
// Capture STDOUT
// Prepare a mock environment
'REQUEST_METHOD' => $method,
'PATH_INFO' => $path,
'SERVER_NAME' => '',
), $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->assertEquals('200', $this->response->status());

This comment has been minimized.

Copy link

@jmperez127 jmperez127 commented Dec 4, 2015

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.