function AutowireTest::testAutowire

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php \Drupal\KernelTests\Core\DependencyInjection\AutowireTest::testAutowire()
  2. 10 core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php \Drupal\KernelTests\Core\DependencyInjection\AutowireTest::testAutowire()

Tests that 'autowire_test.service' has its dependencies injected.

File

core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.php, line 36

Class

AutowireTest
Tests auto-wiring services.

Namespace

Drupal\KernelTests\Core\DependencyInjection

Code

public function testAutowire() : void {
    $service = $this->container
        ->get(TestService::class);
    // Ensure an autowired interface works.
    $this->assertInstanceOf(TestInjection::class, $service->getTestInjection());
    $this->assertInstanceOf(TestInjection3::class, $service->getTestInjection3());
    // Ensure an autowired class works.
    $this->assertInstanceOf(TestInjection2::class, $service->getTestInjection2());
    // Ensure an autowired core class works.
    $this->assertInstanceOf(Connection::class, $service->getDatabase());
    // Ensure an autowired core synthetic class works.
    $this->assertInstanceOf(DrupalKernelInterface::class, $service->getKernel());
}

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