|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\DBAL\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use Doctrine\DBAL\Driver\AbstractSQLServerDriver; |
|
7
|
|
|
use Doctrine\DBAL\Driver\Connection as DriverConnection; |
|
8
|
|
|
use Doctrine\DBAL\Driver\PDOSqlsrv\Driver as PDOSqlsrvDriver; |
|
9
|
|
|
use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; |
|
10
|
|
|
use Doctrine\DBAL\Platforms\SQLServer2008Platform; |
|
11
|
|
|
use Doctrine\DBAL\Schema\SQLServerSchemaManager; |
|
12
|
|
|
use PDO; |
|
13
|
|
|
|
|
14
|
|
|
class AbstractSQLServerDriverTest extends AbstractDriverTest |
|
15
|
|
|
{ |
|
16
|
|
|
protected function createDriver() |
|
17
|
|
|
{ |
|
18
|
|
|
return $this->getMockForAbstractClass('Doctrine\DBAL\Driver\AbstractSQLServerDriver'); |
|
|
|
|
|
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
protected function createPlatform() |
|
22
|
|
|
{ |
|
23
|
|
|
return new SQLServer2008Platform(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function createSchemaManager(Connection $connection) |
|
27
|
|
|
{ |
|
28
|
|
|
return new SQLServerSchemaManager($connection); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
protected function getDatabasePlatformsForVersions() |
|
32
|
|
|
{ |
|
33
|
|
|
return array( |
|
34
|
|
|
array('9', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), |
|
35
|
|
|
array('9.00', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), |
|
36
|
|
|
array('9.00.0', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), |
|
37
|
|
|
array('9.00.1398', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), |
|
38
|
|
|
array('9.00.1398.99', 'Doctrine\DBAL\Platforms\SQLServerPlatform'), |
|
39
|
|
|
array('9.00.1399', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
40
|
|
|
array('9.00.1399.0', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
41
|
|
|
array('9.00.1399.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
42
|
|
|
array('9.00.1400', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
43
|
|
|
array('9.10', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
44
|
|
|
array('9.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
45
|
|
|
array('10.00.1599', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
46
|
|
|
array('10.00.1599.99', 'Doctrine\DBAL\Platforms\SQLServer2005Platform'), |
|
47
|
|
|
array('10.00.1600', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
48
|
|
|
array('10.00.1600.0', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
49
|
|
|
array('10.00.1600.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
50
|
|
|
array('10.00.1601', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
51
|
|
|
array('10.10', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
52
|
|
|
array('10.10.9999', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
53
|
|
|
array('11.00.2099', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
54
|
|
|
array('11.00.2099.99', 'Doctrine\DBAL\Platforms\SQLServer2008Platform'), |
|
55
|
|
|
array('11.00.2100', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), |
|
56
|
|
|
array('11.00.2100.0', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), |
|
57
|
|
|
array('11.00.2100.99', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), |
|
58
|
|
|
array('11.00.2101', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), |
|
59
|
|
|
array('12', 'Doctrine\DBAL\Platforms\SQLServer2012Platform'), |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
protected function getDriver() : AbstractSQLServerDriver |
|
64
|
|
|
{ |
|
65
|
|
|
return static::createDriver(); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function checkForSkippingTest(AbstractSQLServerDriver $driver) : void |
|
69
|
|
|
{ |
|
70
|
|
|
if (extension_loaded('sqlsrv') && $driver instanceof SQLSrvDriver |
|
|
|
|
|
|
71
|
|
|
|| extension_loaded('pdo_sqlsrv') && $driver instanceof PDOSqlsrvDriver) { |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->markTestSkipped('The test is only for the sqlsrv and the pdo_sqlsrv drivers'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
protected function getConnection(AbstractSQLServerDriver $driver, array $driverOptions) : DriverConnection |
|
79
|
|
|
{ |
|
80
|
|
|
return $driver->connect( |
|
81
|
|
|
[ |
|
82
|
|
|
'host' => $GLOBALS['db_host'], |
|
83
|
|
|
'port' => $GLOBALS['db_port'], |
|
84
|
|
|
], |
|
85
|
|
|
$GLOBALS['db_username'], |
|
86
|
|
|
$GLOBALS['db_password'], |
|
87
|
|
|
$driverOptions |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testConnectionOptions() : void |
|
92
|
|
|
{ |
|
93
|
|
|
$driver = $this->getDriver(); |
|
94
|
|
|
$this->checkForSkippingTest($driver); |
|
95
|
|
|
$connection = $this->getConnection($driver, ['APP' => 'APP_NAME']); |
|
96
|
|
|
$result = $connection->query('select APP_NAME() as app')->fetch(); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
self::assertSame('APP_NAME', $result['app']); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function testDriverOptions() : void |
|
102
|
|
|
{ |
|
103
|
|
|
$driver = $this->getDriver(); |
|
104
|
|
|
$this->checkForSkippingTest($driver); |
|
105
|
|
|
$connection = $this->getConnection($driver, [PDO::ATTR_CASE => PDO::CASE_UPPER]); |
|
106
|
|
|
|
|
107
|
|
|
self::assertSame(PDO::CASE_UPPER, $connection->getAttribute(PDO::ATTR_CASE)); |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: