fix tests

This commit is contained in:
Dennis Eichhorn 2024-05-18 00:12:37 +00:00
parent 0cb183c1df
commit e78031906e
4 changed files with 28 additions and 14 deletions

View File

@ -54,8 +54,14 @@ final class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
'from' => null, 'from' => null,
'element' => null, 'element' => null,
'component' => null, 'component' => null,
'permission' => PermissionType::NONE,
'category' => null, 'category' => null,
'hasRead' => false,
'hasModify' => false,
'hasCreate' => false,
'hasDelete' => false,
'hasPermission' => false,
'defaultCPermissions' => null,
'defaultPPermissions' => null,
], ],
$perm->jsonSerialize() $perm->jsonSerialize()
); );

View File

@ -45,7 +45,7 @@ final class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf( self::assertInstanceOf(
\phpOMS\DataStorage\Cache\Connection\MemCached::class, \phpOMS\DataStorage\Cache\Connection\MemCached::class,
ConnectionFactory::create(['type' => CacheType::MEMCACHED, 'data' => $GLOBALS['CONFIG']['cache']['memcached']]) ConnectionFactory::create(\array_merge(['type' => CacheType::MEMCACHED], $GLOBALS['CONFIG']['cache']['memcached']))
); );
} }
@ -61,7 +61,7 @@ final class ConnectionFactoryTest extends \PHPUnit\Framework\TestCase
self::assertInstanceOf( self::assertInstanceOf(
\phpOMS\DataStorage\Cache\Connection\RedisCache::class, \phpOMS\DataStorage\Cache\Connection\RedisCache::class,
ConnectionFactory::create(['type' => CacheType::REDIS, 'data' => $GLOBALS['CONFIG']['cache']['redis']]) ConnectionFactory::create(\array_merge(['type' => CacheType::REDIS], $GLOBALS['CONFIG']['cache']['redis']))
); );
} }

View File

