aboutsummaryrefslogtreecommitdiffstats
path: root/tests/di
diff options
context:
space:
mode:
Diffstat (limited to 'tests/di')
-rw-r--r--tests/di/create_container_test.php95
-rw-r--r--tests/di/fixtures/config.php4
-rw-r--r--tests/di/fixtures/config/production/config.yml2
-rw-r--r--tests/di/fixtures/config/production/container/environment.yml32
-rw-r--r--tests/di/fixtures/config/test/config.yml2
-rw-r--r--tests/di/fixtures/config/test/container/environment.yml (renamed from tests/di/fixtures/config/services.yml)14
-rw-r--r--tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml (renamed from tests/di/fixtures/ext/vendor/disabled/config/services.yml)0
-rw-r--r--tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/enabled-3/config/services.yml2
-rw-r--r--tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml (renamed from tests/di/fixtures/ext/vendor/enabled/config/services.yml)0
-rw-r--r--tests/di/fixtures/ext/vendor/enabled_4/di/extension.php32
-rw-r--r--tests/di/fixtures/ext/vendor/enabled_4/environment.yml2
-rw-r--r--tests/di/fixtures/other_config/production/config.yml2
-rw-r--r--tests/di/fixtures/other_config/production/container/environment.yml32
-rw-r--r--tests/di/fixtures/other_config/test/config.yml2
-rw-r--r--tests/di/fixtures/other_config/test/container/environment.yml (renamed from tests/di/fixtures/other_config/services.yml)14
-rw-r--r--tests/di/ordered_service_collection_test.php51
-rw-r--r--tests/di/service_collection_test.php47
18 files changed, 261 insertions, 74 deletions
diff --git a/tests/di/create_container_test.php b/tests/di/create_container_test.php
index 1a7eb4698c..1fd2cbd7ee 100644
--- a/tests/di/create_container_test.php
+++ b/tests/di/create_container_test.php
@@ -13,7 +13,7 @@
namespace
{
- require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
+ require_once dirname(__FILE__) . '/fixtures/ext/vendor/enabled_4/di/extension.php';
class phpbb_di_container_test extends \phpbb_test_case
{
@@ -30,7 +30,8 @@ namespace
{
$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->builder = new phpbb_mock_phpbb_di_container_builder($this->phpbb_root_path . 'fixtures/', 'php');
+ $this->builder->with_config($this->config_php);
$this->filename = $this->phpbb_root_path . '../tmp/container.php';
if (is_file($this->filename))
@@ -45,6 +46,7 @@ namespace
{
$container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
+ $this->assertFalse($container->hasParameter('container_exception'));
// Checks the core services
$this->assertTrue($container->hasParameter('core'));
@@ -57,6 +59,9 @@ namespace
// Checks use_extensions
$this->assertTrue($container->hasParameter('enabled'));
+ $this->assertTrue($container->hasParameter('enabled_2'));
+ $this->assertTrue($container->hasParameter('enabled_3'));
+ $this->assertTrue($container->hasParameter('enabled_4'));
$this->assertFalse($container->hasParameter('disabled'));
$this->assertFalse($container->hasParameter('available'));
@@ -69,14 +74,12 @@ namespace
// 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_dump_container()
+ public function test_without_cache()
{
- $this->builder->set_dump_container(false);
+ $this->builder->without_cache();
$container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
@@ -90,9 +93,9 @@ namespace
$this->assertTrue($container->isFrozen());
}
- public function test_use_extensions()
+ public function test_without_extensions()
{
- $this->builder->set_use_extensions(false);
+ $this->builder->without_extensions();
$container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
@@ -105,9 +108,9 @@ namespace
$this->assertFalse($container->hasParameter('available'));
}
- public function test_compile_container()
+ public function test_without_compiled_container()
{
- $this->builder->set_compile_container(false);
+ $this->builder->without_compiled_container();
$container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
@@ -115,19 +118,9 @@ namespace
$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()
+ public function test_with_config_path()
{
- $this->builder->set_config_path($this->phpbb_root_path . 'fixtures/other_config/');
+ $this->builder->with_config_path($this->phpbb_root_path . 'fixtures/other_config/');
$container = $this->builder->get_container();
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
@@ -135,70 +128,32 @@ namespace
$this->assertFalse($container->hasParameter('core'));
}
- public function test_set_custom_parameters()
+ public function test_with_custom_parameters()
{
- $this->builder->set_custom_parameters(array('my_parameter' => true));
+ $this->builder->with_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'));
}
}
}
-namespace phpbb\db\driver
+namespace phpbb\extension
{
- class container_mock extends \phpbb\db\driver\driver
+ class manager_mock extends \phpbb\extension\manager
{
- public function sql_connect($sqlserver, $sqluser, $sqlpassword, $database, $port = false, $persistency = false, $new_link = false)
- {
- }
-
- public function sql_query($query = '', $cache_ttl = 0)
- {
- }
-
- public function sql_fetchrow($query_id = false)
- {
- }
-
- public function sql_freeresult($query_id = false)
- {
- }
-
- function sql_server_info($raw = false, $use_cache = true)
- {
- }
-
- function sql_affectedrows()
- {
- }
-
- function sql_rowseek($rownum, &$query_id)
- {
- }
-
- function sql_nextid()
- {
- }
-
- function sql_escape($msg)
- {
- }
-
- function sql_like_expression($expression)
- {
- }
-
- function sql_not_like_expression($expression)
+ public function __construct()
{
}
- function sql_fetchrowset($query_id = false)
+ public function all_enabled($phpbb_relative = true)
{
return array(
- array('ext_name' => 'vendor/enabled'),
+ 'vendor/enabled' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled/',
+ 'vendor/enabled-2' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled-2/',
+ 'vendor/enabled-3' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled-3/',
+ 'vendor/enabled_4' => dirname(__FILE__) . '/fixtures/ext/vendor/enabled_4/',
);
}
}
diff --git a/tests/di/fixtures/config.php b/tests/di/fixtures/config.php
index 04e20f63d8..1e9207d924 100644
--- a/tests/di/fixtures/config.php
+++ b/tests/di/fixtures/config.php
@@ -1,11 +1,11 @@
<?php
// phpBB 3.1.x auto-generated configuration file
// Do not change anything in this file!
-$dbms = 'container_mock';
+$dbms = 'mysql';
$dbhost = '127.0.0.1';
$dbport = '';
$dbname = 'phpbb';
$dbuser = 'root';
$dbpasswd = '';
$table_prefix = 'phpbb_';
-$acm_type = '\phpbb\cache\driver\null';
+$acm_type = '\phpbb\cache\driver\dummy';
diff --git a/tests/di/fixtures/config/production/config.yml b/tests/di/fixtures/config/production/config.yml
new file mode 100644
index 0000000000..fcfa84f68b
--- /dev/null
+++ b/tests/di/fixtures/config/production/config.yml
@@ -0,0 +1,2 @@
+core:
+ require_dev_dependencies: true
diff --git a/tests/di/fixtures/config/production/container/environment.yml b/tests/di/fixtures/config/production/container/environment.yml
new file mode 100644
index 0000000000..8281d9e941
--- /dev/null
+++ b/tests/di/fixtures/config/production/container/environment.yml
@@ -0,0 +1,32 @@
+parameters:
+ core: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - '@service_container'
+
+ dbal.conn.driver:
+ synthetic: true
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
+
+ ext.manager:
+ class: phpbb\extension\manager_mock
+
+ template.twig.environment:
+ class: Exception
+ arguments:
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - []
diff --git a/tests/di/fixtures/config/test/config.yml b/tests/di/fixtures/config/test/config.yml
new file mode 100644
index 0000000000..fcfa84f68b
--- /dev/null
+++ b/tests/di/fixtures/config/test/config.yml
@@ -0,0 +1,2 @@
+core:
+ require_dev_dependencies: true
diff --git a/tests/di/fixtures/config/services.yml b/tests/di/fixtures/config/test/container/environment.yml
index 913a2603c9..252117dd32 100644
--- a/tests/di/fixtures/config/services.yml
+++ b/tests/di/fixtures/config/test/container/environment.yml
@@ -8,10 +8,22 @@ services:
dbal.conn:
class: phpbb\db\driver\factory
arguments:
- - @service_container
+ - '@service_container'
dbal.conn.driver:
synthetic: true
dispatcher:
class: phpbb\db\driver\container_mock
+
+ template.twig.environment:
+ class: Exception
+ arguments:
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - []
diff --git a/tests/di/fixtures/ext/vendor/disabled/config/services.yml b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml
index 31ada384bf..31ada384bf 100644
--- a/tests/di/fixtures/ext/vendor/disabled/config/services.yml
+++ b/tests/di/fixtures/ext/vendor/disabled/config/test/container/environment.yml
diff --git a/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml
new file mode 100644
index 0000000000..feeb5a7a2d
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled-2/config/test/container/environment.yml
@@ -0,0 +1,2 @@
+parameters:
+ enabled_2: true
diff --git a/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml
new file mode 100644
index 0000000000..0dae35d2bd
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled-3/config/services.yml
@@ -0,0 +1,2 @@
+parameters:
+ enabled_3: true
diff --git a/tests/di/fixtures/ext/vendor/enabled/config/services.yml b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml
index 88a7919ed1..88a7919ed1 100644
--- a/tests/di/fixtures/ext/vendor/enabled/config/services.yml
+++ b/tests/di/fixtures/ext/vendor/enabled/config/default/container/environment.yml
diff --git a/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php
new file mode 100644
index 0000000000..8e5ed6c52c
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled_4/di/extension.php
@@ -0,0 +1,32 @@
+<?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.
+*
+*/
+
+namespace vendor\enabled_4\di;
+
+use phpbb\extension\di\extension_base;
+use Symfony\Component\Config\FileLocator;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
+
+/**
+* Container core extension
+*/
+class extension extends extension_base
+{
+ protected function load_services(ContainerBuilder $container)
+ {
+ $filesystem = new \phpbb\filesystem\filesystem();
+ $loader = new YamlFileLoader($container, new FileLocator($filesystem->realpath($this->ext_path)));
+ $loader->load('environment.yml');
+ }
+}
diff --git a/tests/di/fixtures/ext/vendor/enabled_4/environment.yml b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml
new file mode 100644
index 0000000000..d0affe4fd6
--- /dev/null
+++ b/tests/di/fixtures/ext/vendor/enabled_4/environment.yml
@@ -0,0 +1,2 @@
+parameters:
+ enabled_4: true
diff --git a/tests/di/fixtures/other_config/production/config.yml b/tests/di/fixtures/other_config/production/config.yml
new file mode 100644
index 0000000000..fcfa84f68b
--- /dev/null
+++ b/tests/di/fixtures/other_config/production/config.yml
@@ -0,0 +1,2 @@
+core:
+ require_dev_dependencies: true
diff --git a/tests/di/fixtures/other_config/production/container/environment.yml b/tests/di/fixtures/other_config/production/container/environment.yml
new file mode 100644
index 0000000000..c0d2f87bab
--- /dev/null
+++ b/tests/di/fixtures/other_config/production/container/environment.yml
@@ -0,0 +1,32 @@
+parameters:
+ other_config: true
+
+services:
+ config.php:
+ synthetic: true
+
+ dbal.conn:
+ class: phpbb\db\driver\factory
+ arguments:
+ - '@service_container'
+
+ dbal.conn.driver:
+ synthetic: true
+
+ dispatcher:
+ class: phpbb\db\driver\container_mock
+
+ ext.manager:
+ class: phpbb\extension\manager_mock
+
+ template.twig.environment:
+ class: Exception
+ arguments:
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - []
diff --git a/tests/di/fixtures/other_config/test/config.yml b/tests/di/fixtures/other_config/test/config.yml
new file mode 100644
index 0000000000..fcfa84f68b
--- /dev/null
+++ b/tests/di/fixtures/other_config/test/config.yml
@@ -0,0 +1,2 @@
+core:
+ require_dev_dependencies: true
diff --git a/tests/di/fixtures/other_config/services.yml b/tests/di/fixtures/other_config/test/container/environment.yml
index d6246d3bc0..b9f6d05018 100644
--- a/tests/di/fixtures/other_config/services.yml
+++ b/tests/di/fixtures/other_config/test/container/environment.yml
@@ -8,10 +8,22 @@ services:
dbal.conn:
class: phpbb\db\driver\factory
arguments:
- - @service_container
+ - '@service_container'
dbal.conn.driver:
synthetic: true
dispatcher:
class: phpbb\db\driver\container_mock
+
+ template.twig.environment:
+ class: Exception
+ arguments:
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - ~
+ - []
diff --git a/tests/di/ordered_service_collection_test.php b/tests/di/ordered_service_collection_test.php
new file mode 100644
index 0000000000..47e6d23744
--- /dev/null
+++ b/tests/di/ordered_service_collection_test.php
@@ -0,0 +1,51 @@
+<?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_ordered_service_collection_test extends \phpbb_test_case
+{
+ /**
+ * @var \phpbb\di\ordered_service_collection
+ */
+ protected $service_collection;
+
+ public function setUp()
+ {
+ $container = new phpbb_mock_container_builder();
+ $container->set('foo', new StdClass);
+ $container->set('bar', new StdClass);
+ $container->set('foobar', new StdClass);
+ $container->set('barfoo', new StdClass);
+
+ $this->service_collection = new \phpbb\di\ordered_service_collection($container);
+ $this->service_collection->add('foo', 7);
+ $this->service_collection->add('bar', 3);
+ $this->service_collection->add('barfoo', 5);
+ $this->service_collection->add('foobar', 2);
+
+ parent::setUp();
+ }
+
+ public function test_service_collection()
+ {
+ $service_names = array();
+
+ // Test the iterator
+ foreach ($this->service_collection as $name => $service)
+ {
+ $service_names[] = $name;
+ $this->assertInstanceOf('StdClass', $service);
+ }
+
+ $this->assertSame(array('foobar', 'bar', 'barfoo', 'foo'), $service_names);
+ }
+}
diff --git a/tests/di/service_collection_test.php b/tests/di/service_collection_test.php
new file mode 100644
index 0000000000..5b51254a4a
--- /dev/null
+++ b/tests/di/service_collection_test.php
@@ -0,0 +1,47 @@
+<?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_service_collection_test extends \phpbb_test_case
+{
+ /**
+ * @var \phpbb\di\service_collection
+ */
+ protected $service_collection;
+
+ public function setUp()
+ {
+ $container = new phpbb_mock_container_builder();
+ $container->set('foo', new StdClass);
+ $container->set('bar', new StdClass);
+
+ $this->service_collection = new \phpbb\di\service_collection($container);
+ $this->service_collection->add('foo');
+ $this->service_collection->add('bar');
+
+ parent::setUp();
+ }
+
+ public function test_service_collection()
+ {
+ $service_names = array();
+
+ // Test the iterator
+ foreach ($this->service_collection as $name => $service)
+ {
+ $service_names[] = $name;
+ $this->assertInstanceOf('StdClass', $service);
+ }
+
+ $this->assertSame(array('foo', 'bar'), $service_names);
+ }
+}