fix(tests): Adjust the migrator test

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-07-03 13:48:58 +02:00
parent 8153c38efe
commit fc383a323f
No known key found for this signature in database
GPG key ID: 74434EFE0D2E2205

View file

@ -17,6 +17,8 @@ use Doctrine\DBAL\Schema\SchemaConfig;
use OC\DB\Migrator;
use OC\DB\OracleMigrator;
use OC\DB\SQLiteMigrator;
use OC\DB\TDoctrineParameterTypeMap;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IConfig;
use OCP\Security\ISecureRandom;
@ -29,6 +31,8 @@ use OCP\Security\ISecureRandom;
* @package Test\DB
*/
class MigratorTest extends \Test\TestCase {
use TDoctrineParameterTypeMap;
/**
* @var \Doctrine\DBAL\Connection $connection
*/
@ -74,12 +78,12 @@ class MigratorTest extends \Test\TestCase {
protected function tearDown(): void {
// Try to delete if exists (IF EXISTS NOT SUPPORTED IN ORACLE)
try {
$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp));
$this->connection->executeStatement('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableNameTmp));
} catch (Exception $e) {
}
try {
$this->connection->exec('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName));
$this->connection->executeStatement('DROP TABLE ' . $this->connection->quoteIdentifier($this->tableName));
} catch (Exception $e) {
}
parent::tearDown();
@ -267,28 +271,28 @@ class MigratorTest extends \Test\TestCase {
public function dataNotNullEmptyValuesFailOracle(): array {
return [
[ParameterType::BOOLEAN, true, Types::BOOLEAN, false],
[ParameterType::BOOLEAN, false, Types::BOOLEAN, true],
[IQueryBuilder::PARAM_BOOL, true, Types::BOOLEAN, false],
[IQueryBuilder::PARAM_BOOL, false, Types::BOOLEAN, true],
[ParameterType::STRING, 'foo', Types::STRING, false],
[ParameterType::STRING, '', Types::STRING, true],
[IQueryBuilder::PARAM_STR, 'foo', Types::STRING, false],
[IQueryBuilder::PARAM_STR, '', Types::STRING, true],
[ParameterType::INTEGER, 1234, Types::INTEGER, false],
[ParameterType::INTEGER, 0, Types::INTEGER, false], // Integer 0 is not stored as Null and therefor works
[IQueryBuilder::PARAM_INT, 1234, Types::INTEGER, false],
[IQueryBuilder::PARAM_INT, 0, Types::INTEGER, false], // Integer 0 is not stored as Null and therefor works
[ParameterType::STRING, '{"a": 2}', Types::JSON, false],
[IQueryBuilder::PARAM_JSON, '{"a": 2}', Types::JSON, false],
];
}
/**
* @dataProvider dataNotNullEmptyValuesFailOracle
*
* @param int $parameterType
* @param int|string $parameterType
* @param bool|int|string $value
* @param string $columnType
* @param bool $oracleThrows
*/
public function testNotNullEmptyValuesFailOracle(int $parameterType, $value, string $columnType, bool $oracleThrows): void {
public function testNotNullEmptyValuesFailOracle(int|string $parameterType, bool|int|string $value, string $columnType, bool $oracleThrows): void {
$startSchema = new Schema([], [], $this->getSchemaConfig());
$table = $startSchema->createTable($this->tableName);
$table->addColumn('id', Types::BIGINT);
@ -308,7 +312,7 @@ class MigratorTest extends \Test\TestCase {
$this->connection->insert(
$this->tableName,
['id' => 1, 'will_it_blend' => $value],
['id' => ParameterType::INTEGER, 'will_it_blend' => $parameterType],
['id' => ParameterType::INTEGER, 'will_it_blend' => $this->convertParameterTypeToDoctrine($parameterType)],
);
$this->addToAssertionCount(1);