1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

Merge branch 'develop-ascraeus' into develop

* develop-ascraeus: (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/
  ...
This commit is contained in:
Andreas Fischer
2014-07-11 11:49:51 +02:00
28 changed files with 919 additions and 482 deletions

View File

@@ -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());
}
}

View File

@@ -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()
{
$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');
protected $config_php;
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
/**
* @var \phpbb\di\container_builder
*/
protected $builder;
protected $phpbb_root_path;
protected $filename;
public function setUp()
{
$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_phpbb_create_install_container()
public function test_default_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');
$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_dump_container()
{
$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);
$this->assertTrue($container->isFrozen());
// 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);
// 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'),
);
}
}
}

View File

@@ -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

View File

@@ -0,0 +1,2 @@
parameters:
available: true

View File

@@ -0,0 +1,2 @@
parameters:
disabled: true

View File

@@ -0,0 +1,2 @@
parameters:
enabled: true

View File

@@ -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

3
tests/fixtures/config.php vendored Normal file
View File

@@ -0,0 +1,3 @@
<?php
$foo = 'bar';
$foo_foo = 'bar bar';

3
tests/fixtures/config_other.php vendored Normal file
View File

@@ -0,0 +1,3 @@
<?php
$bar = 'foo';
$bar_bar = 'foo foo';

View File

@@ -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);
}

View File

@@ -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;
}
}

View File

@@ -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'] : '',