Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Slim Test class
<?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());
}
}
@jmperez127

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.