Commit af53bcb4 authored by Fabien Potencier's avatar Fabien Potencier

renamed Framework to Application

parent 744af92b
......@@ -4,9 +4,9 @@ Silex is a simple web framework to develop simple websites:
require_once __DIR__.'/silex.phar';
use Silex\Framework;
use Silex\Application;
$app = new Framework();
$app = new Application();
$app->get('/hello/{name}', function($name) {
return "Hello $name";
......
......@@ -29,7 +29,7 @@ use Symfony\Component\Routing\Matcher\UrlMatcher;
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class Framework extends HttpKernel implements EventSubscriberInterface
class Application extends HttpKernel implements EventSubscriberInterface
{
private $dispatcher;
private $routes;
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
/**
* Application test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class ApplicationTest extends \PHPUnit_Framework_TestCase
{
public function testFluidInterface()
{
$application = new Application();
$returnValue = $application->match('/foo', function() {});
$this->assertSame($application, $returnValue, '->match() should return $this');
$returnValue = $application->get('/foo', function() {});
$this->assertSame($application, $returnValue, '->get() should return $this');
$returnValue = $application->post('/foo', function() {});
$this->assertSame($application, $returnValue, '->post() should return $this');
$returnValue = $application->put('/foo', function() {});
$this->assertSame($application, $returnValue, '->put() should return $this');
$returnValue = $application->delete('/foo', function() {});
$this->assertSame($application, $returnValue, '->delete() should return $this');
$returnValue = $application->before(function() {});
$this->assertSame($application, $returnValue, '->before() should return $this');
$returnValue = $application->after(function() {});
$this->assertSame($application, $returnValue, '->after() should return $this');
$returnValue = $application->error(function() {});
$this->assertSame($application, $returnValue, '->error() should return $this');
}
public function testGetRequest()
{
$application = new Application();
$application->get('/', function() {
return 'root';
});
$request = Request::create('/');
$application->handle($request);
$this->assertEquals($request, $application->getRequest());
}
}
......@@ -11,7 +11,7 @@
namespace Silex\Tests;
use Silex\Framework;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -29,25 +29,25 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$test = $this;
$framework = new Framework();
$application = new Application();
$framework->before(function() use(&$i, $test) {
$application->before(function() use(&$i, $test) {
$test->assertEquals(0, $i);
$i++;
});
$framework->match('/foo', function() use(&$i, $test) {
$application->match('/foo', function() use(&$i, $test) {
$test->assertEquals(1, $i);
$i++;
});
$framework->after(function() use(&$i, $test) {
$application->after(function() use(&$i, $test) {
$test->assertEquals(2, $i);
$i++;
});
$request = Request::create('/foo');
$framework->handle($request);
$application->handle($request);
$this->assertEquals(3, $i);
}
......@@ -56,19 +56,19 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
{
$i = 0;
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() use (&$i) {
$application->match('/foo', function() use (&$i) {
$i++;
return new Response('foo');
});
$framework->after(function() use(&$i) {
$application->after(function() use(&$i) {
$i++;
});
$request = Request::create('/foo');
$framework->handle($request);
$application->handle($request);
$this->assertEquals(2, $i);
}
......@@ -79,35 +79,35 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$test = $this;
$framework = new Framework();
$application = new Application();
$framework->before(function() use(&$i, $test) {
$application->before(function() use(&$i, $test) {
$test->assertEquals(0, $i);
$i++;
});
$framework->before(function() use(&$i, $test) {
$application->before(function() use(&$i, $test) {
$test->assertEquals(1, $i);
$i++;
});
$framework->match('/foo', function() use(&$i, $test) {
$application->match('/foo', function() use(&$i, $test) {
$test->assertEquals(2, $i);
$i++;
});
$framework->after(function() use(&$i, $test) {
$application->after(function() use(&$i, $test) {
$test->assertEquals(3, $i);
$i++;
});
$framework->after(function() use(&$i, $test) {
$application->after(function() use(&$i, $test) {
$test->assertEquals(4, $i);
$i++;
});
$request = Request::create('/foo');
$framework->handle($request);
$application->handle($request);
$this->assertEquals(5, $i);
}
......
......@@ -11,7 +11,7 @@
namespace Silex\Tests;
use Silex\Framework;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -25,15 +25,15 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testNoErrorHandler()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
try {
$request = Request::create('/foo');
$framework->handle($request);
$application->handle($request);
$this->fail('->handle() should not catch exceptions where no error handler was supplied');
} catch (\RuntimeException $e) {
$this->assertEquals('foo exception', $e->getMessage());
......@@ -42,71 +42,71 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
public function testOneErrorHandler()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
$framework->error(function($e) {
$application->error(function($e) {
return new Response('foo exception handler');
});
$request = Request::create('/foo');
$this->checkRouteResponse($framework, '/foo', 'foo exception handler');
$this->checkRouteResponse($application, '/foo', 'foo exception handler');
}
public function testMultipleErrorHandlers()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
$errors = 0;
$framework->error(function($e) use (&$errors) {
$application->error(function($e) use (&$errors) {
$errors++;
});
$framework->error(function($e) use (&$errors) {
$application->error(function($e) use (&$errors) {
$errors++;
});
$framework->error(function($e) use (&$errors) {
$application->error(function($e) use (&$errors) {
$errors++;
return new Response('foo exception handler');
});
$framework->error(function($e) use (&$errors) {
$application->error(function($e) use (&$errors) {
// should not execute
$errors++;
});
$request = Request::create('/foo');
$this->checkRouteResponse($framework, '/foo', 'foo exception handler', 'should return the first response returned by an exception handler');
$this->checkRouteResponse($application, '/foo', 'foo exception handler', 'should return the first response returned by an exception handler');
$this->assertEquals(3, $errors, 'should execute error handlers until a response is returned');
}
public function testNoResponseErrorHandler()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
$errors = 0;
$framework->error(function($e) use (&$errors) {
$application->error(function($e) use (&$errors) {
$errors++;
});
try {
$request = Request::create('/foo');
$framework->handle($request);
$application->handle($request);
$this->fail('->handle() should not catch exceptions where an empty error handler was supplied');
} catch (\RuntimeException $e) {
$this->assertEquals('foo exception', $e->getMessage());
......@@ -117,45 +117,45 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
public function testStringResponseErrorHandler()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
$framework->error(function($e) {
$application->error(function($e) {
return 'foo exception handler';
});
$request = Request::create('/foo');
$this->checkRouteResponse($framework, '/foo', 'foo exception handler', 'should accept a string response from the error handler');
$this->checkRouteResponse($application, '/foo', 'foo exception handler', 'should accept a string response from the error handler');
}
public function testErrorHandlerException()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
throw new \RuntimeException('foo exception');
});
$framework->error(function($e) {
$application->error(function($e) {
throw new \RuntimeException('foo exception handler exception');
});
try {
$request = Request::create('/foo');
$this->checkRouteResponse($framework, '/foo', 'foo exception handler', 'should accept a string response from the error handler');
$this->checkRouteResponse($application, '/foo', 'foo exception handler', 'should accept a string response from the error handler');
$this->fail('->handle() should not catch exceptions thrown from an error handler');
} catch (\RuntimeException $e) {
$this->assertEquals('foo exception handler exception', $e->getMessage());
}
}
protected function checkRouteResponse($framework, $path, $expectedContent, $method = 'get', $message = null)
protected function checkRouteResponse($application, $path, $expectedContent, $method = 'get', $message = null)
{
$request = Request::create($path, $method);
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertEquals($expectedContent, $response->getContent(), $message);
}
}
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Silex\Tests;
use Silex\Framework;
use Symfony\Component\HttpFoundation\Request;
/**
* Framework test cases.
*
* @author Igor Wiedler <igor@wiedler.ch>
*/
class FrameworkTest extends \PHPUnit_Framework_TestCase
{
public function testFluidInterface()
{
$framework = new Framework();
$returnValue = $framework->match('/foo', function() {});
$this->assertSame($framework, $returnValue, '->match() should return $this');
$returnValue = $framework->get('/foo', function() {});
$this->assertSame($framework, $returnValue, '->get() should return $this');
$returnValue = $framework->post('/foo', function() {});
$this->assertSame($framework, $returnValue, '->post() should return $this');
$returnValue = $framework->put('/foo', function() {});
$this->assertSame($framework, $returnValue, '->put() should return $this');
$returnValue = $framework->delete('/foo', function() {});
$this->assertSame($framework, $returnValue, '->delete() should return $this');
$returnValue = $framework->before(function() {});
$this->assertSame($framework, $returnValue, '->before() should return $this');
$returnValue = $framework->after(function() {});
$this->assertSame($framework, $returnValue, '->after() should return $this');
$returnValue = $framework->error(function() {});
$this->assertSame($framework, $returnValue, '->error() should return $this');
}
public function testGetRequest()
{
$framework = new Framework();
$framework->get('/', function() {
return 'root';
});
$request = Request::create('/');
$framework->handle($request);
$this->assertEquals($request, $framework->getRequest());
}
}
......@@ -11,7 +11,7 @@
namespace Silex\Tests;
use Silex\Framework;
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
......@@ -27,64 +27,64 @@ class RouterTest extends \PHPUnit_Framework_TestCase
{
public function testMapRouting()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
return 'foo';
});
$framework->match('/bar', function() {
$application->match('/bar', function() {
return 'bar';
});
$framework->match('/', function() {
$application->match('/', function() {
return 'root';
});
$this->checkRouteResponse($framework, '/foo', 'foo');
$this->checkRouteResponse($framework, '/bar', 'bar');
$this->checkRouteResponse($framework, '/', 'root');
$this->checkRouteResponse($application, '/foo', 'foo');
$this->checkRouteResponse($application, '/bar', 'bar');
$this->checkRouteResponse($application, '/', 'root');
}
public function testStatusCode()
{
$framework = new Framework();
$application = new Application();
$framework->put('/created', function() {
$application->put('/created', function() {
return new Response('', 201);
});
$framework->match('/forbidden', function() {
$application->match('/forbidden', function() {
return new Response('', 403);
});
$framework->match('/not_found', function() {
$application->match('/not_found', function() {
return new Response('', 404);
});
$request = Request::create('/created', 'put');
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertEquals(201, $response->getStatusCode());
$request = Request::create('/forbidden');
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertEquals(403, $response->getStatusCode());
$request = Request::create('/not_found');
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertEquals(404, $response->getStatusCode());
}
public function testRedirect()
{
$framework = new Framework();
$application = new Application();
$framework->match('/redirect', function() {
$application->match('/redirect', function() {
return new RedirectResponse('/target');
});
$request = Request::create('/redirect');
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertTrue($response->isRedirected('/target'));
}
......@@ -93,68 +93,68 @@ class RouterTest extends \PHPUnit_Framework_TestCase
*/
public function testMissingRoute()
{
$framework = new Framework();
$application = new Application();
$request = Request::create('/baz');
$framework->handle($request);
$application->handle($request);
}
public function testMethodRouting()
{
$framework = new Framework();
$application = new Application();
$framework->match('/foo', function() {
$application->match('/foo', function() {
return 'foo';
});
$framework->match('/bar', function() {
$application->match('/bar', function() {
return 'bar';
}, 'GET|POST');
$framework->get('/resource', function() {
$application->get('/resource', function() {
return 'get resource';
});
$framework->post('/resource', function() {
$application->post('/resource', function() {
return 'post resource';
});
$framework->put('/resource', function() {
$application->put('/resource', function() {
return 'put resource';
});
$framework->delete('/resource', function() {
$application->delete('/resource', function() {
return 'delete resource';
});
$this->checkRouteResponse($framework, '/foo', 'foo');
$this->checkRouteResponse($framework, '/bar', 'bar');
$this->checkRouteResponse($framework, '/bar', 'bar', 'post');
$this->checkRouteResponse($framework, '/resource', 'get resource');
$this->checkRouteResponse($framework, '/resource', 'post resource', 'post');
$this->checkRouteResponse($framework, '/resource', 'put resource', 'put');
$this->checkRouteResponse($framework, '/resource', 'delete resource', 'delete');
$this->checkRouteResponse($application, '/foo', 'foo');
$this->checkRouteResponse($application, '/bar', 'bar');
$this->checkRouteResponse($application, '/bar', 'bar', 'post');
$this->checkRouteResponse($application, '/resource', 'get resource');
$this->checkRouteResponse($application, '/resource', 'post resource', 'post');
$this->checkRouteResponse($application, '/resource', 'put resource', 'put');
$this->checkRouteResponse($application, '/resource', 'delete resource', 'delete');
}
public function testRequestShouldBeStoredRegardlessOfRouting() {
$framework = new Framework();
$framework->get('/foo', function() use ($framework) {
return new Response($framework->getRequest()->getRequestUri());
$application = new Application();
$application->get('/foo', function() use ($application) {
return new Response($application->getRequest()->getRequestUri());
});
$framework->error(function($e) use ($framework) {
return new Response($framework->getRequest()->getRequestUri());
$application->error(function($e) use ($application) {
return new Response($application->getRequest()->getRequestUri());
});
foreach(array('/foo', '/bar') as $path) {
$request = Request::create($path);
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertContains($path, $response->getContent());
}
}
protected function checkRouteResponse($framework, $path, $expectedContent, $method = 'get', $message = null)
protected function checkRouteResponse($application, $path, $expectedContent, $method = 'get', $message = null)
{
$request = Request::create($path, $method);
$response = $framework->handle($request);
$response = $application->handle($request);
$this->assertEquals($expectedContent, $response->getContent(), $message);
}
}
......@@ -11,7 +11,7 @@
namespace Silex\Tests;
use Silex\Framework;
use Silex\Application;
use Silex\WebTestCase;
/**
......@@ -23,7 +23,7 @@ class WebTestCaseTest extends WebTestCase
{
public function createApp()
{
$app = new Framework();
$app = new Application();
$app->match('/hello', function() {
return 'world';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment