aboutsummaryrefslogtreecommitdiffstats
path: root/tests/di/create_container_test.php
diff options
context:
space:
mode:
authorTristan Darricau <github@nicofuma.fr>2014-06-28 01:36:59 +0200
committerTristan Darricau <github@nicofuma.fr>2014-07-07 01:02:27 +0200
commit1d966fbc86db47c3518b35de849cad3a1f295e71 (patch)
tree06ba40dbd2a99046bee989b1b4ff987e37e37a0b /tests/di/create_container_test.php
parentc87f44c6692c55adb3ce5bc5b7bca8da7b1357ab (diff)
downloadforums-1d966fbc86db47c3518b35de849cad3a1f295e71.tar
forums-1d966fbc86db47c3518b35de849cad3a1f295e71.tar.gz
forums-1d966fbc86db47c3518b35de849cad3a1f295e71.tar.bz2
forums-1d966fbc86db47c3518b35de849cad3a1f295e71.tar.xz
forums-1d966fbc86db47c3518b35de849cad3a1f295e71.zip
[ticket/12775] Add tests for the container factory
PHPBB3-12775
Diffstat (limited to 'tests/di/create_container_test.php')
-rw-r--r--tests/di/create_container_test.php148
1 files changed, 120 insertions, 28 deletions
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php
index 5983b244fd..d41f1af5ae 100644
--- a/tests/di/create_container_test.php
+++ b/tests/di/create_container_test.php
@@ -14,50 +14,135 @@
namespace
{
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
- class phpbb_di_container_test extends phpbb_test_case
+ class phpbb_di_container_test extends \phpbb_test_case
{
- public function test_phpbb_create_container()
+ protected $config_php;
+
+ /**
+ * @var \phpbb\di\container_factory
+ */
+ protected $factory;
+ protected $phpbb_root_path;
+ protected $filename;
+
+ public function setUp()
{
- $this->markTestSkipped();
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
+ $this->phpbb_root_path = dirname(__FILE__) . '/';
+ $this->config_php = new \phpbb\config_php($this->phpbb_root_path . 'fixtures/', 'php');
+ $this->factory = new phpbb_mock_container_factory($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php');
+
+ $this->filename = $this->phpbb_root_path . '../tmp/cache/container.php';
+ if (is_file($this->filename))
+ {
+ unlink($this->filename);
+ }
+
+ parent::setUp();
+ }
+ public function test_default_container()
+ {
+ $container = $this->factory->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks the core services
+ $this->assertTrue($container->hasParameter('core'));
+
+ // Checks compile_container
+ $this->assertTrue($container->isFrozen());
+
+ // Checks inject_config
+ $this->assertTrue($container->hasParameter('dbal.dbhost'));
+
+ // Checks use_extensions
+ $this->assertTrue($container->hasParameter('enabled'));
+ $this->assertFalse($container->hasParameter('disabled'));
+ $this->assertFalse($container->hasParameter('available'));
+
+ // Checks set_custom_parameters
+ $this->assertTrue($container->hasParameter('core.root_path'));
+
+ // Checks dump_container
+ $this->assertTrue(is_file($this->filename));
+
+ // Checks the construction of a dumped container
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('phpbb_cache_container', $container);
+ $this->assertFalse($container->isFrozen());
+ $container->getParameterBag(); // needed, otherwise the container is not marked as frozen
+ $this->assertTrue($container->isFrozen());
}
- public function test_phpbb_create_install_container()
+ public function test_dump_container()
{
- $this->markTestSkipped();
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_install_container($phpbb_root_path, 'php');
+ $this->factory->set_dump_container(false);
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ // Checks dump_container
+ $this->assertFalse(is_file($this->filename));
+
+ // Checks the construction of a dumped container
+ $container = $this->factory->get_container();
+ $this->assertNotInstanceOf('phpbb_cache_container', $container);
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
$this->assertTrue($container->isFrozen());
}
- public function test_phpbb_create_compiled_container()
+ public function test_use_extensions()
{
- $this->markTestSkipped();
- $phpbb_root_path = __DIR__ . '/../../phpBB/';
- $config_file = __DIR__ . '/fixtures/config.php';
- $extensions = array(
- new \phpbb\di\extension\config(__DIR__ . '/fixtures/config.php'),
- new \phpbb\di\extension\core($phpbb_root_path . 'config'),
- );
- $container = phpbb_create_compiled_container($config_file, $extensions, array(), $phpbb_root_path, 'php');
+ $this->factory->set_use_extensions(false);
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks the core services
+ $this->assertTrue($container->hasParameter('core'));
+
+ // Checks use_extensions
+ $this->assertFalse($container->hasParameter('enabled'));
+ $this->assertFalse($container->hasParameter('disabled'));
+ $this->assertFalse($container->hasParameter('available'));
+ }
+ public function test_compile_container()
+ {
+ $this->factory->set_compile_container(false);
+ $container = $this->factory->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
- $this->assertTrue($container->isFrozen());
+
+ // Checks compile_container
+ $this->assertFalse($container->isFrozen());
+ }
+
+ public function test_inject_config()
+ {
+ $this->factory->set_inject_config(false);
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ // Checks inject_config
+ $this->assertFalse($container->hasParameter('dbal.dbhost'));
+ }
+
+ public function test_set_config_path()
+ {
+ $this->factory->set_config_path($this->phpbb_root_path . 'fixtures/other_config/');
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ $this->assertTrue($container->hasParameter('other_config'));
+ $this->assertFalse($container->hasParameter('core'));
+ }
+
+ public function test_set_custom_parameters()
+ {
+ $this->factory->set_custom_parameters(array('my_parameter' => true));
+ $container = $this->factory->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ $this->assertTrue($container->hasParameter('my_parameter'));
+ $this->assertFalse($container->hasParameter('core.root_path'));
}
}
}
@@ -105,5 +190,12 @@ namespace phpbb\db\driver
function sql_like_expression($expression)
{
}
+
+ function sql_fetchrowset($query_id = false)
+ {
+ return array(
+ array('ext_name' => 'vendor/enabled'),
+ );
+ }
}
}