Commit 11fda10c authored by Jérémy Romey's avatar Jérémy Romey

Updated Application register and mount methods to return Application

parent ca7e2dc4
...@@ -154,6 +154,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -154,6 +154,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
* *
* @param ServiceProviderInterface $provider A ServiceProviderInterface instance * @param ServiceProviderInterface $provider A ServiceProviderInterface instance
* @param array $values An array of values that customizes the provider * @param array $values An array of values that customizes the provider
*
* @return Application
*/ */
public function register(ServiceProviderInterface $provider, array $values = array()) public function register(ServiceProviderInterface $provider, array $values = array())
{ {
...@@ -164,6 +166,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -164,6 +166,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
$this[$key] = $value; $this[$key] = $value;
} }
return $this;
} }
/** /**
...@@ -428,6 +432,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -428,6 +432,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
* *
* @param string $prefix The route prefix * @param string $prefix The route prefix
* @param ControllerCollection|ControllerProviderInterface $controllers A ControllerCollection or a ControllerProviderInterface instance * @param ControllerCollection|ControllerProviderInterface $controllers A ControllerCollection or a ControllerProviderInterface instance
*
* @return Application
*/ */
public function mount($prefix, $controllers) public function mount($prefix, $controllers)
{ {
...@@ -440,6 +446,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -440,6 +446,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
} }
$this['routes']->addCollection($controllers->flush($prefix), $prefix); $this['routes']->addCollection($controllers->flush($prefix), $prefix);
return $this;
} }
/** /**
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
namespace Silex\Tests; namespace Silex\Tests;
use Silex\Application; use Silex\Application;
use Silex\ControllerCollection;
use Silex\Route;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
...@@ -468,6 +470,23 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase ...@@ -468,6 +470,23 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo /', $app->handle($mainRequest)->getContent()); $this->assertEquals('foo /', $app->handle($mainRequest)->getContent());
} }
public function testRegisterShouldReturnSelf()
{
$app = new Application();
$provider = $this->getMock('Silex\ServiceProviderInterface');
$this->assertSame($app, $app->register($provider));
}
public function testMountShouldReturnSelf()
{
$app = new Application();
$mounted = new ControllerCollection(new Route());
$mounted->get('/{name}', function ($name) { return new Response($name); });
$this->assertSame($app, $app->mount('/hello', $mounted));
}
} }
class FooController class FooController
......
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