1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Driver\SQLSrv; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Driver\SQLSrv\Driver; |
6
|
|
|
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvException; |
7
|
|
|
use Doctrine\DBAL\Driver\SQLSrv\SQLSrvStatement; |
8
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
9
|
|
|
|
10
|
|
|
class StatementTest extends DbalFunctionalTestCase |
11
|
|
|
{ |
12
|
|
|
protected function setUp() |
13
|
|
|
{ |
14
|
|
|
if (!extension_loaded('sqlsrv')) { |
15
|
|
|
self::markTestSkipped('sqlsrv is not installed.'); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
if (!$this->_conn->getDriver() instanceof Driver) { |
21
|
|
|
self::markTestSkipped('sqlsrv only test'); |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testFailureToPrepareResultsInException() |
26
|
|
|
{ |
27
|
|
|
// use the driver connection directly to avoid having exception wrapped |
28
|
|
|
$stmt = $this->_conn->getWrappedConnection()->prepare(null); |
29
|
|
|
|
30
|
|
|
// it's impossible to prepare the statement without bound variables for SQL Server, |
31
|
|
|
// so the preparation happens before the first execution when variables are already in place |
32
|
|
|
$this->expectException(SQLSrvException::class); |
33
|
|
|
$stmt->execute(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testObjectsWillBeCastedToString() |
37
|
|
|
{ |
38
|
|
|
// use the driver connection directly to avoid having exception wrapped |
39
|
|
|
/** @var SQLSrvStatement $stmt */ |
40
|
|
|
$stmt = $this->_conn->getWrappedConnection()->prepare("SELECT ?"); |
41
|
|
|
|
42
|
|
|
// create and bind an object that implements magic method __toString() |
43
|
|
|
$object = new StringCastableObject('test string'); |
44
|
|
|
$stmt->bindParam(1, $object, \PDO::PARAM_STR); |
45
|
|
|
|
46
|
|
|
// when executing the query, no Exception must be thrown |
47
|
|
|
$stmt->execute(); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|