SqlsrvConnectionTest.php in Drupal driver for SQL Server and SQL Azure 8.2
File
tests/src/Unit/SqlsrvConnectionTest.php
View source
<?php
namespace Drupal\Tests\sqlsrv\Unit;
use Drupal\Driver\Database\sqlsrv\Connection;
use Drupal\Driver\Database\sqlsrv\ConnectionSettings;
use Drupal\Tests\UnitTestCase;
class SqlsrvConnectionTest extends UnitTestCase {
protected $mockPdo;
protected $mockSchema;
protected $options;
protected function setUp() {
parent::setUp();
$this->mockSchema = $this
->getMockBuilder('Drupal\\Driver\\Database\\sqlsrv\\Schema')
->setMethods([
'getDefaultSchema',
'__construct',
])
->setMockClassName('MockSchema')
->setConstructorArgs([
NULL,
])
->disableOriginalConstructor()
->getMock();
$this->mockSchema
->method('getDefaultSchema')
->willReturn('dbo');
if (!class_exists('Drupal\\Driver\\Database\\mock\\Schema')) {
class_alias('MockSchema', 'Drupal\\Driver\\Database\\mock\\Schema');
}
$this->options['namespace'] = 'Drupal\\Driver\\Database\\mock';
$this->options['prefix']['default'] = '';
$this->options['driver_settings'] = ConnectionSettings::instanceFromData([]);
$this->mockPdo = $this
->createMock('Drupal\\Tests\\Core\\Database\\Stub\\StubPDO');
}
public function providerEscapeTables() {
return [
[
'nocase',
'nocase',
],
];
}
public function providerEscapeFields() {
return [
[
'[timestamp]',
'timestamp',
],
];
}
public function testEscapeTable($expected, $name) {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals($expected, $connection
->escapeTable($name));
}
public function testEscapeField($expected, $name) {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals($expected, $connection
->escapeField($name));
}
public function testDriverString() {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals('sqlsrv', $connection
->driver());
}
public function testDatabaseType() {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals('sqlsrv', $connection
->databaseType());
}
}