Skip to content

Commit a09ea47

Browse files
committed
Create a function to build a container
1 parent aec2487 commit a09ea47

1 file changed

Lines changed: 23 additions & 10 deletions

File tree

tests/framework/extension_database_test_case.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,26 @@
99

1010
abstract class extension_database_test_case extends phpbb_database_test_case
1111
{
12+
protected $container;
13+
14+
public function get_container()
15+
{
16+
17+
if ($this->container === null)
18+
{
19+
global $phpbb_root_path, $phpEx;
20+
21+
// We must create a config file to be able to create the container
22+
$this->create_config_file($phpbb_root_path, $phpEx);
23+
24+
// Setup the container
25+
require_once($phpbb_root_path . 'includes/functions_container.' . $phpEx);
26+
$this->container = phpbb_create_default_container($phpbb_root_path, $phpEx);
27+
}
28+
29+
return $this->container;
30+
}
31+
1232
public function getConnection()
1333
{
1434
global $phpbb_root_path, $phpEx;
@@ -31,17 +51,10 @@ public function getConnection()
3151
// Install phpBB's schema
3252
$manager->load_schema($this->new_dbal());
3353

34-
// We must create a config file to be able to create the container
35-
$this->create_config_file($phpbb_root_path, $phpEx);
36-
37-
// Setup the container
38-
require_once($phpbb_root_path . 'includes/functions_container.' . $phpEx);
39-
$this->container = phpbb_create_default_container($phpbb_root_path, $phpEx);
40-
4154
// Setup some globals needed to add schema data and module data to the tables
4255
global $cache, $db, $phpbb_log, $phpbb_container;
4356

44-
$phpbb_container = $this->container;
57+
$phpbb_container = $this->get_container();
4558
$cache = $phpbb_container->get('cache');
4659
$db = $phpbb_container->get('dbal.conn');
4760
$phpbb_log = $phpbb_container->get('log');
@@ -66,8 +79,8 @@ public function getConnection()
6679
// If there are any migrations, load and run them all
6780
if (file_exists($migrations_path) && is_dir($migrations_path))
6881
{
69-
$finder = $this->container->get('ext.finder');
70-
$migrator = $this->container->get('migrator');
82+
$finder = $phpbb_container->get('ext.finder');
83+
$migrator = $phpbb_container->get('migrator');
7184

7285
$migrations = array();
7386
$vendor_ext = $this->get_vendor_ext($phpbb_root_path);

0 commit comments

Comments
 (0)