forked from doctrine/dbal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doctrine#6627 from doctrine/4.2.x
Merge 4.2.x up into 4.3.x
- Loading branch information
Showing
12 changed files
with
192 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Tests\Functional\Driver\OCI8; | ||
|
||
use Doctrine\DBAL\DriverManager; | ||
use Doctrine\DBAL\Exception\DriverException; | ||
use Doctrine\DBAL\Tests\FunctionalTestCase; | ||
use Doctrine\DBAL\Tests\TestUtil; | ||
use Throwable; | ||
|
||
class ConnectionTest extends FunctionalTestCase | ||
{ | ||
public static function setUpBeforeClass(): void | ||
{ | ||
if (TestUtil::isDriverOneOf('oci8')) { | ||
return; | ||
} | ||
|
||
self::markTestSkipped('This test requires the oci8 driver.'); | ||
} | ||
|
||
public function testPrepareThrowsErrorOnConnectionLost(): void | ||
{ | ||
$this->markConnectionNotReusable(); | ||
$this->killCurrentSession(); | ||
|
||
$this->expectException(DriverException::class); | ||
|
||
$this->connection->prepare('SELECT * FROM 1'); | ||
} | ||
|
||
/** | ||
* Kill the current session, by using another connection | ||
* Oracle doesn't allow you to terminate the current session, so we use a second connection | ||
*/ | ||
private function killCurrentSession(): void | ||
{ | ||
$row = $this->connection->fetchNumeric( | ||
<<<'SQL' | ||
SELECT SID, SERIAL# | ||
FROM V$SESSION | ||
WHERE AUDSID = USERENV('SESSIONID') | ||
SQL, | ||
); | ||
|
||
self::assertNotFalse($row); | ||
/** @psalm-suppress PossiblyUndefinedArrayOffset */ | ||
[$sid, $serialNumber] = $row; | ||
|
||
self::assertNotNull($sid, 'SID is missing.'); | ||
self::assertNotNull($serialNumber, 'Serial number is missing.'); | ||
|
||
$params = TestUtil::getConnectionParams(); | ||
$params['driverOptions']['exclusive'] = true; | ||
$secondConnection = DriverManager::getConnection($params); | ||
|
||
$sessionParam = $this->connection->quote($sid . ', ' . $serialNumber); | ||
$secondConnection->executeStatement('ALTER SYSTEM DISCONNECT SESSION ' . $sessionParam . ' IMMEDIATE'); | ||
|
||
// Ensure OCI driver is aware of connection state change by executing any statement | ||
try { | ||
$this->connection->executeStatement('INVALID SQL'); | ||
} catch (Throwable) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.