Fix tests broken due to changes in container

This commit is contained in:
Timothy Warren 2016-08-29 15:36:36 -04:00
parent 88e06a0052
commit 4e4ac58263
10 changed files with 51 additions and 42 deletions

View File

@ -63,23 +63,38 @@ class BaseCommand extends Command {
$container = new Container(); $container = new Container();
// Create Config Object // Create Config Object
$config = new Config($config_array); $container->set('config', function() {
$container->set('config', $config); return new Config();
});
$container->setInstance('config', $config_array);
// Create Cache Object // Create Cache Object
$container->set('cache', new CacheManager($config)); $container->set('cache', function($container) {
return new CacheManager($container->get('config'));
});
// Create session Object // Create session Object
$session = (new SessionFactory())->newInstance($_COOKIE); $container->set('session', function() {
$container->set('session', $session); return (new SessionFactory())->newInstance($_COOKIE);
});
// Models // Models
$container->set('api-model', new Model\API($container)); $container->set('api-model', function($container) {
$container->set('anime-model', new Model\Anime($container)); return new Model\API($container);
$container->set('manga-model', new Model\Manga($container)); });
$container->set('anime-model', function($container) {
return new Model\Anime($container);
});
$container->set('manga-model', function($container) {
return new Model\Manga($container);
});
$container->set('auth', new HummingbirdAuth($container)); $container->set('auth', function($container) {
$container->set('util', new Util($container)); return new HummingbirdAuth($container);
});
$container->set('util', function($container) {
return new Util($container);
});
return $container; return $container;
}; };

View File

@ -24,7 +24,7 @@ class HummingbirdAuthTest extends AnimeClient_TestCase {
$auth = new HummingbirdAuth($this->container); $auth = new HummingbirdAuth($this->container);
$friend = new Friend($auth); $friend = new Friend($auth);
$this->auth = $friend; $this->auth = $friend;
$this->container->set('session', self::$session); $this->container->setInstance('session', self::$session);
} }
public function dataAuthenticate() public function dataAuthenticate()

View File

@ -33,7 +33,7 @@ class ControllerTest extends AnimeClient_TestCase {
'database' => '', 'database' => '',
'file' => ":memory:" 'file' => ":memory:"
]); ]);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
$this->assertInstanceOf( $this->assertInstanceOf(
'Aviat\AnimeClient\Controller', 'Aviat\AnimeClient\Controller',

View File

@ -29,39 +29,25 @@ class DispatcherTest extends AnimeClient_TestCase {
'SERVER_NAME' => $host 'SERVER_NAME' => $host
]); ]);
$request = ServerRequestFactory::fromGlobals( $this->setSuperGlobals([
$_SERVER, '_SERVER' => $_SERVER
$_GET, ]);
$_POST,
$_COOKIE,
$_FILES
);
$old_config = $this->container->get('config');
$logger = new Logger('test_logger'); $logger = new Logger('test_logger');
$logger->pushHandler(new TestHandler(Logger::DEBUG)); $logger->pushHandler(new TestHandler(Logger::DEBUG));
// Add the appropriate objects to the container
$this->container = new Container([
'config' => $old_config,
'request' => $request,
'response' => new Response,
'aura-router' => new RouterContainer
]);
$this->container->setLogger($logger, 'default'); $this->container->setLogger($logger, 'default');
if ( ! empty($config)) if ( ! empty($config))
{ {
$config = new Config($config); $config = new Config($config);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
} }
$this->router = new Dispatcher($this->container); $this->router = new Dispatcher($this->container);
$this->config = $this->container->get('config'); $this->config = $this->container->get('config');
$this->urlGenerator = new UrlGenerator($this->container); $this->urlGenerator = new UrlGenerator($this->container);
$this->container->set('url-generator', $this->urlGenerator); $this->container->setInstance('url-generator', $this->urlGenerator);
} }
public function testRouterSanity() public function testRouterSanity()

View File

