You are here

public function ServicesDefaultsTest::testAutowiring in Drupal 10

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

File

core/tests/Drupal/KernelTests/Core/DependencyInjection/ServicesDefaultsTest.php, line 20

Class

ServicesDefaultsTest
Tests services _defaults definition.

Namespace

Drupal\KernelTests\Core\DependencyInjection

Code

public function testAutowiring() {

  // Ensure interface autowiring works.
  $this
    ->assertSame($this->container
    ->get('Drupal\\services_defaults_test\\TestInjection'), $this->container
    ->get('Drupal\\services_defaults_test\\TestService')
    ->getTestInjection());

  // Ensure defaults autowire works.
  $this
    ->assertSame($this->container
    ->get('Drupal\\services_defaults_test\\TestInjection2'), $this->container
    ->get('Drupal\\services_defaults_test\\TestService')
    ->getTestInjection2());

  // Ensure that disabling autowiring works.
  $this
    ->assertNotSame($this->container
    ->get('Drupal\\services_defaults_test\\TestInjection'), $this->container
    ->get('services_default_test.no_autowire')
    ->getTestInjection());
  $this
    ->assertSame($this->container
    ->get('services_default_test.no_autowire.arg'), $this->container
    ->get('services_default_test.no_autowire')
    ->getTestInjection());
  $this
    ->assertSame($this->container
    ->get('Drupal\\services_defaults_test\\TestInjection2'), $this->container
    ->get('services_default_test.no_autowire')
    ->getTestInjection2());
}