Skip to content

Instantly share code, notes, and snippets.

@shahariaazam
Last active August 26, 2016 06:49
Show Gist options
  • Save shahariaazam/8523437 to your computer and use it in GitHub Desktop.
Save shahariaazam/8523437 to your computer and use it in GitHub Desktop.
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
Copy link

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