ConnectionTest.php

Same filename in this branch
  1. 11.x core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  2. 11.x core/modules/mysql/tests/src/Unit/ConnectionTest.php
  3. 11.x core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  4. 11.x core/modules/mysqli/tests/src/Kernel/mysqli/ConnectionTest.php
  5. 11.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  6. 11.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  7. 11.x core/modules/pgsql/tests/src/Unit/ConnectionTest.php
  8. 11.x core/modules/pgsql/tests/src/Kernel/pgsql/ConnectionTest.php
Same filename and directory in other branches
  1. 10 core/modules/sqlite/tests/src/Kernel/sqlite/ConnectionTest.php
  2. 8.9.x core/tests/Drupal/Tests/Core/Database/Driver/sqlite/ConnectionTest.php
  3. 10 core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  4. 10 core/modules/mysql/tests/src/Unit/ConnectionTest.php
  5. 10 core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  6. 10 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  7. 10 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  8. 9 core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  9. 9 core/modules/mysql/tests/src/Unit/ConnectionTest.php
  10. 9 core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  11. 9 core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  12. 9 core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  13. 8.9.x core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  14. 8.9.x core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  15. main core/modules/sqlite/tests/src/Unit/ConnectionTest.php
  16. main core/modules/mysql/tests/src/Unit/ConnectionTest.php
  17. main core/modules/mysql/tests/src/Kernel/mysql/ConnectionTest.php
  18. main core/modules/mysqli/tests/src/Kernel/mysqli/ConnectionTest.php
  19. main core/tests/Drupal/KernelTests/Core/Database/ConnectionTest.php
  20. main core/tests/Drupal/Tests/Core/Database/ConnectionTest.php
  21. main core/modules/pgsql/tests/src/Unit/ConnectionTest.php
  22. main core/modules/pgsql/tests/src/Kernel/pgsql/ConnectionTest.php
  23. main core/modules/search/tests/src/Unit/Database/ConnectionTest.php

Namespace

Drupal\Tests\search\Unit\Database

File

core/modules/search/tests/src/Unit/Database/ConnectionTest.php

View source
<?php

declare (strict_types=1);
namespace Drupal\Tests\search\Unit\Database;

use Composer\Autoload\ClassLoader;
use Drupal\Core\Database\Connection;
use Drupal\Tests\Core\Database\Stub\StubConnection;
use Drupal\Tests\UnitTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

/**
 * Tests the connections for the Search queries.
 */
class ConnectionTest extends UnitTestCase {
  
  /**
   * Data provider for testGetDriverClass().
   *
   * @return array
   *   Array of arrays with the following elements:
   *   - Expected namespaced class name.
   *   - Namespace.
   *   - Class name without namespace.
   */
  public static function providerGetDriverClass() : array {
    return [
      [
        'SearchQuery',
        'Drupal\\SearchFake\\Driver\\Database\\SearchFake',
        'SearchQuery',
      ],
      [
        'Drupal\\search_fake\\Driver\\Database\\SearchFakeWithAllCustomClasses\\SearchQuery',
        'Drupal\\search_fake\\Driver\\Database\\SearchFakeWithAllCustomClasses',
        'SearchQuery',
      ],
      [
        'Drupal\\search\\SearchQuery',
        'Drupal\\search_fake\\Driver\\Database\\SearchFakeWithAllCustomClasses',
        'Drupal\\search\\SearchQuery',
      ],
      [
        '\\Drupal\\search\\SearchQuery',
        'Drupal\\search_fake\\Driver\\Database\\SearchFakeWithAllCustomClasses',
        '\\Drupal\\search\\SearchQuery',
      ],
    ];
  }
  
  /**
   * Tests get driver class.
   */
  public function testGetDriverClass(string $expected, ?string $namespace, string $class) : void {
    $additional_class_loader = new ClassLoader();
    $additional_class_loader->addPsr4("Drupal\\search_fake\\Driver\\Database\\SearchFake\\", __DIR__ . "/../../../modules/search_fake/src/Driver/Database/SearchFake");
    $additional_class_loader->addPsr4("Drupal\\search_fake\\Driver\\Database\\SearchFakeWithAllCustomClasses\\", __DIR__ . "/../../../modules/search_fake/src/Driver/Database/SearchFakeWithAllCustomClasses");
    $additional_class_loader->register(TRUE);
    $connection = new StubConnection($this->createStub(\PDO::class), [
      'namespace' => $namespace,
    ]);
    match ($class) {  'Install\\Tasks', 'ExceptionHandler', 'Select', 'Insert', 'Merge', 'Upsert', 'Update', 'Delete', 'Truncate', 'Schema', 'Condition', 'Transaction' => $this->expectExceptionMessageIs('Calling Drupal\\Core\\Database\\Connection::getDriverClass() for \'' . $class . '\' is not supported. Use standard autoloading in the methods that return database operations. See https://www.drupal.org/node/3217534'),
      default => NULL,
    
    };
    $this->assertEquals($expected, $connection->getDriverClass($class));
  }

}

Classes

Title Deprecated Summary
ConnectionTest Tests the connections for the Search queries.

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