Commit b42bc687 authored by Fabien Potencier's avatar Fabien Potencier

merged branch jeremyFreeAgent/register (PR #603)

This PR was merged into the master branch.

Commits
-------

11fda10c Updated Application register and mount methods to return Application

Discussion
----------

Updated Application register and mount methods to return Application

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-21T17:43:08Z

Thanky @igorw, I've fixed that.

---------------------------------------------------------------------------

by igorw at 2013-01-21T17:44:15Z

I'm not opposed to this, but if we add it for `register` we should also do it for `mount` imo.

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-21T17:44:18Z

You were faster than @stof on that one!

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-21T17:48:03Z

Yes, for `mount` too... Do I add it ?

---------------------------------------------------------------------------

by igorw at 2013-01-21T18:49:33Z

You can add it as a separate commit. If we decide that it is not needed for `mount`, you can rebase that commit out ;-)

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-21T23:17:50Z

I've pushed it in the PR #604.

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-22T10:15:19Z

Is that better this way?

---------------------------------------------------------------------------

by igorw at 2013-01-22T14:09:29Z

I would have two tests in the ApplicationTest: `testRegisterShouldReturnSelf`, `testMountShouldReturnSelf`.

---------------------------------------------------------------------------

by jeremyFreeAgent at 2013-01-22T14:17:21Z

Done!
parents 7c05e116 11fda10c
...@@ -150,6 +150,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -150,6 +150,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())
{ {
...@@ -160,6 +162,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -160,6 +162,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;
} }
/** /**
...@@ -424,6 +428,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -424,6 +428,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)
{ {
...@@ -436,6 +442,8 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -436,6 +442,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