[ticket/12483] Move schema files into tmp/ and only copy them when needed

PHPBB3-12483
This commit is contained in:
Joas Schilling 2014-05-03 11:48:52 +02:00
parent 709296e54a
commit 5bae2911a2

View file

@ -54,40 +54,48 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
static public function setUpBeforeClass() static public function setUpBeforeClass()
{ {
$schema_md5 = md5(serialize(static::setup_extensions())); $setup_extensions = static::setup_extensions();
self::$schema_file = '';
self::$schema_file = __DIR__ . '/schemas/' . $schema_md5 . '.json'; if (!empty($setup_extensions))
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; $schema_md5 = md5(serialize($setup_extensions));
$finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path); self::$schema_file = __DIR__ . '/../tmp/' . $schema_md5 . '.json';
$classes = $finder->core_path('phpbb/') self::$phpbb_schema_copy = __DIR__ . '/../tmp/schema_phpbb_copy.json';
->core_directory('db/migration/data') self::$install_schema_file = __DIR__ . '/../../phpBB/install/schemas/schema.json';
->extension_directory('migrations')
->get_classes();
$db = new \phpbb\db\driver\sqlite(); if (!file_exists(self::$schema_file))
$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(); global $phpbb_root_path, $phpEx, $table_prefix;
$fp = fopen(self::$schema_file, 'wb'); $finder = new \phpbb\extension\finder(new phpbb_testcase_extension_manager(static::setup_extensions()), new \phpbb\filesystem(), $phpbb_root_path);
fwrite($fp, json_encode($schema_data)); $classes = $finder->core_path('phpbb/')
fclose($fp); ->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);
} }
copy(self::$install_schema_file, self::$phpbb_schema_copy);
copy(self::$schema_file, self::$install_schema_file);
parent::setUpBeforeClass(); parent::setUpBeforeClass();
} }
static public function tearDownAfterClass() 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(); parent::tearDownAfterClass();
} }