Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
93.94% |
62 / 66 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_migration_test_base | |
93.94% |
62 / 66 |
|
50.00% |
2 / 4 |
8.01 | |
0.00% |
0 / 1 |
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setUp | |
100.00% |
55 / 55 |
|
100.00% |
1 / 1 |
1 | |||
| apply_migration | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
3.58 | |||
| revert_migration | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
3.58 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | abstract class phpbb_migration_test_base extends phpbb_database_test_case |
| 15 | { |
| 16 | /** @var \phpbb\auth\auth */ |
| 17 | protected $auth; |
| 18 | |
| 19 | /** @var \phpbb\cache\driver\driver_interface */ |
| 20 | protected $cache; |
| 21 | |
| 22 | /** @var \phpbb\cache\service */ |
| 23 | protected $cache_service; |
| 24 | |
| 25 | /** @var \phpbb\config\config */ |
| 26 | protected $config; |
| 27 | |
| 28 | /** @var \phpbb\db\driver\driver_interface */ |
| 29 | protected $db; |
| 30 | |
| 31 | /** @var \phpbb\db\tools\tools_interface */ |
| 32 | protected $db_tools; |
| 33 | |
| 34 | /** @var \Doctrine\DBAL\Connection */ |
| 35 | protected $doctrine_db; |
| 36 | |
| 37 | /** @var \phpbb\extension\manager */ |
| 38 | protected $extension_manager; |
| 39 | |
| 40 | /** @var \phpbb\db\migrator */ |
| 41 | protected $migrator; |
| 42 | |
| 43 | /** @var \phpbb\db\migration\tool\tool_interface */ |
| 44 | protected $tools; |
| 45 | |
| 46 | /** @var \phpbb\user */ |
| 47 | protected $user; |
| 48 | |
| 49 | /** @var string */ |
| 50 | protected $fixture; |
| 51 | |
| 52 | /** @var string */ |
| 53 | protected $migration_class; |
| 54 | |
| 55 | public function getDataSet() |
| 56 | { |
| 57 | return $this->createXMLDataSet(__DIR__ . $this->fixture); |
| 58 | } |
| 59 | |
| 60 | protected function setUp(): void |
| 61 | { |
| 62 | global $cache, $db, $phpbb_log, $phpbb_dispatcher, $phpbb_root_path, $phpEx, $skip_add_log, $table_prefix, $user; |
| 63 | |
| 64 | parent::setUp(); |
| 65 | |
| 66 | // Disable the logs |
| 67 | $skip_add_log = true; |
| 68 | |
| 69 | $db = $this->db = $this->new_dbal(); |
| 70 | $this->doctrine_db = $this->new_doctrine_dbal(); |
| 71 | $factory = new \phpbb\db\tools\factory(); |
| 72 | $this->db_tools = $factory->get($this->doctrine_db); |
| 73 | $this->db_tools->set_table_prefix($table_prefix); |
| 74 | $this->cache = new phpbb_mock_cache(); |
| 75 | $this->auth = new \phpbb\auth\auth(); |
| 76 | $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); |
| 77 | $this->config = new \phpbb\config\db($this->db, $this->cache, 'phpbb_config'); |
| 78 | $this->config->initialise($this->cache); |
| 79 | $cache = $this->cache_service = new \phpbb\cache\service($this->cache, $this->config, $this->db, $phpbb_dispatcher, $phpbb_root_path, $phpEx); |
| 80 | |
| 81 | |
| 82 | $lang_loader = new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx); |
| 83 | $lang = new \phpbb\language\language($lang_loader); |
| 84 | $user = $this->user = new \phpbb\user($lang, '\phpbb\datetime'); |
| 85 | |
| 86 | $phpbb_log = new \phpbb\log\log($this->db, $this->user, $this->auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE); |
| 87 | |
| 88 | $container = new phpbb_mock_container_builder(); |
| 89 | $container->set('event_dispatcher', $phpbb_dispatcher); |
| 90 | |
| 91 | $finder_factory = $this->createMock('\phpbb\finder\factory'); |
| 92 | $this->extension_manager = new \phpbb\extension\manager( |
| 93 | $container, |
| 94 | $this->db, |
| 95 | $this->config, |
| 96 | $finder_factory, |
| 97 | 'phpbb_ext', |
| 98 | __DIR__ . '/../../phpBB/', |
| 99 | null |
| 100 | ); |
| 101 | |
| 102 | $module_manager = new \phpbb\module\module_manager($this->cache, $this->db, $this->extension_manager, 'phpbb_modules', $phpbb_root_path, $phpEx); |
| 103 | |
| 104 | $this->tools = array( |
| 105 | 'config' => new \phpbb\db\migration\tool\config($this->config), |
| 106 | 'config_text' => new \phpbb\db\migration\tool\config_text(new \phpbb\config\db_text($this->db, 'phpbb_config_text')), |
| 107 | 'module' => new \phpbb\db\migration\tool\module($this->db, $this->user, $module_manager, 'phpbb_modules'), |
| 108 | 'permission' => new \phpbb\db\migration\tool\permission($this->db, $this->cache_service, $this->auth, $phpbb_root_path, $phpEx), |
| 109 | ); |
| 110 | |
| 111 | $this->migrator = new \phpbb\db\migrator( |
| 112 | $container, |
| 113 | $this->config, |
| 114 | $this->db, |
| 115 | $this->db_tools, |
| 116 | 'phpbb_migrations', |
| 117 | __DIR__ . '/../../phpBB/', |
| 118 | 'php', |
| 119 | 'phpbb_', |
| 120 | self::get_core_tables(), |
| 121 | $this->tools, |
| 122 | new \phpbb\db\migration\helper() |
| 123 | ); |
| 124 | $container->set('migrator', $this->migrator); |
| 125 | |
| 126 | $migration = $this->migrator->get_migration($this->migration_class); |
| 127 | $depends = $migration->depends_on(); |
| 128 | $this->migrator->populate_migrations($depends); |
| 129 | |
| 130 | $this->migrator->set_migrations([$this->migration_class]); |
| 131 | } |
| 132 | |
| 133 | protected function apply_migration() |
| 134 | { |
| 135 | while (!$this->migrator->finished()) |
| 136 | { |
| 137 | try |
| 138 | { |
| 139 | $this->migrator->update(); |
| 140 | } |
| 141 | catch (\phpbb\db\migration\exception $e) |
| 142 | { |
| 143 | $this->fail('Applying migration error: ' . $e->__toString()); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return $this->migrator->finished(); |
| 148 | } |
| 149 | |
| 150 | protected function revert_migration() |
| 151 | { |
| 152 | while ($this->migrator->migration_state($this->migration_class) !== false) |
| 153 | { |
| 154 | try |
| 155 | { |
| 156 | $this->migrator->revert($this->migration_class); |
| 157 | } |
| 158 | catch (\phpbb\db\migration\exception $e) |
| 159 | { |
| 160 | $this->fail('Reverting migration error: ' . $e->__toString()); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | return !$this->migrator->migration_state($this->migration_class); |
| 165 | } |
| 166 | } |