mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-24 10:31:57 +02:00
Merge pull request #1056 from igorw/feature/compiled-dic
[feature/compiled-dic] Compile the DI Container into a cached class
This commit is contained in:
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2010 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
class phpbb_cron_task_provider_test extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
$this->tasks = array(
|
||||
'phpbb_cron_task_core_dummy_task',
|
||||
'phpbb_cron_task_core_second_dummy_task',
|
||||
'phpbb_ext_testext_cron_dummy_task',
|
||||
);
|
||||
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\TaggedContainerInterface');
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->returnValue(array_flip($this->tasks)));
|
||||
$container
|
||||
->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnCallback(function ($name) {
|
||||
return new $name;
|
||||
}));
|
||||
|
||||
$this->provider = new phpbb_cron_task_provider($container);
|
||||
}
|
||||
|
||||
public function test_manager_finds_shipped_tasks()
|
||||
{
|
||||
$task_names = array();
|
||||
foreach ($this->provider as $task)
|
||||
{
|
||||
$task_names[] = $task->get_name();
|
||||
}
|
||||
sort($task_names);
|
||||
|
||||
$this->assertEquals(array(
|
||||
'phpbb_cron_task_core_dummy_task',
|
||||
'phpbb_cron_task_core_second_dummy_task',
|
||||
'phpbb_ext_testext_cron_dummy_task',
|
||||
), $task_names);
|
||||
}
|
||||
}
|
72
tests/di/create_container_test.php
Normal file
72
tests/di/create_container_test.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/functions_container.php';
|
||||
require_once dirname(__FILE__) . '/../../phpBB/includes/db/dbal.php';
|
||||
|
||||
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),
|
||||
);
|
||||
$container = phpbb_create_container($extensions, $phpbb_root_path, 'php');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
||||
}
|
||||
|
||||
public function test_phpbb_create_install_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),
|
||||
);
|
||||
$container = phpbb_create_install_container($phpbb_root_path, 'php');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
||||
$this->assertTrue($container->isFrozen());
|
||||
}
|
||||
|
||||
public function test_phpbb_create_compiled_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),
|
||||
);
|
||||
$container = phpbb_create_compiled_container($extensions, array(), $phpbb_root_path, 'php');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
|
||||
$this->assertTrue($container->isFrozen());
|
||||
}
|
||||
}
|
||||
|
||||
class dbal_container_mock extends dbal
|
||||
{
|
||||
public function sql_connect()
|
||||
{
|
||||
}
|
||||
|
||||
public function sql_query()
|
||||
{
|
||||
}
|
||||
|
||||
public function sql_fetchrow()
|
||||
{
|
||||
}
|
||||
|
||||
public function sql_freeresult()
|
||||
{
|
||||
}
|
||||
}
|
11
tests/di/fixtures/config.php
Normal file
11
tests/di/fixtures/config.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
// phpBB 3.1.x auto-generated configuration file
|
||||
// Do not change anything in this file!
|
||||
$dbms = 'container_mock';
|
||||
$dbhost = '127.0.0.1';
|
||||
$dbport = '';
|
||||
$dbname = 'phpbb';
|
||||
$dbuser = 'root';
|
||||
$dbpasswd = '';
|
||||
$table_prefix = 'phpbb_';
|
||||
$acm_type = 'phpbb_cache_driver_null';
|
@@ -11,7 +11,7 @@ class phpbb_event_dispatcher_test extends phpbb_test_case
|
||||
{
|
||||
public function test_trigger_event()
|
||||
{
|
||||
$dispatcher = new phpbb_event_dispatcher();
|
||||
$dispatcher = new phpbb_event_dispatcher(new phpbb_mock_container_builder());
|
||||
|
||||
$dispatcher->addListener('core.test_event', function (phpbb_event_data $event) {
|
||||
$event['foo'] = $event['foo'] . '2';
|
||||
|
160
tests/mock/container_builder.php
Normal file
160
tests/mock/container_builder.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package testing
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ScopeInterface;
|
||||
|
||||
class phpbb_mock_container_builder implements ContainerInterface
|
||||
{
|
||||
/**
|
||||
* Sets a service.
|
||||
*
|
||||
* @param string $id The service identifier
|
||||
* @param object $service The service instance
|
||||
* @param string $scope The scope of the service
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a service.
|
||||
*
|
||||
* @param string $id The service identifier
|
||||
* @param int $invalidBehavior The behavior when the service does not exist
|
||||
*
|
||||
* @return object The associated service
|
||||
*
|
||||
* @throws InvalidArgumentException if the service is not defined
|
||||
* @throws ServiceCircularReferenceException When a circular reference is detected
|
||||
* @throws ServiceNotFoundException When the service is not defined
|
||||
*
|
||||
* @see Reference
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the given service is defined.
|
||||
*
|
||||
* @param string $id The service identifier
|
||||
*
|
||||
* @return Boolean true if the service is defined, false otherwise
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function has($id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a parameter.
|
||||
*
|
||||
* @param string $name The parameter name
|
||||
*
|
||||
* @return mixed The parameter value
|
||||
*
|
||||
* @throws InvalidArgumentException if the parameter is not defined
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function getParameter($name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a parameter exists.
|
||||
*
|
||||
* @param string $name The parameter name
|
||||
*
|
||||
* @return Boolean The presence of parameter in container
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasParameter($name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a parameter.
|
||||
*
|
||||
* @param string $name The parameter name
|
||||
* @param mixed $value The parameter value
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function setParameter($name, $value)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Enters the given scope
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function enterScope($name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Leaves the current scope, and re-enters the parent scope
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function leaveScope($name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a scope to the container
|
||||
*
|
||||
* @param ScopeInterface $scope
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function addScope(ScopeInterface $scope)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this container has the given scope
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function hasScope($name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the given scope is currently active.
|
||||
*
|
||||
* It does however not check if the scope actually exists.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Boolean
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public function isScopeActive($name)
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user