From bc8b0c7b1dcec1c39efb35e4b4ecc6f4071badfb Mon Sep 17 00:00:00 2001 From: Benjamin Morel Date: Sun, 8 Nov 2020 23:17:59 +0100 Subject: [PATCH] Test case --- .../Tests/DBAL/Functional/LockModeTest.php | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php diff --git a/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php b/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php new file mode 100644 index 00000000000..2b61aaeea75 --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Functional/LockModeTest.php @@ -0,0 +1,81 @@ +c1 = TestUtil::getConnection(); + $this->c2 = TestUtil::getConnection(); + + if ($this->c1->getDriver() instanceof OCI8\Driver) { + // https://github.com/doctrine/dbal/issues/4417 + self::markTestSkipped('This test fails on OCI8 for a currently unknown reason'); + } + + $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 + { + try { + $this->c1->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED); + $this->c2->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED); + } catch (Exception $e) { + self::markTestSkipped('This test must be able to set a transaction isolation level'); + } + + $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(); + } +}