mirror of
https://github.com/dg/dibi.git
synced 2025-08-06 22:26:43 +02:00
PdoDriver: check for misconfigured PDO connections resource (#294)
This commit is contained in:
@@ -78,6 +78,10 @@ class PdoDriver implements Dibi\Driver, Dibi\ResultDriver
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->connection->getAttribute(PDO::ATTR_ERRMODE) !== PDO::ERRMODE_SILENT) {
|
||||
throw new Dibi\DriverException('PDO connection in exception or warning error mode is not supported.');
|
||||
}
|
||||
|
||||
$this->driverName = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME);
|
||||
$this->serverVersion = isset($config['version'])
|
||||
? $config['version']
|
||||
|
41
tests/dibi/PdoDriver.providedConnection.phpt
Normal file
41
tests/dibi/PdoDriver.providedConnection.phpt
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Tester\Assert;
|
||||
|
||||
require __DIR__ . '/bootstrap.php';
|
||||
|
||||
|
||||
function buildPdoDriver($errorMode)
|
||||
{
|
||||
$pdo = new PDO('sqlite::memory:');
|
||||
if ($errorMode !== null) {
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, $errorMode);
|
||||
}
|
||||
$config = ['resource' => $pdo];
|
||||
$driver = new Dibi\Drivers\PdoDriver;
|
||||
$driver->connect($config);
|
||||
}
|
||||
|
||||
|
||||
// PDO error mode: exception
|
||||
Assert::exception(function () {
|
||||
buildPdoDriver(PDO::ERRMODE_EXCEPTION);
|
||||
}, 'Dibi\DriverException', 'PDO connection in exception or warning error mode is not supported.');
|
||||
|
||||
|
||||
// PDO error mode: warning
|
||||
Assert::exception(function () {
|
||||
buildPdoDriver(PDO::ERRMODE_WARNING);
|
||||
}, 'Dibi\DriverException', 'PDO connection in exception or warning error mode is not supported.');
|
||||
|
||||
|
||||
// PDO error mode: explicitly set silent
|
||||
test(function () {
|
||||
buildPdoDriver(PDO::ERRMODE_SILENT);
|
||||
});
|
||||
|
||||
|
||||
// PDO error mode: implicitly set silent
|
||||
test(function () {
|
||||
buildPdoDriver(null);
|
||||
});
|
Reference in New Issue
Block a user