You are here

class InstallerObjectTest in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php \Drupal\Tests\Core\Database\InstallerObjectTest
  2. 10 core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php \Drupal\Tests\Core\Database\InstallerObjectTest

Tests the db_installer_object() function that is used during installation.

These tests run in isolation to prevent the autoloader additions from affecting other tests.

@covers ::db_installer_object

@runTestsInSeparateProcesses @preserveGlobalState disabled

@group Database

Hierarchy

Expanded class hierarchy of InstallerObjectTest

File

core/tests/Drupal/Tests/Core/Database/InstallerObjectTest.php, line 25

Namespace

Drupal\Tests\Core\Database
View source
class InstallerObjectTest extends UnitTestCase {

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();
    require_once __DIR__ . '/../../../../../includes/install.inc';
    $additional_class_loader = new ClassLoader();
    $additional_class_loader
      ->addPsr4("Drupal\\Driver\\Database\\fake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/custom/fake");
    $additional_class_loader
      ->addPsr4("Drupal\\Core\\Database\\Driver\\corefake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/core/corefake");
    $additional_class_loader
      ->addPsr4("Drupal\\Driver\\Database\\corefake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/custom/corefake");
    $additional_class_loader
      ->addPsr4("Drupal\\driver_test\\Driver\\Database\\DrivertestMysql\\", __DIR__ . "/../../../../../../modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestMysql");
    $additional_class_loader
      ->register(TRUE);
  }

  /**
   * @dataProvider providerDbInstallerObject
   */
  public function testDbInstallerObject($driver, $namespace, $expected_class_name) {
    $object = db_installer_object($driver, $namespace);
    $this
      ->assertEquals(get_class($object), $expected_class_name);
  }

  /**
   * Dataprovider for testDbUrltoConnectionConversion().
   *
   * @return array
   *   Array of arrays with the following elements:
   *   - driver: The driver name.
   *   - namespace: The namespace providing the driver.
   *   - class: The fully qualified class name of the expected install task.
   */
  public function providerDbInstallerObject() {
    return [
      // A driver only in the core namespace.
      [
        'mysql',
        NULL,
        MysqlInstallTasks::class,
      ],
      // A driver only in the custom namespace.
      [
        'fake',
        "Drupal\\Driver\\Database\\fake",
        FakeInstallTasks::class,
      ],
      // A driver in both namespaces. The custom one takes precedence.
      [
        'corefake',
        "Drupal\\Driver\\Database\\corefake",
        CustomCoreFakeInstallTasks::class,
      ],
      // A driver from a module that has a different name as the driver.
      [
        'DrivertestMysql',
        "Drupal\\driver_test\\Driver\\Database\\DrivertestMysql",
        DriverTestMysqlInstallTasks::class,
      ],
    ];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InstallerObjectTest::providerDbInstallerObject public function Dataprovider for testDbUrltoConnectionConversion().
InstallerObjectTest::setUp protected function Overrides UnitTestCase::setUp
InstallerObjectTest::testDbInstallerObject public function @dataProvider providerDbInstallerObject
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.