|
9 | 9 |
|
10 | 10 | abstract class extension_database_test_case extends phpbb_database_test_case |
11 | 11 | { |
12 | | - static protected $already_connected = false; |
| 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 | + } |
13 | 31 |
|
14 | 32 | public function getConnection() |
15 | 33 | { |
16 | 34 | global $phpbb_root_path, $phpEx; |
17 | 35 |
|
| 36 | + static $already_connected = false; |
| 37 | + |
18 | 38 | $config = $this->get_database_config(); |
19 | 39 |
|
20 | 40 | $manager = $this->create_connection_manager($config); |
21 | 41 |
|
22 | | - if (!self::$already_connected) |
| 42 | + if (!$already_connected) |
23 | 43 | { |
24 | 44 | $manager->recreate_db(); |
25 | 45 | } |
26 | 46 |
|
27 | 47 | $manager->connect(); |
28 | 48 |
|
29 | | - if (!self::$already_connected) |
| 49 | + if (!$already_connected) |
30 | 50 | { |
31 | 51 | // Install phpBB's schema |
32 | 52 | $manager->load_schema($this->new_dbal()); |
33 | 53 |
|
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 | | - |
41 | 54 | // Setup some globals needed to add schema data and module data to the tables |
42 | 55 | global $cache, $db, $phpbb_log, $phpbb_container; |
43 | 56 |
|
44 | | - $phpbb_container = $this->container; |
| 57 | + $phpbb_container = $this->get_container(); |
45 | 58 | $cache = $phpbb_container->get('cache'); |
46 | 59 | $db = $phpbb_container->get('dbal.conn'); |
47 | 60 | $phpbb_log = $phpbb_container->get('log'); |
@@ -100,7 +113,7 @@ public function getConnection() |
100 | 113 | } |
101 | 114 | } |
102 | 115 |
|
103 | | - self::$already_connected = true; |
| 116 | + $already_connected = true; |
104 | 117 | } |
105 | 118 |
|
106 | 119 | return $this->createDefaultDBConnection($manager->get_pdo(), 'testdb'); |
|
0 commit comments