Created
January 1, 2011 22:14
-
-
Save igorw/762053 to your computer and use it in GitHub Desktop.
This file contains hidden or 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__.'/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; |
This file contains hidden or 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 | |
| // 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'); | |
| } | |
| } |
This file contains hidden or 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 | |
| $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