class SqlsrvConnectionTest in Drupal driver for SQL Server and SQL Azure 8.2
Same name and namespace in other branches
- 4.2.x tests/src/Unit/SqlsrvConnectionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
- 3.0.x tests/src/Unit/SqlsrvConnectionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
- 3.1.x tests/src/Unit/SqlsrvConnectionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
- 4.0.x tests/src/Unit/SqlsrvConnectionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
- 4.1.x tests/src/Unit/SqlsrvConnectionTest.php \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
Test the behavior of the Connection class.
These tests are not expected to pass on other database drivers.
@group Database
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\sqlsrv\Unit\SqlsrvConnectionTest
Expanded class hierarchy of SqlsrvConnectionTest
File
- tests/
src/ Unit/ SqlsrvConnectionTest.php, line 16
Namespace
Drupal\Tests\sqlsrv\UnitView source
class SqlsrvConnectionTest extends UnitTestCase {
/**
* Mock PDO object for use in tests.
*
* @var \PHPUnit\Framework\MockObject\MockObject|\Drupal\Tests\Core\Database\Stub\StubPDO
*/
protected $mockPdo;
/**
* Mock Schema object for use in tests.
*
* @var \PHPUnit\Framework\MockObject\MockObject|\Drupal\Driver\Database\sqlsrv\Schema
*/
protected $mockSchema;
/**
* Database connection options.
*
* The core test suite uses an empty array.
* This module requires at least a value in:
* $option['prefix']['default']
*
* @var array
*/
protected $options;
/**
* {@inheritdoc}
*/
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');
}
/**
* Data provider for testEscapeTable.
*
* @return array
* An indexed array of where each value is an array of arguments to pass to
* testEscapeField. The first value is the expected value, and the second
* value is the value to test.
*/
public function providerEscapeTables() {
return [
[
'nocase',
'nocase',
],
];
}
/**
* Data provider for testEscapeField.
*
* @return array
* Array of arrays with the following elements:
* - Expected escaped string.
* - String to escape.
*/
public function providerEscapeFields() {
return [
[
'[timestamp]',
'timestamp',
],
];
}
/**
* Test that tables are properly escaped.
*
* @dataProvider providerEscapeTables
*/
public function testEscapeTable($expected, $name) {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals($expected, $connection
->escapeTable($name));
}
/**
* Test that fields are properly escaped.
*
* @dataProvider providerEscapeFields
*/
public function testEscapeField($expected, $name) {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals($expected, $connection
->escapeField($name));
}
/**
* Test that the connection returns the correct driver string.
*/
public function testDriverString() {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals('sqlsrv', $connection
->driver());
}
/**
* Test that the connection returns the correct database type string.
*/
public function testDatabaseType() {
$connection = new Connection($this->mockPdo, $this->options);
$this
->assertEquals('sqlsrv', $connection
->databaseType());
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
SqlsrvConnectionTest:: |
protected | property | Mock PDO object for use in tests. | |
SqlsrvConnectionTest:: |
protected | property | Mock Schema object for use in tests. | |
SqlsrvConnectionTest:: |
protected | property | Database connection options. | |
SqlsrvConnectionTest:: |
public | function | Data provider for testEscapeField. | |
SqlsrvConnectionTest:: |
public | function | Data provider for testEscapeTable. | |
SqlsrvConnectionTest:: |
protected | function |
Overrides UnitTestCase:: |
|
SqlsrvConnectionTest:: |
public | function | Test that the connection returns the correct database type string. | |
SqlsrvConnectionTest:: |
public | function | Test that the connection returns the correct driver string. | |
SqlsrvConnectionTest:: |
public | function | Test that fields are properly escaped. | |
SqlsrvConnectionTest:: |
public | function | Test that tables are properly escaped. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |