forked from doctrine/dbal
/
ConnectionTest.php
113 lines (88 loc) · 3.12 KB
/
ConnectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional\Driver\PDO;
use Doctrine\DBAL\Driver\PDO\Connection;
use Doctrine\DBAL\Driver\PDO\Exception;
use Doctrine\DBAL\Driver\PDO\OCI\Driver as PDOOCIDriver;
use Doctrine\DBAL\Driver\PDO\PgSQL\Driver as PDOPgSQLDriver;
use Doctrine\DBAL\Driver\PDO\SQLSrv\Driver as PDOSQLSrvDriver;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use function get_class;
use function sprintf;
/**
* @requires extension pdo
*/
class ConnectionTest extends DbalFunctionalTestCase
{
/**
* The PDO driver connection under test.
*
* @var Connection
*/
protected $driverConnection;
protected function setUp(): void
{
parent::setUp();
$this->driverConnection = $this->connection->getWrappedConnection();
if ($this->driverConnection instanceof Connection) {
return;
}
$this->markTestSkipped('PDO connection only test.');
}
protected function tearDown(): void
{
$this->resetSharedConn();
parent::tearDown();
}
public function testDoesNotRequireQueryForServerVersion(): void
{
self::assertFalse($this->driverConnection->requiresQueryForServerVersion());
}
public function testThrowsWrappedExceptionOnConstruct(): void
{
$this->expectException(Exception::class);
new Connection('foo');
}
public function testThrowsWrappedExceptionOnExec(): void
{
$this->expectException(Exception::class);
$this->driverConnection->exec('foo');
}
public function testThrowsWrappedExceptionOnPrepare(): void
{
$driver = $this->connection->getDriver();
if ($driver instanceof PDOSQLSrvDriver) {
$this->markTestSkipped('pdo_sqlsrv does not allow setting PDO::ATTR_EMULATE_PREPARES at connection level.');
}
// Some PDO adapters do not check the query server-side
// even though emulated prepared statements are disabled,
// so an exception is thrown only eventually.
if (
$driver instanceof PDOOCIDriver
|| $driver instanceof PDOPgSQLDriver
) {
self::markTestSkipped(sprintf(
'The underlying implementation of the %s driver does not check the query to be prepared server-side.',
get_class($driver)
));
}
// Emulated prepared statements have to be disabled for this test
// so that PDO actually communicates with the database server to check the query.
$this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$this->expectException(Exception::class);
$this->driverConnection->prepare('foo');
}
public function testThrowsWrappedExceptionOnQuery(): void
{
$this->expectException(Exception::class);
$this->driverConnection->query('foo');
}
/**
* This test ensures backward compatibility with DBAL 2.x and should be removed in 3.0.
*/
public function testQuoteInteger(): void
{
self::assertSame("'1'", $this->connection->getWrappedConnection()->quote(1));
}
}