Skip to content

Commit

Permalink
Failing test case for #4400
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Nov 8, 2020
1 parent 97ee7c4 commit 115e17b
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
4 changes: 2 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
<ini name="error_reporting" value="-1" />

<!-- Test connection parameters -->
<!-- Uncomment, otherwise SQLite runs

<var name="db_driver" value="pdo_mysql"/>
<var name="db_host" value="localhost" />
<var name="db_port" value="3306"/>
<var name="db_user" value="root" />
<var name="db_password" value="" />
<var name="db_dbname" value="doctrine_tests" />
-->

<!--<var name="db_event_subscribers" value="Doctrine\DBAL\Event\Listeners\OracleSessionInit">-->

<!-- Privileged user connection parameters. Used to create and drop the test database -->
Expand Down
70 changes: 70 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php
Original file line number Diff line number Diff line change
@@ -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')) {
return;
}

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);

self::assertFalse($this->c2->fetchOne($query));

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

0 comments on commit 115e17b

Please sign in to comment.