@ -102,9 +102,9 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
$sql = ''; $sql = '';
if ($con instanceof MysqlConnection) { if ($con instanceof MysqlConnection) {
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';'; $sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = ?;';
} elseif ($con instanceof PostgresConnection) { } elseif ($con instanceof PostgresConnection) {
$sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\';'; $sql = 'SELECT [table_name] FROM [information_schema].[tables] WHERE [table_schema] = ?;';
} elseif ($con instanceof SqlServerConnection) { } elseif ($con instanceof SqlServerConnection) {
$sql = 'SELECT [table_name] FROM [sys].[tables] INNER JOIN [sys].[schemas] ON [sys].[tables.schema_id] = [sys].[schemas.schema_id];'; $sql = 'SELECT [table_name] FROM [sys].[tables] INNER JOIN [sys].[schemas] ON [sys].[tables.schema_id] = [sys].[schemas.schema_id];';
} elseif ($con instanceof SQLiteConnection) { } elseif ($con instanceof SQLiteConnection) {
@ -133,13 +133,13 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
$sql = ''; $sql = '';
if ($con instanceof MysqlConnection) { if ($con instanceof MysqlConnection) {
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';'; $sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = ? AND [table_name] = ?;';
} elseif ($con instanceof PostgresConnection) { } elseif ($con instanceof PostgresConnection) {
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';'; $sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = ? AND [table_name] = ?;';
} elseif ($con instanceof SqlServerConnection) { } elseif ($con instanceof SqlServerConnection) {
$sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = \'' . $GLOBALS['CONFIG']['db']['core']['masters']['admin']['database']. '\' AND [table_name] = \'test\';'; $sql = 'SELECT * FROM [information_schema].[columns] WHERE [table_schema] = ? AND [table_name] = ?;';
} elseif ($con instanceof SQLiteConnection) { } elseif ($con instanceof SQLiteConnection) {
$sql = 'SELECT * FROM pragma_table_info(\'test\') WHERE pragma_table_info(\'test\') = \'test\';'; $sql = 'SELECT * FROM pragma_table_info(?) WHERE pragma_table_info(?) = ?;';
} }
$sql = \strtr($sql, '[]', $iS . $iE); $sql = \strtr($sql, '[]', $iS . $iE);
@ -164,13 +164,13 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
$sql = ''; $sql = '';
if ($con instanceof MysqlConnection) { if ($con instanceof MysqlConnection) {
$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 = 'CREATE TABLE IF NOT EXISTS [user_roles] ([user_id] INT AUTO_INCREMENT, [role_id] VARCHAR(10) DEFAULT ? 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;';
} elseif ($con instanceof PostgresConnection) { } elseif ($con instanceof PostgresConnection) {
$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]));'; $sql = 'CREATE TABLE IF NOT EXISTS [user_roles] ([user_id] INT AUTO_INCREMENT, [role_id] VARCHAR(10) DEFAULT ? NULL, PRIMARY KEY ([user_id]), FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));';
} elseif ($con instanceof SqlServerConnection) { } elseif ($con instanceof SqlServerConnection) {
$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]));'; $sql = 'CREATE TABLE IF NOT EXISTS [user_roles] ([user_id] INT AUTO_INCREMENT, [role_id] VARCHAR(10) DEFAULT ? NULL, PRIMARY KEY ([user_id]), FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));';
} elseif ($con instanceof SQLiteConnection) { } elseif ($con instanceof SQLiteConnection) {
$sql = 'CREATE TABLE [user_roles] ([user_id] INTEGER AUTOINCREMENT PRIMARY KEY, [role_id] TEXT DEFAULT \'1\' NULL, FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));'; $sql = 'CREATE TABLE [user_roles] ([user_id] INTEGER AUTOINCREMENT PRIMARY KEY, [role_id] TEXT DEFAULT ? NULL, FOREIGN KEY ([user_id]) REFERENCES [users] ([ext1_id]), FOREIGN KEY ([role_id]) REFERENCES [roles] ([ext2_id]));';
} }
$sql = \strtr($sql, '[]', $iS . $iE); $sql = \strtr($sql, '[]', $iS . $iE);
@ -196,7 +196,7 @@ final class BuilderTest extends \PHPUnit\Framework\TestCase
$iE = $con->getGrammar()->systemIdentifierEnd; $iE = $con->getGrammar()->systemIdentifierEnd;
$query = new Builder($con); $query = new Builder($con);
$sql = 'CREATE TABLE IF NOT EXISTS user_roles (user_id INT NOT NULL 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 = 'CREATE TABLE IF NOT EXISTS user_roles (user_id INT NOT NULL AUTO_INCREMENT, role_id VARCHAR(10) DEFAULT ? 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); $sql = \strtr($sql, '[]', $iS . $iE);
self::assertEquals( self::assertEquals(
$sql, $sql,

View File

@ -46,6 +46,8 @@ final class LocationTest extends \PHPUnit\Framework\TestCase
'state' => '', 'state' => '',
'lat' => 0.0, 'lat' => 0.0,
'lon' => 0.0, 'lon' => 0.0,
'id' => 0,
'type' => 2,
]; ];
self::assertEquals('', $this->location->postal); self::assertEquals('', $this->location->postal);
@ -111,6 +113,8 @@ final class LocationTest extends \PHPUnit\Framework\TestCase
'state' => 'This is a state 123', 'state' => 'This is a state 123',
'lat' => 12.1, 'lat' => 12.1,
'lon' => 11.2, 'lon' => 11.2,
'id' => 0,
'type' => 2,
]; ];
$this->location->postal = '0123456789'; $this->location->postal = '0123456789';
@ -137,6 +141,8 @@ final class LocationTest extends \PHPUnit\Framework\TestCase
'state' => 'This is a state 123', 'state' => 'This is a state 123',
'lat' => 12.1, 'lat' => 12.1,
'lon' => 11.2, 'lon' => 11.2,
'id' => 0,
'type' => 2,
]; ];
$this->location->postal = '0123456789'; $this->location->postal = '0123456789';
@ -164,6 +170,8 @@ final class LocationTest extends \PHPUnit\Framework\TestCase
'state' => 'This is a state 123', 'state' => 'This is a state 123',
'lat' => 12.1, 'lat' => 12.1,
'lon' => 11.2, 'lon' => 11.2,
'id' => 0,
'type' => 2,
]; ];
$this->location->unserialize(\json_encode($expected)); $this->location->unserialize(\json_encode($expected));