aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_framework/phpbb_database_test_case.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-03 01:17:51 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-06-10 19:41:34 +0200
commit997028a0ecf1df761363b061acf6ae220dd3479f (patch)
tree3187b7bf42e5f250a88acdb94e8a9be275fa5875 /tests/test_framework/phpbb_database_test_case.php
parent9842137028f70a2b48ea4eaaddd710cbcf7dc8d5 (diff)
downloadforums-997028a0ecf1df761363b061acf6ae220dd3479f.tar
forums-997028a0ecf1df761363b061acf6ae220dd3479f.tar.gz
forums-997028a0ecf1df761363b061acf6ae220dd3479f.tar.bz2
forums-997028a0ecf1df761363b061acf6ae220dd3479f.tar.xz
forums-997028a0ecf1df761363b061acf6ae220dd3479f.zip
[ticket/12483] Allow to setup extensions before database and functional tests
PHPBB3-12483
Diffstat (limited to 'tests/test_framework/phpbb_database_test_case.php')
-rw-r--r--tests/test_framework/phpbb_database_test_case.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php
index 60ac68e7b8..157982ff3c 100644
--- a/tests/test_framework/phpbb_database_test_case.php
+++ b/tests/test_framework/phpbb_database_test_case.php
@@ -21,6 +21,12 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
protected $fixture_xml_data;
+ static protected $schema_file;
+
+ static protected $phpbb_schema_copy;
+
+ static protected $install_schema_file;
+
public function __construct($name = NULL, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
@@ -38,6 +44,54 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
$this->db_connections = array();
}
+ /**
+ * @return array List of extensions that should be set up
+ */
+ static protected function setup_extensions()
+ {
+ return array();
+ }
+
+ static public function setUpBeforeClass()
+ {
+ $schema_md5 = md5(serialize(static::setup_extensions()));
+
+ self::$schema_file = __DIR__ . '/schemas/' . $schema_md5 . '.json';
+ self::$phpbb_schema_copy = __DIR__ . '/schemas/schema_phpbb_copy.json';
+ self::$install_schema_file = __DIR__ . '/../../../../../install/schemas/schema.json';
+
+ if (!file_exists(self::$schema_file))
+ {
+ global $phpbb_root_path, $phpEx, $table_prefix;
+
+ $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path);
+ $classes = $finder->core_path('phpbb/')
+ ->core_directory('db/migration/data')
+ ->extension_directory('migrations')
+ ->get_classes();
+
+ $db = new \phpbb\db\driver\sqlite();
+ $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, new \phpbb\db\tools($db, true), $phpbb_root_path, $phpEx, $table_prefix);
+ $schema_data = $schema_generator->get_schema();
+
+ $fp = fopen(self::$schema_file, 'wb');
+ fwrite($fp, json_encode($schema_data));
+ fclose($fp);
+ }
+
+ copy(self::$install_schema_file, self::$phpbb_schema_copy);
+ copy(self::$schema_file, self::$install_schema_file);
+
+ parent::setUpBeforeClass();
+ }
+
+ static public function tearDownAfterClass()
+ {
+ copy(self::$phpbb_schema_copy, self::$install_schema_file);
+
+ parent::tearDownAfterClass();
+ }
+
protected function tearDown()
{
parent::tearDown();