Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
54.95% |
50 / 91 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| get_callable_from_step_test | |
54.95% |
50 / 91 |
|
80.00% |
4 / 5 |
11.48 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
43 / 43 |
|
100.00% |
1 / 1 |
2 | |||
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get_callable_from_step_provider | |
0.00% |
0 / 41 |
|
0.00% |
0 / 1 |
2 | |||
| test_get_callable_from_step | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| call_get_callable_from_step | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 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 | class get_callable_from_step_test extends phpbb_database_test_case |
| 15 | { |
| 16 | protected $migrator; |
| 17 | protected $module_added; |
| 18 | |
| 19 | protected function setUp(): void |
| 20 | { |
| 21 | global $phpbb_root_path, $php_ext, $table_prefix, $phpbb_log, $user; |
| 22 | |
| 23 | parent::setUp(); |
| 24 | |
| 25 | $phpbb_log = $this->getMockBuilder('\phpbb\log\log')->disableOriginalConstructor()->getMock(); |
| 26 | $db = $this->new_dbal(); |
| 27 | $db_doctrine = $this->new_doctrine_dbal(); |
| 28 | $factory = new \phpbb\db\tools\factory(); |
| 29 | $db_tools = $factory->get($db_doctrine); |
| 30 | $db_tools->set_table_prefix($table_prefix); |
| 31 | $user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock(); |
| 32 | $user->ip = '127.0.0.1'; |
| 33 | $module_manager = new \phpbb\module\module_manager( |
| 34 | $this->getMockBuilder('\phpbb\cache\driver\dummy')->disableOriginalConstructor()->getMock(), |
| 35 | $db, |
| 36 | new phpbb_mock_extension_manager($phpbb_root_path), |
| 37 | 'phpbb_modules', |
| 38 | $phpbb_root_path, |
| 39 | $php_ext |
| 40 | ); |
| 41 | $module_tools = new \phpbb\db\migration\tool\module($db, $user, $module_manager, 'phpbb_modules'); |
| 42 | $this->migrator = new \phpbb\db\migrator( |
| 43 | new phpbb_mock_container_builder(), |
| 44 | new \phpbb\config\config(array()), |
| 45 | $db, |
| 46 | $db_tools, |
| 47 | 'phpbb_migrations', |
| 48 | $phpbb_root_path, |
| 49 | $php_ext, |
| 50 | $table_prefix, |
| 51 | self::get_core_tables(), |
| 52 | array($module_tools), |
| 53 | new \phpbb\db\migration\helper() |
| 54 | ); |
| 55 | |
| 56 | if (!$module_tools->exists('acp', 0, 'new_module_langname')) |
| 57 | { |
| 58 | $module_tools->add('acp', 0, array( |
| 59 | 'module_basename' => 'new_module_basename', |
| 60 | 'module_langname' => 'new_module_langname', |
| 61 | 'module_mode' => 'settings', |
| 62 | 'module_auth' => '', |
| 63 | 'module_display' => true, |
| 64 | 'before' => false, |
| 65 | 'after' => false, |
| 66 | )); |
| 67 | $this->module_added = true; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | public function getDataSet() |
| 72 | { |
| 73 | return $this->createXMLDataSet(__DIR__ . '/../dbal/fixtures/migrator.xml'); |
| 74 | } |
| 75 | |
| 76 | public static function get_callable_from_step_provider() |
| 77 | { |
| 78 | return array( |
| 79 | array( |
| 80 | array('if', array( |
| 81 | false, |
| 82 | array('permission.add', array('some_data')), |
| 83 | )), |
| 84 | true, // expects false |
| 85 | ), |
| 86 | array( |
| 87 | array('if', array( |
| 88 | array('module.exists', array( |
| 89 | 'mcp', |
| 90 | 'RANDOM_PARENT', |
| 91 | 'RANDOM_MODULE' |
| 92 | )), |
| 93 | array('permission.add', array('some_data')), |
| 94 | )), |
| 95 | true, // expects false |
| 96 | ), |
| 97 | array( |
| 98 | array('if', array( |
| 99 | array('module.exists', array( |
| 100 | 'acp', |
| 101 | 0, |
| 102 | 'new_module_langname' |
| 103 | )), |
| 104 | array('module.add', array( |
| 105 | 'acp', |
| 106 | 0, |
| 107 | 'module_basename' => 'new_module_basename2', |
| 108 | 'module_langname' => 'new_module_langname2', |
| 109 | 'module_mode' => 'settings', |
| 110 | 'module_auth' => '', |
| 111 | 'module_display' => true, |
| 112 | 'before' => false, |
| 113 | 'after' => false, |
| 114 | )), |
| 115 | )), |
| 116 | false, // expects false |
| 117 | ), |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * @dataProvider get_callable_from_step_provider |
| 123 | */ |
| 124 | public function test_get_callable_from_step($step, $expects_false) |
| 125 | { |
| 126 | if ($expects_false) |
| 127 | { |
| 128 | $this->assertFalse($this->call_get_callable_from_step($step)); |
| 129 | } |
| 130 | else |
| 131 | { |
| 132 | $this->assertNotFalse($this->call_get_callable_from_step($step)); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | protected function call_get_callable_from_step($step) |
| 137 | { |
| 138 | $class = new ReflectionClass($this->migrator); |
| 139 | $method = $class->getMethod('get_callable_from_step'); |
| 140 | return $method->invokeArgs($this->migrator, array($step)); |
| 141 | } |
| 142 | } |