aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2014-07-11 11:49:51 +0200
committerAndreas Fischer <bantu@phpbb.com>2014-07-11 11:49:51 +0200
commitb2a883d504d9ece8525fcc1a4aa8e44a000db6ca (patch)
tree81a85d5242913fa7e667b5adc873bd4a500ed406 /tests
parent147b942e5c885f13181f0cb4d67cb4ccee4652df (diff)
parent58a52fe5b90215d090ba3b992f96d401d805440c (diff)
downloadforums-b2a883d504d9ece8525fcc1a4aa8e44a000db6ca.tar
forums-b2a883d504d9ece8525fcc1a4aa8e44a000db6ca.tar.gz
forums-b2a883d504d9ece8525fcc1a4aa8e44a000db6ca.tar.bz2
forums-b2a883d504d9ece8525fcc1a4aa8e44a000db6ca.tar.xz
forums-b2a883d504d9ece8525fcc1a4aa8e44a000db6ca.zip
Merge pull request #2671 from Nicofuma/ticket/12775
[ticket/12775] Replace functions_container with a container_builder class. * Nicofuma/ticket/12775: (34 commits) [ticket/12775] Set dbal.conn.driver as synthetic during installation [ticket/12775] Add the definition of dbal.conn in fixtures/config/services.yml [ticket/12775] Inject the connection when created in the container [ticket/12775] Extract the vars later in install/install_update.php [ticket/12775] Rename config_php_handler to config_php_file container_builder [ticket/12775] Set defined_vars as a property of config_php_file [ticket/12775] Fix doc blocks in the container builder [ticket/12775] Remove useless includes of config.php [ticket/12775] Move phpbb_convert_30_dbms_to_31 into the config file class [ticket/12775] Fix comments [ticket/12775] Update doc blocks [ticket/12775] Fix container_builder [ticket/12775] Rename config_php to config_php_file [ticket/12775] Renamed to \phpbb\di\container_builder [ticket/12775] Remove the last include of functions_container [ticket/12775] Fix unit tests [ticket/12775] Add tests for \phpbb\config_php [ticket/12775] Add tests for the container factory [ticket/12775] Use a field instead of a local var in load_config_var() [ticket/12775] Update container and config in install/ ...
Diffstat (limited to 'tests')
-rw-r--r--tests/config_php_file_test.php30
-rw-r--r--tests/di/create_container_test.php145
-rw-r--r--tests/di/fixtures/config/services.yml14
-rw-r--r--tests/di/fixtures/ext/vendor/available/config/services.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/disabled/config/services.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/enabled/config/services.yml2
-rw-r--r--tests/di/fixtures/other_config/services.yml14
-rw-r--r--tests/fixtures/config.php3
-rw-r--r--tests/fixtures/config_other.php3
-rw-r--r--tests/functions/convert_30_dbms_to_31_test.php3
-rw-r--r--tests/mock/phpbb_di_container_builder.php20
-rw-r--r--tests/test_framework/phpbb_test_case_helpers.php20
12 files changed, 219 insertions, 39 deletions
diff --git a/tests/config_php_file_test.php b/tests/config_php_file_test.php
new file mode 100644
index 0000000000..c2e4eb21c7
--- /dev/null
+++ b/tests/config_php_file_test.php
@@ -0,0 +1,30 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_config_php_file_test extends phpbb_test_case
+{
+ public function test_default()
+ {
+ $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php');
+ $this->assertSame('bar', $config_php->get('foo'));
+ $this->assertSame(array('foo' => 'bar', 'foo_foo' => 'bar bar'), $config_php->get_all());
+ }
+
+ public function test_set_config_file()
+ {
+ $config_php = new \phpbb\config_php_file(dirname( __FILE__ ) . '/fixtures/', 'php');
+ $config_php->set_config_file(dirname( __FILE__ ) . '/fixtures/config_other.php');
+ $this->assertSame('foo', $config_php->get('bar'));
+ $this->assertSame(array('bar' => 'foo', 'bar_bar' => 'foo foo'), $config_php->get_all());
+ }
+}
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php
index 8bf9f636fa..559c0b122c 100644
--- a/tests/di/create_container_test.php
+++ b/tests/di/create_container_test.php
@@ -14,47 +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_builder
+ */
+ protected $builder;
+ protected $phpbb_root_path;
+ protected $filename;
+
+ public function setUp()
{
- $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_file($this->phpbb_root_path . 'fixtures/', 'php');
+ $this->builder = new phpbb_mock_phpbb_di_container_builder($this->config_php, $this->phpbb_root_path . 'fixtures/', 'php');
+
+ $this->filename = $this->phpbb_root_path . '../tmp/container.php';
+ if (is_file($this->filename))
+ {
+ unlink($this->filename);
+ }
+
+ parent::setUp();
+ }
+ public function test_default_container()
+ {
+ $container = $this->builder->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->builder->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()
{
- $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->builder->set_dump_container(false);
+ $container = $this->builder->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->builder->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()
{
- $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->builder->set_use_extensions(false);
+ $container = $this->builder->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->builder->set_compile_container(false);
+ $container = $this->builder->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->builder->set_inject_config(false);
+ $container = $this->builder->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->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/');
+ $container = $this->builder->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->builder->set_custom_parameters(array('my_parameter' => true));
+ $container = $this->builder->get_container();
+ $this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+
+ $this->assertTrue($container->hasParameter('my_parameter'));
+ $this->assertFalse($container->hasParameter('core.root_path'));
}
}
}
@@ -102,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'),
+ );
+ }
}
}
diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/services.yml
new file mode 100644
index 0000000000..f2a22ae109
--- /dev/null
+++ b/tests/di/fixtures/config/services.yml
@@ -0,0 +1,14 @@
+parameters:
+ core: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
diff --git a/tests/di/fixtures/ext/vendor/available/config/services.yml b/tests/di/fixtures/ext/vendor/available/config/services.yml
new file mode 100644
index 0000000000..2ced431f5a
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/available/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ available: true
diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/services.yml
new file mode 100644
index 0000000000..31ada384bf
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/disabled/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ disabled: true
diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/services.yml
new file mode 100644
index 0000000000..88a7919ed1
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ enabled: true
diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/services.yml
new file mode 100644
index 0000000000..c299bfc648
--- /dev/null
+++ b/tests/di/fixtures/other_config/services.yml
@@ -0,0 +1,14 @@
+parameters:
+ other_config: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - @service_container
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
diff --git a/tests/fixtures/config.php b/tests/fixtures/config.php
new file mode 100644
index 0000000000..ae9e8c22de
--- /dev/null
+++ b/tests/fixtures/config.php
@@ -0,0 +1,3 @@
+<?php
+$foo = 'bar';
+$foo_foo = 'bar bar';
diff --git a/tests/fixtures/config_other.php b/tests/fixtures/config_other.php
new file mode 100644
index 0000000000..e0ecc17bb9
--- /dev/null
+++ b/tests/fixtures/config_other.php
@@ -0,0 +1,3 @@
+<?php
+$bar = 'foo';
+$bar_bar = 'foo foo';
diff --git a/tests/functions/convert_30_dbms_to_31_test.php b/tests/functions/convert_30_dbms_to_31_test.php
index a3992aef5c..729c0a82f0 100644
--- a/tests/functions/convert_30_dbms_to_31_test.php
+++ b/tests/functions/convert_30_dbms_to_31_test.php
@@ -36,7 +36,8 @@ class phpbb_convert_30_dbms_to_31_test extends phpbb_test_case
{
$expected = "phpbb\\db\\driver\\$input";
- $output = phpbb_convert_30_dbms_to_31($input);
+ $config_php_file = new \phpbb\config_php_file('', '');
+ $output = $config_php_file->convert_30_dbms_to_31($input);
$this->assertEquals($expected, $output);
}
diff --git a/tests/mock/phpbb_di_container_builder.php b/tests/mock/phpbb_di_container_builder.php
new file mode 100644
index 0000000000..59cdf0bb2b
--- /dev/null
+++ b/tests/mock/phpbb_di_container_builder.php
@@ -0,0 +1,20 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_mock_phpbb_di_container_builder extends \phpbb\di\container_builder
+{
+ protected function get_container_filename()
+ {
+ return $this->phpbb_root_path . '../../tmp/container.' . $this->php_ext;
+ }
+}
diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php
index a29b6e1955..ade1bf6e23 100644
--- a/tests/test_framework/phpbb_test_case_helpers.php
+++ b/tests/test_framework/phpbb_test_case_helpers.php
@@ -142,17 +142,16 @@ class phpbb_test_case_helpers
$test_config = dirname(__FILE__) . '/../test_config.php';
}
+ $config_php_file = new \phpbb\config_php_file('', '');
+
if (file_exists($test_config))
{
- include($test_config);
-
- if (!function_exists('phpbb_convert_30_dbms_to_31'))
- {
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- }
+ $config_php_file->set_config_file($test_config);
+ extract($config_php_file->get_all());
+ unset($dbpasswd);
$config = array_merge($config, array(
- 'dbms' => phpbb_convert_30_dbms_to_31($dbms),
+ 'dbms' => $config_php_file->convert_30_dbms_to_31($dbms),
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
@@ -183,13 +182,8 @@ class phpbb_test_case_helpers
if (isset($_SERVER['PHPBB_TEST_DBMS']))
{
- if (!function_exists('phpbb_convert_30_dbms_to_31'))
- {
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
- }
-
$config = array_merge($config, array(
- 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? phpbb_convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
+ 'dbms' => isset($_SERVER['PHPBB_TEST_DBMS']) ? $config_php_file->convert_30_dbms_to_31($_SERVER['PHPBB_TEST_DBMS']) : '',
'dbhost' => isset($_SERVER['PHPBB_TEST_DBHOST']) ? $_SERVER['PHPBB_TEST_DBHOST'] : '',
'dbport' => isset($_SERVER['PHPBB_TEST_DBPORT']) ? $_SERVER['PHPBB_TEST_DBPORT'] : '',
'dbname' => isset($_SERVER['PHPBB_TEST_DBNAME']) ? $_SERVER['PHPBB_TEST_DBNAME'] : '',