mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 22:28:51 +00:00
Merge branch 'develop-ascraeus' into develop
* develop-ascraeus: [ticket/12362] Do not use database test case as it's not needed [ticket/12362] Add tests for schema generator [ticket/12362] Throw exception in schema generator on unresolvable dependency
This commit is contained in:
commit
b2834a5563
2 changed files with 85 additions and 0 deletions
|
@ -40,6 +40,9 @@ class schema_generator
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $tables;
|
protected $tables;
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
protected $dependencies = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
|
@ -69,11 +72,13 @@ class schema_generator
|
||||||
$migrations = $this->class_names;
|
$migrations = $this->class_names;
|
||||||
|
|
||||||
$tree = array();
|
$tree = array();
|
||||||
|
$check_dependencies = true;
|
||||||
while (!empty($migrations))
|
while (!empty($migrations))
|
||||||
{
|
{
|
||||||
foreach ($migrations as $migration_class)
|
foreach ($migrations as $migration_class)
|
||||||
{
|
{
|
||||||
$open_dependencies = array_diff($migration_class::depends_on(), $tree);
|
$open_dependencies = array_diff($migration_class::depends_on(), $tree);
|
||||||
|
|
||||||
if (empty($open_dependencies))
|
if (empty($open_dependencies))
|
||||||
{
|
{
|
||||||
$migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
|
$migration = new $migration_class($this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
|
||||||
|
@ -170,10 +175,41 @@ class schema_generator
|
||||||
}
|
}
|
||||||
unset($migrations[$migration_key]);
|
unset($migrations[$migration_key]);
|
||||||
}
|
}
|
||||||
|
else if ($check_dependencies)
|
||||||
|
{
|
||||||
|
$this->dependencies = array_merge($this->dependencies, $open_dependencies);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only run this check after the first run
|
||||||
|
if ($check_dependencies)
|
||||||
|
{
|
||||||
|
$this->check_dependencies();
|
||||||
|
$check_dependencies = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ksort($this->tables);
|
ksort($this->tables);
|
||||||
return $this->tables;
|
return $this->tables;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if one of the migrations files' dependencies can't be resolved
|
||||||
|
* by the supplied list of migrations
|
||||||
|
*
|
||||||
|
* @throws UnexpectedValueException If a dependency can't be resolved
|
||||||
|
*/
|
||||||
|
protected function check_dependencies()
|
||||||
|
{
|
||||||
|
// Strip duplicate values from array
|
||||||
|
$this->dependencies = array_unique($this->dependencies);
|
||||||
|
|
||||||
|
foreach ($this->dependencies as $dependency)
|
||||||
|
{
|
||||||
|
if (!in_array($dependency, $this->class_names))
|
||||||
|
{
|
||||||
|
throw new \UnexpectedValueException("Unable to resolve the dependency '$dependency'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
49
tests/migrator/schema_generator_test.php
Normal file
49
tests/migrator/schema_generator_test.php
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) 2014 phpBB Group
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class schmema_generator_test extends phpbb_test_case
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->config = new \phpbb\config\config(array());
|
||||||
|
$this->db = new \phpbb\db\driver\sqlite();
|
||||||
|
$this->db_tools = new \phpbb\db\tools($this->db);
|
||||||
|
$this->table_prefix = 'phpbb_';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function get_schema_generator(array $class_names)
|
||||||
|
{
|
||||||
|
$this->generator = new \phpbb\db\migration\schema_generator($class_names, $this->config, $this->db, $this->db_tools, $this->phpbb_root_path, $this->php_ext, $this->table_prefix);
|
||||||
|
|
||||||
|
return $this->generator;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @expectedException \UnexpectedValueException
|
||||||
|
*/
|
||||||
|
public function test_check_dependencies_fail()
|
||||||
|
{
|
||||||
|
$this->get_schema_generator(array('\phpbb\db\migration\data\v310\forgot_password'));
|
||||||
|
|
||||||
|
$this->generator->get_schema();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_get_schema_success()
|
||||||
|
{
|
||||||
|
$this->get_schema_generator(array(
|
||||||
|
'\phpbb\db\migration\data\v30x\release_3_0_1_rc1',
|
||||||
|
'\phpbb\db\migration\data\v30x\release_3_0_0',
|
||||||
|
'\phpbb\db\migration\data\v310\boardindex'
|
||||||
|
));
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('phpbb_users', $this->generator->get_schema());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue