Skip to content

Commit

Permalink
Failing test case for doctrine#4400
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 8, 2020
1 parent 97ee7c4 commit a0727d9
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php
@@ -0,0 +1,70 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\Tests\DbalTestCase;
use Doctrine\Tests\TestUtil;

class LockModeTest extends DbalTestCase
{
/** @var Connection */
private $c1;

/** @var Connection */
private $c2;

public function setUp(): void
{
$this->c1 = TestUtil::getConnection();
$this->c2 = TestUtil::getConnection();

$table = new Table('users');
$table->addColumn('id', 'integer');

$this->c1->getSchemaManager()->createTable($table);

if (! $this->c2->getSchemaManager()->tablesExist('users')) {
if ($this->c2->getDatabasePlatform() instanceof SqlitePlatform) {
self::markTestSkipped('This test cannot run on SQLite using an in-memory database');
}

self::fail('Separate connections do not seem to talk to the same database');
}
}

public function tearDown(): void
{
$this->c1->getSchemaManager()->dropTable('users');

$this->c1->close();
$this->c2->close();
}

public function testLockModeNoneDoesNotBreakTransactionIsolation(): void
{
$this->c1->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
$this->c2->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);

$this->c1->beginTransaction();
$this->c2->beginTransaction();

$this->c1->insert('users', ['id' => 1]);

$query = 'SELECT id FROM users';
$query = $this->c2->getDatabasePlatform()->appendLockHint($query, LockMode::NONE);

$statement = $this->c2->query($query);

self::assertFalse($statement->fetchOne());

$this->c1->commit();
$this->c2->commit();
}
}

0 comments on commit a0727d9

Please sign in to comment.