aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dbal
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dbal')
-rw-r--r--tests/dbal/auto_increment_test.php4
-rw-r--r--tests/dbal/db_tools_test.php20
-rw-r--r--tests/dbal/migration/if.php4
-rw-r--r--tests/dbal/migration/if_params.php44
-rw-r--r--tests/dbal/migration/recall.php2
-rw-r--r--tests/dbal/migration/recall_params.php42
-rw-r--r--tests/dbal/migrator_test.php52
-rw-r--r--tests/dbal/migrator_tool_config_test.php2
-rw-r--r--tests/dbal/migrator_tool_config_text_test.php2
-rw-r--r--tests/dbal/migrator_tool_module_test.php4
-rw-r--r--tests/dbal/migrator_tool_permission_test.php2
-rw-r--r--tests/dbal/sql_affected_rows_test.php2
-rw-r--r--tests/dbal/sql_insert_buffer_test.php2
13 files changed, 159 insertions, 23 deletions
diff --git a/tests/dbal/auto_increment_test.php b/tests/dbal/auto_increment_test.php
index 950a4fc8f7..27d10d2843 100644
--- a/tests/dbal/auto_increment_test.php
+++ b/tests/dbal/auto_increment_test.php
@@ -23,7 +23,7 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml');
}
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
@@ -42,7 +42,7 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
$this->table_exists = true;
}
- protected function tearDown()
+ protected function tearDown(): void
{
if ($this->table_exists)
{
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index 0365463a48..20ea2b3729 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -25,7 +25,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
}
- protected function setUp()
+ protected function setUp(): void
{
parent::setUp();
@@ -77,7 +77,7 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$this->table_exists = true;
}
- protected function tearDown()
+ protected function tearDown(): void
{
if ($this->table_exists)
{
@@ -346,10 +346,10 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_perform_schema_changes_drop_tables()
{
- $db_tools = $this->getMock('\phpbb\db\tools\tools', array(
- 'sql_table_exists',
- 'sql_table_drop',
- ), array(&$this->db));
+ $db_tools = $this->getMockBuilder('\phpbb\db\tools\tools')
+ ->setMethods(array('sql_table_exists', 'sql_table_drop'))
+ ->setConstructorArgs(array(&$this->db))
+ ->getMock();
// pretend all tables exist
$db_tools->expects($this->any())->method('sql_table_exists')
@@ -372,10 +372,10 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_perform_schema_changes_drop_columns()
{
- $db_tools = $this->getMock('\phpbb\db\tools\tools', array(
- 'sql_column_exists',
- 'sql_column_remove',
- ), array(&$this->db));
+ $db_tools = $this->getMockBuilder('\phpbb\db\tools\tools')
+ ->setMethods(array('sql_column_exists', 'sql_column_remove'))
+ ->setConstructorArgs(array(&$this->db))
+ ->getMock();
// pretend all columns exist
$db_tools->expects($this->any())->method('sql_column_exists')
diff --git a/tests/dbal/migration/if.php b/tests/dbal/migration/if.php
index 481250ea77..83fba1cbd4 100644
--- a/tests/dbal/migration/if.php
+++ b/tests/dbal/migration/if.php
@@ -23,11 +23,11 @@ class phpbb_dbal_migration_if extends \phpbb\db\migration\migration
return array(
array('if', array(
true,
- array('custom', array(array(&$this, 'test_true'))),
+ array('custom', array(array($this, 'test_true'))),
)),
array('if', array(
false,
- array('custom', array(array(&$this, 'test_false'))),
+ array('custom', array(array($this, 'test_false'))),
)),
);
}
diff --git a/tests/dbal/migration/if_params.php b/tests/dbal/migration/if_params.php
new file mode 100644
index 0000000000..7280088ddc
--- /dev/null
+++ b/tests/dbal/migration/if_params.php
@@ -0,0 +1,44 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_dbal_migration_if_params extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('if', array(
+ true,
+ array('custom', array(array($this, 'test'), array('true'))),
+ )),
+ array('if', array(
+ false,
+ array('custom', array(array($this, 'test'), array('false'))),
+ )),
+ );
+ }
+
+ function test($param)
+ {
+ global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
+
+ $var = 'migrator_test_if_' . $param . '_failed';
+
+ ${$var} = !${$var};
+ }
+
+}
diff --git a/tests/dbal/migration/recall.php b/tests/dbal/migration/recall.php
index c0333b084d..e065b5c4d8 100644
--- a/tests/dbal/migration/recall.php
+++ b/tests/dbal/migration/recall.php
@@ -21,7 +21,7 @@ class phpbb_dbal_migration_recall extends \phpbb\db\migration\migration
function update_data()
{
return array(
- array('custom', array(array(&$this, 'test_call'))),
+ array('custom', array(array($this, 'test_call'))),
);
}
diff --git a/tests/dbal/migration/recall_params.php b/tests/dbal/migration/recall_params.php
new file mode 100644
index 0000000000..ee0f04c09d
--- /dev/null
+++ b/tests/dbal/migration/recall_params.php
@@ -0,0 +1,42 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+class phpbb_dbal_migration_recall_params extends \phpbb\db\migration\migration
+{
+ function update_schema()
+ {
+ return array();
+ }
+
+ function update_data()
+ {
+ return array(
+ array('custom', array(array($this, 'test_call'), array(5))),
+ );
+ }
+
+ // This function should be called 5 times
+ function test_call($times, $input)
+ {
+ global $migrator_test_call_input;
+
+ $migrator_test_call_input = (int) $input;
+
+ if ($migrator_test_call_input < $times)
+ {
+ return ($migrator_test_call_input + 1);
+ }
+
+ return;
+ }
+}
diff --git a/tests/dbal/migrator_test.php b/tests/dbal/migrator_test.php
index 372b2dbe1e..7d6b100449 100644
--- a/tests/dbal/migrator_test.php
+++ b/tests/dbal/migrator_test.php
@@ -15,6 +15,8 @@ require_once dirname(__FILE__) . '/migration/dummy.php';
require_once dirname(__FILE__) . '/migration/unfulfillable.php';
require_once dirname(__FILE__) . '/migration/if.php';
require_once dirname(__FILE__) . '/migration/recall.php';
+require_once dirname(__FILE__) . '/migration/if_params.php';
+require_once dirname(__FILE__) . '/migration/recall_params.php';
require_once dirname(__FILE__) . '/migration/revert.php';
require_once dirname(__FILE__) . '/migration/revert_with_dependency.php';
require_once dirname(__FILE__) . '/migration/revert_table.php';
@@ -42,7 +44,7 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator.xml');
}
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
@@ -196,6 +198,54 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertSame(10, $migrator_test_call_input);
}
+ public function test_if_params()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_if_params'));
+
+ // Don't like this, but I'm not sure there is any other way to do this
+ global $migrator_test_if_true_failed, $migrator_test_if_false_failed;
+ $migrator_test_if_true_failed = true;
+ $migrator_test_if_false_failed = false;
+
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+ }
+
+ $this->assertFalse($migrator_test_if_true_failed, 'True test failed');
+ $this->assertFalse($migrator_test_if_false_failed, 'False test failed');
+
+ while ($this->migrator->migration_state('phpbb_dbal_migration_if_params') !== false)
+ {
+ $this->migrator->revert('phpbb_dbal_migration_if_params');
+ }
+
+ $this->assertFalse($migrator_test_if_true_failed, 'True test after revert failed');
+ $this->assertFalse($migrator_test_if_false_failed, 'False test after revert failed');
+ }
+
+ public function test_recall_params()
+ {
+ $this->migrator->set_migrations(array('phpbb_dbal_migration_recall_params'));
+
+ global $migrator_test_call_input;
+
+ // Run the schema first
+ $this->migrator->update();
+
+ $i = 0;
+ while (!$this->migrator->finished())
+ {
+ $this->migrator->update();
+
+ $this->assertSame($i, $migrator_test_call_input);
+
+ $i++;
+ }
+
+ $this->assertSame(5, $migrator_test_call_input);
+ }
+
public function test_revert()
{
global $migrator_test_revert_counter;
diff --git a/tests/dbal/migrator_tool_config_test.php b/tests/dbal/migrator_tool_config_test.php
index 13e0c13e3c..74d816dbcd 100644
--- a/tests/dbal/migrator_tool_config_test.php
+++ b/tests/dbal/migrator_tool_config_test.php
@@ -13,7 +13,7 @@
class phpbb_dbal_migrator_tool_config_test extends phpbb_test_case
{
- public function setup()
+ public function setUp(): void
{
$this->config = new \phpbb\config\config(array());
diff --git a/tests/dbal/migrator_tool_config_text_test.php b/tests/dbal/migrator_tool_config_text_test.php
index b271c2d62e..051e0a7556 100644
--- a/tests/dbal/migrator_tool_config_text_test.php
+++ b/tests/dbal/migrator_tool_config_text_test.php
@@ -18,7 +18,7 @@ class phpbb_dbal_migrator_tool_config_text_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_config_text.xml');
}
- public function setup()
+ public function setUp(): void
{
parent::setup();
diff --git a/tests/dbal/migrator_tool_module_test.php b/tests/dbal/migrator_tool_module_test.php
index e34ee7b59c..ecc7b384e7 100644
--- a/tests/dbal/migrator_tool_module_test.php
+++ b/tests/dbal/migrator_tool_module_test.php
@@ -21,7 +21,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_module.xml');
}
- public function setup()
+ public function setUp(): void
{
// Need global $db, $user for delete_module function in acp_modules
global $phpbb_root_path, $phpEx, $skip_add_log, $db, $user, $phpbb_log;
@@ -39,7 +39,7 @@ class phpbb_dbal_migrator_tool_module_test extends phpbb_database_test_case
$cache = new phpbb_mock_cache;
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
- $auth = $this->getMock('\phpbb\auth\auth');
+ $auth = $this->createMock('\phpbb\auth\auth');
$phpbb_log = new \phpbb\log\log($db, $user, $auth, $phpbb_dispatcher, $phpbb_root_path, 'adm/', $phpEx, LOG_TABLE);
// Correctly set the root path for this test to this directory, so the classes can be found
diff --git a/tests/dbal/migrator_tool_permission_test.php b/tests/dbal/migrator_tool_permission_test.php
index ccad6a1387..a48c367896 100644
--- a/tests/dbal/migrator_tool_permission_test.php
+++ b/tests/dbal/migrator_tool_permission_test.php
@@ -24,7 +24,7 @@ class phpbb_dbal_migrator_tool_permission_test extends phpbb_database_test_case
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/migrator_permission.xml');
}
- public function setup()
+ public function setUp(): void
{
// Global $db and $cache are needed in acp/auth.php constructor
global $phpbb_root_path, $phpEx, $db, $cache;
diff --git a/tests/dbal/sql_affected_rows_test.php b/tests/dbal/sql_affected_rows_test.php
index 07d7318358..e9fb1f2724 100644
--- a/tests/dbal/sql_affected_rows_test.php
+++ b/tests/dbal/sql_affected_rows_test.php
@@ -16,7 +16,7 @@ class phpbb_dbal_sql_affected_rows_test extends phpbb_database_test_case
/** @var \phpbb\db\driver\driver_interface */
protected $db;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();
$this->db = $this->new_dbal();
diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php
index eae0abceba..b0e678b9da 100644
--- a/tests/dbal/sql_insert_buffer_test.php
+++ b/tests/dbal/sql_insert_buffer_test.php
@@ -16,7 +16,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
protected $db;
protected $buffer;
- public function setUp()
+ public function setUp(): void
{
parent::setUp();