@ -43,7 +43,7 @@ class MenuHelperTest extends AnimeClient_TestCase {
// Set config for tests // Set config for tests
$config = $this->container->get('config'); $config = $this->container->get('config');
$config->set('menus', $menus); $config->set('menus', $menus);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
foreach($menus as $case => $config) foreach($menus as $case => $config)
{ {

View File

@ -66,7 +66,7 @@ class MenuGeneratorTest extends AnimeClient_TestCase {
]; ];
$config = $this->container->get('config'); $config = $this->container->get('config');
$config->set('menus', $menus); $config->set('menus', $menus);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
$expected = ''; $expected = '';
$this->assertEquals($expected, $this->generator->generate('manga_list')); $this->assertEquals($expected, $this->generator->generate('manga_list'));

View File

@ -10,7 +10,7 @@ class AnimeCollectionModelTest extends AnimeClient_TestCase {
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->container->set('config', new Config([ $this->container->setInstance('config', new Config([
'database' => [ 'database' => [
'collection' => [ 'collection' => [
'type' => 'sqlite', 'type' => 'sqlite',
@ -37,7 +37,7 @@ class AnimeCollectionModelTest extends AnimeClient_TestCase {
public function testInvalidDatabase() public function testInvalidDatabase()
{ {
$this->container->set('config', new Config([ $this->container->setInstance('config', new Config([
'database' => [ 'database' => [
'collection' => [ 'collection' => [
'type' => 'sqlite', 'type' => 'sqlite',
@ -57,7 +57,7 @@ class AnimeCollectionModelTest extends AnimeClient_TestCase {
public function testNonExistentDatabase() public function testNonExistentDatabase()
{ {
$this->container->set('config', new Config([ $this->container->setInstance('config', new Config([
'database' => [ 'database' => [
'collection' => [ 'collection' => [
'type' => 'sqlite', 'type' => 'sqlite',

View File

@ -12,7 +12,7 @@ class MangaModelTest extends AnimeClient_TestCase {
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
$this->container->set('util', new MockUtil($this->container)); $this->container->setInstance('util', new MockUtil($this->container));
$this->model = new Friend(new TestMangaModel($this->container)); $this->model = new Friend(new TestMangaModel($this->container));
$this->mockDir = __DIR__ . '/../../test_data/manga_list'; $this->mockDir = __DIR__ . '/../../test_data/manga_list';
} }

View File

@ -83,7 +83,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
public function testFullUrl($config, $path, $type, $expected) public function testFullUrl($config, $path, $type, $expected)
{ {
$config = new Config($config); $config = new Config($config);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
$urlGenerator = new UrlGenerator($this->container); $urlGenerator = new UrlGenerator($this->container);
$result = $urlGenerator->full_url($path, $type); $result = $urlGenerator->full_url($path, $type);
@ -127,7 +127,7 @@ class UrlGeneratorTest extends AnimeClient_TestCase {
public function testBaseUrl($config, $type, $expected) public function testBaseUrl($config, $type, $expected)
{ {
$config = new Config($config); $config = new Config($config);
$this->container->set('config', $config); $this->container->setInstance('config', $config);
$urlGenerator = new UrlGenerator($this->container); $urlGenerator = new UrlGenerator($this->container);
$result = $urlGenerator->base_url($type); $result = $urlGenerator->base_url($type);

View File

@ -91,7 +91,13 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
// Set up DI container // Set up DI container
$di = require _dir($APP_DIR, 'bootstrap.php'); $di = require _dir($APP_DIR, 'bootstrap.php');
$container = $di($config_array); $container = $di($config_array);
$container->set('session-handler', self::$session_handler);
// Use mock session handler
$container->set('session-handler', function() {
$session_handler = new TestSessionHandler();
session_set_save_handler($session_handler, TRUE);
return $session_handler;
});
$this->container = $container; $this->container = $container;
} }
@ -116,8 +122,10 @@ class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {
['Zend\Diactoros\ServerRequestFactory', 'fromGlobals'], ['Zend\Diactoros\ServerRequestFactory', 'fromGlobals'],
array_merge($default, $supers) array_merge($default, $supers)
); );
$this->container->set('request', $request); $this->container->setInstance('request', $request);
$this->container->set('response', new HttpResponse()); $this->container->set('repsone', function() {
return new HttpResponse();
});
} }
/** /**