Skip to content

Commit

Permalink
fixup! tests(DB): Add test for date time comparisons in query builder
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusknorr committed Jul 13, 2023
1 parent ab3cdcc commit 197d052
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@

namespace Test\DB\QueryBuilder;

use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\DBAL\Types\Types;
use OC\DB\QueryBuilder\Literal;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig;
use OCP\Server;
use Test\TestCase;

/**
Expand All @@ -31,13 +35,13 @@
class ExpressionBuilderDBTest extends TestCase {
/** @var \Doctrine\DBAL\Connection|\OCP\IDBConnection */
protected $connection;
protected $schemaSetup = false;

protected function setUp(): void {
parent::setUp();

$this->connection = \OC::$server->getDatabaseConnection();

$this->connection->getQueryBuilder()->delete('testing')->executeStatement();
$this->prepareTestingTable();
}

public function likeProvider() {
Expand Down Expand Up @@ -215,4 +219,31 @@ protected function createConfig($appId, $key, $value) {
])
->execute();
}

protected function prepareTestingTable(): void {
if ($this->schemaSetup) {
$this->connection->getQueryBuilder()->delete('testing')->executeStatement();
}

$prefix = Server::get(IConfig::class)->getSystemValueString('dbtableprefix', 'oc_');
$schema = $this->connection->createSchema();
try {
$schema->getTable($prefix . 'testing');
$this->connection->getQueryBuilder()->delete('testing')->executeStatement();
} catch (SchemaException $e) {
$this->schemaSetup = true;
$table = $schema->createTable($prefix . 'testing');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'notnull' => true,
]);

$table->addColumn('datetime', Types::DATETIME_MUTABLE, [
'notnull' => false,
]);

$table->setPrimaryKey(['id']);
$this->connection->migrateToSchema($schema);
}
}
}

0 comments on commit 197d052

Please sign in to comment.