mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-20 13:28:42 +00:00
test fixes
This commit is contained in:
parent
5d2ff0aa47
commit
37db31e85f
|
|
@ -67,4 +67,58 @@ class PostgresGrammar extends Grammar
|
|||
|
||||
return \rtrim($builder->toSql(), ';');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile create table fields query.
|
||||
*
|
||||
* @param SchemaBuilder $query Query
|
||||
* @param array $fields Fields to create
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function compileCreateFields(SchemaBuilder $query, array $fields) : string
|
||||
{
|
||||
$fieldQuery = '';
|
||||
$keys = '';
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name]) . ' ' . $field['type'];
|
||||
|
||||
if (isset($field['default']) || ($field['default'] === null && ($field['null'] ?? false))) {
|
||||
$fieldQuery .= ' DEFAULT ' . $this->compileValue($query, $field['default']);
|
||||
}
|
||||
|
||||
if ($field['null'] ?? false) {
|
||||
$fieldQuery .= ' ' . ($field['null'] ? '' : 'NOT ') . 'NULL';
|
||||
}
|
||||
|
||||
if ($field['autoincrement'] ?? false) {
|
||||
$fieldQuery .= ' AUTO_INCREMENT';
|
||||
}
|
||||
|
||||
$fieldQuery .= ',';
|
||||
|
||||
if ($field['primary'] ?? false) {
|
||||
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if ($field['unique'] ?? false) {
|
||||
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['foreignTable'], $field['foreignKey'])) {
|
||||
$keys .= ' FOREIGN KEY (' . $this->expressionizeTableColumn([$name]) . ') REFERENCES '
|
||||
. $this->expressionizeTableColumn([$field['foreignTable']])
|
||||
. ' (' . $this->expressionizeTableColumn([$field['foreignKey']]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['meta']['multi_autoincrement'])) {
|
||||
$query->hasPostQuery = true;
|
||||
}
|
||||
}
|
||||
|
||||
return '(' . \ltrim(\rtrim($fieldQuery . $keys, ','), ' ') . ')';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,8 +78,62 @@ class SQLiteGrammar extends Grammar
|
|||
$builder = new Builder($query->getConnection());
|
||||
$builder->select('*')
|
||||
->from('pragma_table_info(\'' . $table . '\')')
|
||||
->where('pragma_table_info(\'' . $table . '\')', '=', $query->getConnection()->getDatabase());
|
||||
->where('pragma_table_info(\'' . $table . '\')', '=', $table);
|
||||
|
||||
return \rtrim($builder->toSql(), ';');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile create table fields query.
|
||||
*
|
||||
* @param SchemaBuilder $query Query
|
||||
* @param array $fields Fields to create
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function compileCreateFields(SchemaBuilder $query, array $fields) : string
|
||||
{
|
||||
$fieldQuery = '';
|
||||
$keys = '';
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name]) . ' ' . $field['type'];
|
||||
|
||||
if (isset($field['default']) || ($field['default'] === null && ($field['null'] ?? false))) {
|
||||
$fieldQuery .= ' DEFAULT ' . $this->compileValue($query, $field['default']);
|
||||
}
|
||||
|
||||
if ($field['null'] ?? false) {
|
||||
$fieldQuery .= ' ' . ($field['null'] ? '' : 'NOT ') . 'NULL';
|
||||
}
|
||||
|
||||
if ($field['autoincrement'] ?? false) {
|
||||
$fieldQuery .= ' AUTO_INCREMENT';
|
||||
}
|
||||
|
||||
$fieldQuery .= ',';
|
||||
|
||||
if ($field['primary'] ?? false) {
|
||||
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if ($field['unique'] ?? false) {
|
||||
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['foreignTable'], $field['foreignKey'])) {
|
||||
$keys .= ' FOREIGN KEY (' . $this->expressionizeTableColumn([$name]) . ') REFERENCES '
|
||||
. $this->expressionizeTableColumn([$field['foreignTable']])
|
||||
. ' (' . $this->expressionizeTableColumn([$field['foreignKey']]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['meta']['multi_autoincrement'])) {
|
||||
$query->hasPostQuery = true;
|
||||
}
|
||||
}
|
||||
|
||||
return '(' . \ltrim(\rtrim($fieldQuery . $keys, ','), ' ') . ')';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,4 +84,58 @@ class SqlServerGrammar extends Grammar
|
|||
|
||||
return \rtrim($builder->toSql(), ';');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile create table fields query.
|
||||
*
|
||||
* @param SchemaBuilder $query Query
|
||||
* @param array $fields Fields to create
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function compileCreateFields(SchemaBuilder $query, array $fields) : string
|
||||
{
|
||||
$fieldQuery = '';
|
||||
$keys = '';
|
||||
|
||||
foreach ($fields as $name => $field) {
|
||||
$fieldQuery .= ' ' . $this->expressionizeTableColumn([$name]) . ' ' . $field['type'];
|
||||
|
||||
if (isset($field['default']) || ($field['default'] === null && ($field['null'] ?? false))) {
|
||||
$fieldQuery .= ' DEFAULT ' . $this->compileValue($query, $field['default']);
|
||||
}
|
||||
|
||||
if ($field['null'] ?? false) {
|
||||
$fieldQuery .= ' ' . ($field['null'] ? '' : 'NOT ') . 'NULL';
|
||||
}
|
||||
|
||||
if ($field['autoincrement'] ?? false) {
|
||||
$fieldQuery .= ' AUTO_INCREMENT';
|
||||
}
|
||||
|
||||
$fieldQuery .= ',';
|
||||
|
||||
if ($field['primary'] ?? false) {
|
||||
$keys .= ' PRIMARY KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if ($field['unique'] ?? false) {
|
||||
$keys .= ' UNIQUE KEY (' . $this->expressionizeTableColumn([$name]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['foreignTable'], $field['foreignKey'])) {
|
||||
$keys .= ' FOREIGN KEY (' . $this->expressionizeTableColumn([$name]) . ') REFERENCES '
|
||||
. $this->expressionizeTableColumn([$field['foreignTable']])
|
||||
. ' (' . $this->expressionizeTableColumn([$field['foreignKey']]) . '),';
|
||||
}
|
||||
|
||||
if (isset($field['meta']['multi_autoincrement'])) {
|
||||
$query->hasPostQuery = true;
|
||||
}
|
||||
}
|
||||
|
||||
return '(' . \ltrim(\rtrim($fieldQuery . $keys, ','), ' ') . ')';
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ final class ForensicsTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEqualsWithDelta(0.249, $analysis[2], 0.01);
|
||||
self::assertEqualsWithDelta(0.164, $analysis[3], 0.01);
|
||||
self::assertEqualsWithDelta(0.102, $analysis[4], 0.01);
|
||||
self::assertEqualsWithDelta(0.102, $analysis[5], 0.01);
|
||||
self::assertEqualsWithDelta(0.073, $analysis[5], 0.01);
|
||||
self::assertEqualsWithDelta(0.059, $analysis[6], 0.01);
|
||||
self::assertEqualsWithDelta(0.044, $analysis[7], 0.01);
|
||||
self::assertEqualsWithDelta(0.032, $analysis[8], 0.01);
|
||||
|
|
|
|||
|
|
@ -105,8 +105,19 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$iE = $con->getGrammar()->systemIdentifierEnd;
|
||||
|
||||
$query = new Builder($con);
|
||||
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';';
|
||||
$sql = \strtr($sql, '[]', $iS . $iE);
|
||||
|
||||
$sql = '';
|
||||
if ($con instanceof MysqlConnection) {
|
||||
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';';
|
||||
} elseif ($con instanceof PostgresConnection) {
|
||||
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';';
|
||||
} elseif ($con instanceof SqlServerConnection) {
|
||||
$sql = 'SELECT [table_name] FROM [sys].[tables] INNER JOIN [sys].[schemas] ON [sys].[tables.schema_id] = [sys].[schemas.schema_id];';
|
||||
} elseif ($con instanceof SQLiteConnection) {
|
||||
$sql = 'SELECT `name` FROM `sqlite_master` WHERE `type` = \'table\';';
|
||||
}
|
||||
|
||||
$sql = \strtr($sql, '[]', $iS . $iE);
|
||||
self::assertEquals($sql, $query->selectTables()->toSql());
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +138,19 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$iE = $con->getGrammar()->systemIdentifierEnd;
|
||||
|
||||
$query = new Builder($con);
|
||||
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND table_name = \'test\';';
|
||||
|
||||
$sql = '';
|
||||
if ($con instanceof MysqlConnection) {
|
||||
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';';
|
||||
} elseif ($con instanceof PostgresConnection) {
|
||||
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';';
|
||||
} elseif ($con instanceof SqlServerConnection) {
|
||||
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';';
|
||||
} elseif ($con instanceof SQLiteConnection) {
|
||||
$sql = 'SELECT * FROM pragma_table_info(\'test\') WHERE pragma_table_info(\'test\') = \'test\';';
|
||||
}
|
||||
|
||||
$sql = '';
|
||||
$sql = \strtr($sql, '[]', $iS . $iE);
|
||||
self::assertEquals($sql, $query->selectFields('test')->toSql());
|
||||
}
|
||||
|
|
@ -148,6 +171,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
|
|||
$iS = $con->getGrammar()->systemIdentifierStart;
|
||||
$iE = $con->getGrammar()->systemIdentifierEnd;
|
||||
|
||||
// @todo: fix, this is not correct for sqlite
|
||||
$query = new Builder($con);
|
||||
$sql = 'CREATE TABLE IF NOT EXISTS [user_roles] ([user_id] INT AUTO_INCREMENT, [role_id] VARCHAR(10) DEFAULT \'1\' NULL, PRIMARY KEY ([user_id]), FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id])) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AUTO_INCREMENT=1;';
|
||||
$sql = \strtr($sql, '[]', $iS . $iE);
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ final class ISO3166CharEnumTest extends \PHPUnit\Framework\TestCase
|
|||
'middle-east', 'south-america', 'north-america', 'central-asia',
|
||||
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
|
||||
'central-africa', 'east-africa', 'north-africa', 'south-africa',
|
||||
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
'west-africa', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
];
|
||||
|
||||
foreach ($regions as $region) {
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ final class ISO3166NameEnumTest extends \PHPUnit\Framework\TestCase
|
|||
'middle-east', 'south-america', 'north-america', 'central-asia',
|
||||
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
|
||||
'central-africa', 'east-africa', 'north-africa', 'south-africa',
|
||||
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
'west-africa', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
];
|
||||
|
||||
foreach ($regions as $region) {
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ final class ISO3166NumEnumTest extends \PHPUnit\Framework\TestCase
|
|||
'middle-east', 'south-america', 'north-america', 'central-asia',
|
||||
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
|
||||
'central-africa', 'east-africa', 'north-africa', 'south-africa',
|
||||
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
'west-africa', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
];
|
||||
|
||||
foreach ($regions as $region) {
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ final class ISO3166TwoEnumTest extends \PHPUnit\Framework\TestCase
|
|||
'middle-east', 'south-america', 'north-america', 'central-asia',
|
||||
'south-asia', 'southeast-asia', 'east-asia', 'west-asia',
|
||||
'central-africa', 'east-africa', 'north-africa', 'south-africa',
|
||||
'west-africe', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
'west-africa', 'australia', 'polynesia', 'melanesia', 'antarctica',
|
||||
];
|
||||
|
||||
foreach ($regions as $region) {
|
||||
|
|
|
|||
|
|
@ -174,8 +174,8 @@ final class ViewTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals('USD 1.235', $view->getCurrency(1.2345, 'USD', 'long'));
|
||||
|
||||
$this->app->l11nManager->loadLanguage('en', '0', ['0' => ['CurrencyK' => 'K']]);
|
||||
self::assertEquals('K$ 12.345', $view->getCurrency(12345.0, 'long', '$', 1000));
|
||||
self::assertEquals('KUSD 12.345', $view->getCurrency(12345.0, 'long', null, 1000));
|
||||
self::assertEquals('K$ 12.345', $view->getCurrency(12345.0, '$', 'long', 1000));
|
||||
self::assertEquals('KUSD 12.345', $view->getCurrency(12345.0, null, 'long', 1000));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user