Skip to content

Commit

Permalink
Test default container factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianluca Arbezzano committed Oct 2, 2015
1 parent b1b5eed commit 7455612
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class App
*/
public function __construct(ContainerInterface $container = null)
{
$this->container = $container ?: Container\PHPDiFactory::buildContainer(Loader::load());
if ($container === null) {
$container = Container\PHPDiFactory::buildContainer(Loader::load());
}
$this->container = $container;

if ($container->has('router') == false) {
throw new Exception('Define router config');
Expand Down
4 changes: 2 additions & 2 deletions src/Container/PHPDiFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public static function buildContainer($config = [])
$builder->useAnnotations(true);
$builder->addDefinitions(
[
"event_manager" => DI\object('Zend\EventManager\EventManager'),
"dispatcher" => DI\object('GianArb\Penny\Dispatcher')
'event_manager' => DI\object('Zend\EventManager\EventManager'),
'dispatcher' => DI\object('GianArb\Penny\Dispatcher')
->constructor(DI\get('router')),
]
);
Expand Down
16 changes: 15 additions & 1 deletion tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,21 @@ public function testDispatcherShouldBeCallable()
});
$config['dispatcher'] = new \StdClass();

$app = new App(App::buildContainer($config));
$app = new App(Container\PHPDiFactory::buildContainer($config));
$app->run($request, $response);
}

public function testWithInternalContainerFactory()
{
chdir(dirname(__DIR__.'/../'));
$app = new App();

$request = (new Request())
->withUri(new Uri('/'))
->withMethod('GET');
$response = new Response();

$response = $app->run($request, $response);
$this->assertEquals(200, $response->getStatusCode());
}
}
7 changes: 7 additions & 0 deletions tests/config/app.test.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'router' => \FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) {
$r->addRoute('GET', '/', ['TestApp\Controller\Index', 'index']);
})
];

0 comments on commit 7455612

Please sign in to comment.