Skip to content

Commit

Permalink
Enable functional test
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 11, 2023
1 parent 3f04a41 commit 6d657ad
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 61 deletions.
18 changes: 0 additions & 18 deletions src/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@
*/
class OraclePlatform extends AbstractPlatform
{
/**
* Returns the FOR UPDATE expression.
*
* @return string
*/
public function getForUpdateSQL()
{
return '';
}

/**
* Returns the SKIP LOCKED expression.
*/
public function getSkipLockedSQL(): string
{
return '';
}

/**
* Assertion for Oracle identifiers.
*
Expand Down
13 changes: 6 additions & 7 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1366,15 +1366,14 @@ private function getSQLForSelect(): string
. ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '')
. ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '')
. ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '')
. ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : '')
. ($platform->isLockLocatedAtTheEnd() ? $locksSql : '');
. ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : '');

if ($this->isLimitQuery()) {
return $platform->modifyLimitQuery(
$query,
$this->maxResults,
$this->firstResult,
);
$query = $platform->modifyLimitQuery($query, $this->maxResults, $this->firstResult);
}

if ($platform->isLockLocatedAtTheEnd()) {
$query .= $locksSql;
}

return $query;
Expand Down
62 changes: 26 additions & 36 deletions tests/Functional/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

namespace Doctrine\DBAL\Tests\Functional\Query;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MariaDb1043Platform;
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
use Doctrine\DBAL\Platforms\MySQL57Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Table;
Expand All @@ -22,29 +20,27 @@
use Throwable;

use function get_class;
use function sprintf;

final class QueryBuilderTest extends FunctionalTestCase
{
private function platformSupportsLocks(AbstractPlatform $platform): bool
{
return ! $platform instanceof DB2Platform
&& ! $platform instanceof MariaDb1027Platform
&& ! $platform instanceof MariaDb1043Platform
&& ! $platform instanceof MariaDb1052Platform
&& ! $platform instanceof MySQL57Platform
&& ! $platform instanceof PostgreSQL94Platform
&& ! $platform instanceof OraclePlatform
&& ! $platform instanceof SqlitePlatform;
}

public function testConcurrentConnectionSkipsLockedRows(): void
{
$platform = $this->connection->getDatabasePlatform();
if (! $this->platformSupportsLocks($platform)) {
self::markTestSkipped(
sprintf('Skipping, because platform %s does not support locks', get_class($platform)),
);

if ($platform instanceof MariaDBPlatform && ! $platform instanceof MariaDb1060Platform) {
self::markTestSkipped('Skipping on MariaDB older than 10.6');
}

if ($platform instanceof MySQLPlatform && ! $platform instanceof MySQL80Platform) {
self::markTestSkipped('Skipping on MySQL older than 8.0');
}

if ($platform instanceof PostgreSQLPlatform && ! $platform instanceof PostgreSQL100Platform) {
self::markTestSkipped('Skipping on PostgreSQL older than 10.0');
}

if ($platform instanceof SqlitePlatform) {
self::markTestSkipped('Skipping on SQLite');
}

$tableName = 'users';
Expand Down Expand Up @@ -79,9 +75,7 @@ public function testConcurrentConnectionSkipsLockedRows(): void
);
}

$resultList = $result->fetchAllAssociative();
self::assertCount(1, $resultList);
self::assertEquals(1, $resultList[0]['id']);
self::assertEquals([1], $result->fetchFirstColumn());

$connection2 = TestUtil::getConnection();
self::assertTrue(
Expand All @@ -99,19 +93,15 @@ public function testConcurrentConnectionSkipsLockedRows(): void
->skipLocked();

self::assertTrue($connection1->isTransactionActive(), 'A transaction should still be active on connection 1');
$result = $connection2->executeQuery($qb2->getSQL());
$resultList = $result->fetchAllAssociative();
self::assertCount(1, $resultList);
self::assertEquals(2, $resultList[0]['id']);
$result = $connection2->executeQuery($qb2->getSQL());
self::assertEquals([2], $result->fetchFirstColumn());

$connection1->commit();
self::assertFalse(
$connection1->isTransactionActive(),
'A transaction should not be active anymore on connection 1',
);
$result = $connection2->executeQuery($qb2->getSQL());
$resultList = $result->fetchAllAssociative();
self::assertCount(1, $resultList);
self::assertEquals(1, $resultList[0]['id']);
$result = $connection2->executeQuery($qb2->getSQL());
self::assertEquals([1], $result->fetchFirstColumn());
}
}

0 comments on commit 6d657ad

Please sign in to comment.