mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-13 18:48:40 +00:00
remove db prefix
This commit is contained in:
parent
1fdb93968a
commit
b2f17234fa
84
Algorithm/Graph/DependencyResolver.php
Normal file
84
Algorithm/Graph/DependencyResolver.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Graph;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Graph;
|
||||
|
||||
/**
|
||||
* Dependency resolver class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Graph;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class DependencyResolver
|
||||
{
|
||||
/**
|
||||
* Resolve dependencies
|
||||
*
|
||||
* @param array $graph Graph to resolve
|
||||
*
|
||||
* @return null|array
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function resolve(array $graph) : ?array
|
||||
{
|
||||
$resolved = [];
|
||||
$unresolved = [];
|
||||
foreach ($graph as $table => $dependency) {
|
||||
self::dependencyResolve($table, $graph, $resolved, $unresolved);
|
||||
}
|
||||
|
||||
return !empty($unresolved) ? null : $resolved;
|
||||
}
|
||||
|
||||
/**
|
||||
* Algorithm to resolve dependencies
|
||||
*
|
||||
* @param int|string $item Item id
|
||||
* @param array<int|string, array> $items All items
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function dependencyResolve($item, array $items, array &$resolved, array &$unresolved) : void
|
||||
{
|
||||
$unresolved[] = $item;
|
||||
|
||||
if (!isset($items[$item])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($items[$item] as $dependency) {
|
||||
if (!\in_array($dependency, $unresolved)) {
|
||||
$unresolved[] = $dependency;
|
||||
self::dependencyResolve($dependency, $items, $resolved, $unresolved);
|
||||
} else {
|
||||
continue; // circular dependency
|
||||
}
|
||||
}
|
||||
|
||||
if (!\in_array($item, $resolved)) {
|
||||
$resolved[] = $item;
|
||||
}
|
||||
|
||||
foreach ($unresolved as $key => $unres) {
|
||||
if ($unres === $item) {
|
||||
unset($unresolved[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,14 +48,12 @@ abstract class InstallerAbstract
|
|||
public static function registerInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$queryModule = new Builder($dbPool->get('insert'));
|
||||
$queryModule->prefix($dbPool->get('insert')->prefix);
|
||||
$queryModule->insert('module_id', 'module_theme', 'module_path', 'module_active', 'module_version')
|
||||
->into('module')
|
||||
->values($info->getInternalName(), 'Default', $info->getDirectory(), 0, $info->getVersion())
|
||||
->execute();
|
||||
|
||||
$queryLoad = new Builder($dbPool->get('insert'));
|
||||
$queryLoad->prefix($dbPool->get('insert')->prefix);
|
||||
$queryLoad->insert('module_load_pid', 'module_load_type', 'module_load_from', 'module_load_for', 'module_load_file')
|
||||
->into('module_load');
|
||||
|
||||
|
|
|
|||
|
|
@ -165,7 +165,6 @@ final class ModuleManager
|
|||
$uriHash = $request->getHash();
|
||||
|
||||
$query = new Builder($this->app->dbPool->get('select'));
|
||||
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||
$sth = $query->select('module_load.module_load_type', 'module_load.*')
|
||||
->from('module_load')
|
||||
->innerJoin('module')->on('module_load.module_load_from', '=', 'module.module_id')->orOn('module_load.module_load_for', '=', 'module.module_id')
|
||||
|
|
@ -192,7 +191,6 @@ final class ModuleManager
|
|||
{
|
||||
if (empty($this->active) || !$useCache) {
|
||||
$query = new Builder($this->app->dbPool->get('select'));
|
||||
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||
$sth = $query->select('module.module_path')
|
||||
->from('module')
|
||||
->where('module.module_active', '=', 1)
|
||||
|
|
@ -310,7 +308,6 @@ final class ModuleManager
|
|||
{
|
||||
if (empty($this->installed) || !$useCache) {
|
||||
$query = new Builder($this->app->dbPool->get('select'));
|
||||
$query->prefix($this->app->dbPool->get('select')->prefix);
|
||||
$sth = $query->select('module.module_path')
|
||||
->from('module')
|
||||
->execute();
|
||||
|
|
|
|||
|
|
@ -76,7 +76,6 @@ abstract class StatusAbstract
|
|||
public static function activateInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$query = new Builder($dbPool->get('update'));
|
||||
$query->prefix($dbPool->get('update')->prefix);
|
||||
$query->update('module')
|
||||
->sets('module.module_active', 1)
|
||||
->where('module.module_id', '=', $info->getInternalName())
|
||||
|
|
@ -130,7 +129,6 @@ abstract class StatusAbstract
|
|||
public static function deactivateInDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$query = new Builder($dbPool->get('update'));
|
||||
$query->prefix($dbPool->get('update')->prefix);
|
||||
$query->update('module')
|
||||
->sets('module.module_active', 0)
|
||||
->where('module.module_id', '=', $info->getInternalName())
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ abstract class UninstallerAbstract
|
|||
$definitions = \json_decode($content, true);
|
||||
|
||||
$builder = new SchemaBuilder($dbPool->get('schema'));
|
||||
$builder->prefix($dbPool->get('schema')->prefix);
|
||||
|
||||
foreach ($definitions as $definition) {
|
||||
$builder->dropTable($definition['table'] ?? '');
|
||||
|
|
@ -96,14 +95,12 @@ abstract class UninstallerAbstract
|
|||
public static function unregisterFromDatabase(DatabasePool $dbPool, ModuleInfo $info) : void
|
||||
{
|
||||
$queryLoad = new Builder($dbPool->get('delete'));
|
||||
$queryLoad->prefix($dbPool->get('delete')->prefix);
|
||||
$queryLoad->delete()
|
||||
->from('module_load')
|
||||
->where('module_load_from', '=', $info->getInternalName())
|
||||
->execute();
|
||||
|
||||
$queryModule = new Builder($dbPool->get('delete'));
|
||||
$queryModule->prefix($dbPool->get('delete')->prefix);
|
||||
$queryModule->delete()
|
||||
->from('module')
|
||||
->where('module_id', '=', $info->getInternalName())
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'insert' => [
|
||||
|
|
@ -38,7 +37,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'select' => [
|
||||
|
|
@ -48,7 +46,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'update' => [
|
||||
|
|
@ -58,7 +55,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'delete' => [
|
||||
|
|
@ -68,7 +64,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'schema' => [
|
||||
|
|
@ -78,7 +73,6 @@ $CONFIG = [
|
|||
'login' => 'root', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
],
|
||||
|
|
@ -90,7 +84,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'insert' => [
|
||||
|
|
@ -100,7 +93,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'select' => [
|
||||
|
|
@ -110,7 +102,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'update' => [
|
||||
|
|
@ -120,7 +111,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'delete' => [
|
||||
|
|
@ -130,7 +120,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'schema' => [
|
||||
|
|
@ -140,7 +129,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
],
|
||||
|
|
@ -148,37 +136,31 @@ $CONFIG = [
|
|||
'admin' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'insert' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'select' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'update' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'delete' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'schema' => [
|
||||
'db' => 'sqlite', /* db type */
|
||||
'database' => __DIR__ . '/test.sqlite', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
],
|
||||
|
|
@ -190,7 +172,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'insert' => [
|
||||
|
|
@ -200,7 +181,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'select' => [
|
||||
|
|
@ -210,7 +190,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'update' => [
|
||||
|
|
@ -220,7 +199,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'delete' => [
|
||||
|
|
@ -230,7 +208,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
'schema' => [
|
||||
|
|
@ -240,7 +217,6 @@ $CONFIG = [
|
|||
'login' => 'postgres', /* db login name */
|
||||
'password' => 'root', /* db login password */
|
||||
'database' => 'oms', /* db name */
|
||||
'prefix' => 'oms_', /* db table prefix */
|
||||
'weight' => 1000, /* db table prefix */
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ class FileCacheTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals('', $this->cache->getPrefix());
|
||||
self::assertEquals(CacheType::FILE, $this->cache->getType());
|
||||
self::assertTrue(\is_dir(__DIR__ . '/Cache'));
|
||||
self::assertTrue($this->cache->flushAll());
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ class MemCachedTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals('', $this->cache->getPrefix());
|
||||
self::assertEquals(CacheType::MEMCACHED, $this->cache->getType());
|
||||
self::assertTrue($this->cache->flushAll());
|
||||
self::assertEquals(0, $this->cache->getThreshold());
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class NullCacheTest extends \PHPUnit\Framework\TestCase
|
|||
$cache = new NullCache();
|
||||
$cache->connect([]);
|
||||
|
||||
self::assertEquals('', $cache->getPrefix());
|
||||
self::assertEquals(CacheType::UNDEFINED, $cache->getType());
|
||||
self::assertTrue($cache->add(1, 1));
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ class RedisCacheTest extends \PHPUnit\Framework\TestCase
|
|||
*/
|
||||
public function testDefault() : void
|
||||
{
|
||||
self::assertEquals('', $this->cache->getPrefix());
|
||||
self::assertEquals(CacheType::REDIS, $this->cache->getType());
|
||||
self::assertTrue($this->cache->flushAll());
|
||||
self::assertEquals(0, $this->cache->getThreshold());
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_base` (
|
||||
'CREATE TABLE `test_base` (
|
||||
`test_base_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_base_string` varchar(254) NOT NULL,
|
||||
`test_base_int` int(11) NOT NULL,
|
||||
|
|
@ -97,7 +97,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_belongs_to_one` (
|
||||
'CREATE TABLE `test_belongs_to_one` (
|
||||
`test_belongs_to_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_belongs_to_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_belongs_to_one_id`)
|
||||
|
|
@ -105,7 +105,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_owns_one` (
|
||||
'CREATE TABLE `test_owns_one` (
|
||||
`test_owns_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_owns_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_owns_one_id`)
|
||||
|
|
@ -113,7 +113,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_direct` (
|
||||
'CREATE TABLE `test_has_many_direct` (
|
||||
`test_has_many_direct_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_direct_string` varchar(254) NOT NULL,
|
||||
`test_has_many_direct_to` int(11) NOT NULL,
|
||||
|
|
@ -122,7 +122,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel` (
|
||||
'CREATE TABLE `test_has_many_rel` (
|
||||
`test_has_many_rel_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_has_many_rel_id`)
|
||||
|
|
@ -130,7 +130,7 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel_relations` (
|
||||
'CREATE TABLE `test_has_many_rel_relations` (
|
||||
`test_has_many_rel_relations_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_relations_src` int(11) NOT NULL,
|
||||
`test_has_many_rel_relations_dest` int(11) NOT NULL,
|
||||
|
|
@ -141,12 +141,12 @@ class DataMapperAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
protected function tearDown() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_owns_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel_relations')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,17 +31,5 @@ class GrammarTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$grammar = new Grammar();
|
||||
self::assertEquals('Y-m-d H:i:s', $grammar->getDateFormat());
|
||||
self::assertEquals('', $grammar->getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar can define a default table prefix and return this value
|
||||
* @group framework
|
||||
*/
|
||||
public function testPrefixInputOutput() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
$grammar->setTablePrefix('oms_');
|
||||
self::assertEquals('oms_', $grammar->getTablePrefix());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,5 @@ class GrammarTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$grammar = new Grammar();
|
||||
self::assertEquals('Y-m-d H:i:s', $grammar->getDateFormat());
|
||||
self::assertEquals('', $grammar->getTablePrefix());
|
||||
}
|
||||
|
||||
/**
|
||||
* @testdox The grammar can define a default table prefix and return this value
|
||||
* @group framework
|
||||
*/
|
||||
public function testPrefixInputOutput() : void
|
||||
{
|
||||
$grammar = new Grammar();
|
||||
$grammar->setTablePrefix('oms_');
|
||||
self::assertEquals('oms_', $grammar->getTablePrefix());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,12 +58,12 @@ class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
|
|||
}
|
||||
|
||||
$table = new SchemaBuilder($this->con);
|
||||
$tables = $table->prefix($this->con->prefix)->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
self::assertContains($this->con->prefix . 'test', $tables);
|
||||
self::assertContains($this->con->prefix . 'test_foreign', $tables);
|
||||
$tables = $table->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
self::assertContains('test', $tables);
|
||||
self::assertContains('test_foreign', $tables);
|
||||
|
||||
$field = new SchemaBuilder($this->con);
|
||||
$fields = $field->prefix($this->con->prefix)->selectFields('test')->execute()->fetchAll();
|
||||
$fields = $field->selectFields('test')->execute()->fetchAll();
|
||||
|
||||
foreach ($definitions['test']['fields'] as $key => $field) {
|
||||
self::assertTrue(
|
||||
|
|
@ -81,14 +81,14 @@ class MysqlGrammarTest extends \PHPUnit\Framework\TestCase
|
|||
public function testDelete() : void
|
||||
{
|
||||
$table = new SchemaBuilder($this->con);
|
||||
$tables = $table->prefix($this->con->prefix)->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
$tables = $table->selectTables()->execute()->fetchAll(\PDO::FETCH_COLUMN);
|
||||
|
||||
$delete = new SchemaBuilder($this->con);
|
||||
$delete->prefix($this->con->prefix)->dropTable('test')->execute();
|
||||
$delete->prefix($this->con->prefix)->dropTable('test_foreign')->execute();
|
||||
$delete->dropTable('test')->execute();
|
||||
$delete->dropTable('test_foreign')->execute();
|
||||
|
||||
$tables = $table->prefix($this->con->prefix)->selectTables()->execute()->fetchAll();
|
||||
self::assertNotContains($this->con->prefix . 'test', $tables);
|
||||
self::assertNotContains($this->con->prefix . 'test_foreign', $tables);
|
||||
$tables = $table->selectTables()->execute()->fetchAll();
|
||||
self::assertNotContains('test', $tables);
|
||||
self::assertNotContains('test_foreign', $tables);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SchemaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
protected function setUp() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_base` (
|
||||
'CREATE TABLE `test_base` (
|
||||
`test_base_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_base_string` varchar(254) NOT NULL,
|
||||
`test_base_int` int(11) NOT NULL,
|
||||
|
|
@ -43,7 +43,7 @@ class SchemaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_belongs_to_one` (
|
||||
'CREATE TABLE `test_belongs_to_one` (
|
||||
`test_belongs_to_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_belongs_to_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_belongs_to_one_id`)
|
||||
|
|
@ -53,8 +53,8 @@ class SchemaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
protected function tearDown() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_one')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -66,8 +66,8 @@ class SchemaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
$schema = new SchemaMapper($GLOBALS['dbpool']->get());
|
||||
|
||||
self::assertTrue(\in_array('oms_test_base', $schema->getTables()));
|
||||
self::assertTrue(\in_array('oms_test_belongs_to_one', $schema->getTables()));
|
||||
self::assertTrue(\in_array('test_base', $schema->getTables()));
|
||||
self::assertTrue(\in_array('test_belongs_to_one', $schema->getTables()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,7 +81,7 @@ class SchemaMapperTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertEquals(
|
||||
12,
|
||||
\count($schema->getFields('oms_test_base'))
|
||||
\count($schema->getFields('test_base'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
private function dbSetup() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_base` (
|
||||
'CREATE TABLE `test_base` (
|
||||
`test_base_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_base_string` varchar(254) NOT NULL,
|
||||
`test_base_int` int(11) NOT NULL,
|
||||
|
|
@ -231,7 +231,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_belongs_to_one` (
|
||||
'CREATE TABLE `test_belongs_to_one` (
|
||||
`test_belongs_to_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_belongs_to_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_belongs_to_one_id`)
|
||||
|
|
@ -239,7 +239,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_owns_one` (
|
||||
'CREATE TABLE `test_owns_one` (
|
||||
`test_owns_one_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_owns_one_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_owns_one_id`)
|
||||
|
|
@ -247,7 +247,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_direct` (
|
||||
'CREATE TABLE `test_has_many_direct` (
|
||||
`test_has_many_direct_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_direct_string` varchar(254) NOT NULL,
|
||||
`test_has_many_direct_to` int(11) NOT NULL,
|
||||
|
|
@ -256,7 +256,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel` (
|
||||
'CREATE TABLE `test_has_many_rel` (
|
||||
`test_has_many_rel_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_string` varchar(254) NOT NULL,
|
||||
PRIMARY KEY (`test_has_many_rel_id`)
|
||||
|
|
@ -264,7 +264,7 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
)->execute();
|
||||
|
||||
$GLOBALS['dbpool']->get()->con->prepare(
|
||||
'CREATE TABLE `oms_test_has_many_rel_relations` (
|
||||
'CREATE TABLE `test_has_many_rel_relations` (
|
||||
`test_has_many_rel_relations_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`test_has_many_rel_relations_src` int(11) NOT NULL,
|
||||
`test_has_many_rel_relations_dest` int(11) NOT NULL,
|
||||
|
|
@ -275,12 +275,12 @@ class ModuleAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
private function dbTeardown() : void
|
||||
{
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_owns_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE oms_test_has_many_rel_relations')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_base')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_belongs_to_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_owns_one')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_direct')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel')->execute();
|
||||
$GLOBALS['dbpool']->get()->con->prepare('DROP TABLE test_has_many_rel_relations')->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user