function SelectExtenderTest::testExtend

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php \Drupal\KernelTests\Core\Database\SelectExtenderTest::testExtend()
  2. 11.x core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php \Drupal\KernelTests\Core\Database\SelectExtenderTest::testExtend()

@covers ::extend @covers \Drupal\Core\Database\Query\SelectExtender::extend @dataProvider providerExtend

File

core/tests/Drupal/KernelTests/Core/Database/SelectExtenderTest.php, line 120

Class

SelectExtenderTest
Tests the Select query extender classes.

Namespace

Drupal\KernelTests\Core\Database

Code

public function testExtend(string $expected, string $namespace, string $extend) : void {
    $additional_class_loader = new ClassLoader();
    $additional_class_loader->addPsr4("Drupal\\core_fake\\Driver\\Database\\coreFake\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFake");
    $additional_class_loader->addPsr4("Drupal\\core_fake\\Driver\\Database\\CoreFakeWithAllCustomClasses\\", __DIR__ . "/../../../../../tests/fixtures/database_drivers/module/core_fake/src/Driver/Database/CoreFakeWithAllCustomClasses");
    $additional_class_loader->register(TRUE);
    $mock_pdo = $this->createMock(StubPDO::class);
    $connection = new StubConnection($mock_pdo, [
        'namespace' => $namespace,
    ]);
    // Tests the method \Drupal\Core\Database\Query\Select::extend().
    $select = $connection->select('test')
        ->extend($extend);
    $this->assertEquals($expected, get_class($select));
    // Get an instance of the class \Drupal\Core\Database\Query\SelectExtender.
    $select_extender = $connection->select('test')
        ->extend(SelectExtender::class);
    $this->assertEquals(SelectExtender::class, get_class($select_extender));
    // Tests the method \Drupal\Core\Database\Query\SelectExtender::extend().
    $select_extender_extended = $select_extender->extend($extend);
    $this->assertEquals($expected, get_class($select_extender_extended));
}

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