Skip to content

Instantly share code, notes, and snippets.

@igorw
Created January 1, 2011 22:14
Show Gist options
  • Select an option

  • Save igorw/762053 to your computer and use it in GitHub Desktop.

Select an option

Save igorw/762053 to your computer and use it in GitHub Desktop.
<?php
require_once __DIR__.'/silex.phar';
require_once __DIR__.'/twig/lib/Twig/Autoloader.php';
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Silex\Framework;
Twig_Autoloader::register();
$twig = new Twig_Environment(
new Twig_Loader_Filesystem(__DIR__.'/templates'),
array('debug' => true)
);
$render = function($name, array $context = array()) use ($twig) {
return $twig->loadTemplate($name)->render($context);
};
$app = Framework::create();
$app->get('/hello', function() use ($render) {
return $render('hello.html');
});
$app->error(function($e) {
if ($e instanceof NotFoundHttpException) {
return new Response('The file could not be found.', 404);
}
});
return $app;
<?php
// functional test
use Symfony\Component\HttpFoundation\Request;
class test extends PHPUnit_Framework_TestCase
{
protected $app = null;
public function setUp()
{
$this->app = require __DIR__.'/app.php';
}
public function testHello()
{
$request = Request::create('http://test.com/hello');
$response = $this->app->handle($request);
$this->assertEquals(200, $response->getStatusCode(), '/hello should return ok response');
$this->assertContains('stranger', $response->getContent());
}
public function testAwesome()
{
$request = Request::create('http://test.com/awesome');
$response = $this->app->handle($request);
$this->assertEquals(200, $response->getStatusCode(), '/awesome should return not found response');
}
}
<?php
$app = require __DIR__.'/app.php';
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment