ConnectionTest.php

Same filename in this branch
  1. 8.9.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
Same filename and directory in other branches
  1. 9 core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  2. 9 core/modules/mysql/tests/src/Unit/ConnectionTest.php
  3. 9 core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  4. 9 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  5. 9 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  6. 10 core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  7. 10 core/modules/sqlite/tests/src/Kernel/sqlite/ConnectionTest.php
  8. 10 core/modules/mysql/tests/src/Unit/ConnectionTest.php
  9. 10 core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  10. 10 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  11. 10 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  12. 11.x core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  13. 11.x core/modules/mysql/tests/src/Unit/ConnectionTest.php
  14. 11.x core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  15. 11.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  16. 11.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php

Namespace

Drupal\Tests\Core\Database\Driver\sqlite

File

core/tests/Drupal/Tests/Core/Database/Driver/sqlite/ConnectionTest.php

View source
<?php

namespace Drupal\Tests\Core\Database\Driver\sqlite;

use Drupal\Core\Database\Driver\sqlite\Connection;
use Drupal\Tests\Core\Database\Stub\StubPDO;
use Drupal\Tests\UnitTestCase;

/**
 * @coversDefaultClass \Drupal\Core\Database\Driver\sqlite\Connection
 * @group Database
 */
class ConnectionTest extends UnitTestCase {
    
    /**
     * @covers ::createConnectionOptionsFromUrl
     * @dataProvider providerCreateConnectionOptionsFromUrl
     *
     * @param string $url
     *   SQLite URL.
     * @param string $expected
     *   Expected connection option.
     */
    public function testCreateConnectionOptionsFromUrl(string $url, string $expected) {
        $root = dirname(__DIR__, 8);
        $sqlite_connection = new Connection($this->createMock(StubPDO::class), []);
        $database = $sqlite_connection->createConnectionOptionsFromUrl($url, $root);
        $this->assertEquals('sqlite', $database['driver']);
        $this->assertEquals($expected, $database['database']);
    }
    
    /**
     * Data provider for testCreateConnectionOptionsFromUrl.
     *
     * @return string[][]
     *   Associative array of arrays with the following elements:
     *   - SQLite database URL
     *   - Expected database connection option
     */
    public function providerCreateConnectionOptionsFromUrl() : array {
        $root = dirname(__DIR__, 8);
        return [
            'sqlite relative path' => [
                'sqlite://localhost/tmp/test',
                $root . '/tmp/test',
            ],
            'sqlite absolute path' => [
                'sqlite://localhost//tmp/test',
                '/tmp/test',
            ],
            'in memory sqlite path' => [
                'sqlite://localhost/:memory:',
                ':memory:',
            ],
        ];
    }

}

Classes

Title Deprecated Summary
ConnectionTest @coversDefaultClass \Drupal\Core\Database\Driver\sqlite\Connection @group Database

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.