From 997028a0ecf1df761363b061acf6ae220dd3479f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 01:17:51 +0200 Subject: [ticket/12483] Allow to setup extensions before database and functional tests PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'tests/test_framework/phpbb_database_test_case.php') 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(); -- cgit v1.2.1 From 5bae2911a232648dcc355153180f9bb7ace64d83 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 11:48:52 +0200 Subject: [ticket/12483] Move schema files into tmp/ and only copy them when needed PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 52 +++++++++++++---------- 1 file changed, 30 insertions(+), 22 deletions(-) (limited to 'tests/test_framework/phpbb_database_test_case.php') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 157982ff3c..c704516968 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -54,40 +54,48 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test static public function setUpBeforeClass() { - $schema_md5 = md5(serialize(static::setup_extensions())); + $setup_extensions = static::setup_extensions(); + self::$schema_file = ''; + if (!empty($setup_extensions)) + { + $schema_md5 = md5(serialize($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'; + self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json'; + self::$phpbb_schema_copy = __DIR__ . '/../tmp/schema_phpbb_copy.json'; + self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json'; - if (!file_exists(self::$schema_file)) - { - global $phpbb_root_path, $phpEx, $table_prefix; + 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(); + $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(); + $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); - } + $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); + 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); + if (self::$schema_file !== '') + { + copy(self::$phpbb_schema_copy, self::$install_schema_file); + } parent::tearDownAfterClass(); } -- cgit v1.2.1 From 13217fe3ff391ab958b0d0c6568366875c7d198e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 3 May 2014 11:58:12 +0200 Subject: [ticket/12483] Require the extension manager class PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/test_framework/phpbb_database_test_case.php') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index c704516968..d8533a3d15 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,6 +11,8 @@ * */ +require_once dirname(__FILE__) . '/phpbb_testcase_extension_manager.php'; + abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase { static private $already_connected; -- cgit v1.2.1 From 18d145f38f0f512039a15f64e132b2607283af89 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 6 May 2014 15:23:55 +0200 Subject: [ticket/12483] Use file_put_contents() PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'tests/test_framework/phpbb_database_test_case.php') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index d8533a3d15..ff55b3fc63 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -80,9 +80,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test $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); + file_put_contents(self::$schema_file, json_encode($schema_data)); } copy(self::$install_schema_file, self::$phpbb_schema_copy); -- cgit v1.2.1 From d0766a23218fb028aefaef231b6e42034f69bc8f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 19:38:24 +0200 Subject: [ticket/12483] Fix finder usage when generating the schema.json file PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tests/test_framework/phpbb_database_test_case.php') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index ff55b3fc63..049bd022d7 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -11,8 +11,6 @@ * */ -require_once dirname(__FILE__) . '/phpbb_testcase_extension_manager.php'; - abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_TestCase { static private $already_connected; @@ -70,9 +68,10 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test { 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); + $finder = new \phpbb\finder(new \phpbb\filesystem(), $phpbb_root_path, null, $phpEx); $classes = $finder->core_path('phpbb/') - ->core_directory('db/migration/data') + ->core_directory('/db/migration/data') + ->set_extensions($setup_extensions) ->extension_directory('migrations') ->get_classes(); -- cgit v1.2.1 From 38c2d42304047d9f7f1457c37bc5496825e14ae3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Tue, 10 Jun 2014 19:44:06 +0200 Subject: [ticket/12483] Remove unused globals PHPBB3-12483 --- tests/test_framework/phpbb_database_test_case.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests/test_framework/phpbb_database_test_case.php') diff --git a/tests/test_framework/phpbb_database_test_case.php b/tests/test_framework/phpbb_database_test_case.php index 049bd022d7..05281b1d71 100644 --- a/tests/test_framework/phpbb_database_test_case.php +++ b/tests/test_framework/phpbb_database_test_case.php @@ -212,8 +212,6 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test public function new_dbal() { - global $phpbb_root_path, $phpEx; - $config = $this->get_database_config(); $db = new $config['dbms'](); -- cgit v1.2.1