function AutowiredInstanceTraitTest::testAutowireMissingRequiredService

Same name and namespace in other branches
  1. main core/tests/Drupal/Tests/Core/DependencyInjection/AutowiredInstanceTraitTest.php \Drupal\Tests\Core\DependencyInjection\AutowiredInstanceTraitTest::testAutowireMissingRequiredService()

Tests exception for missing required service.

File

core/tests/Drupal/Tests/Core/DependencyInjection/AutowiredInstanceTraitTest.php, line 69

Class

AutowiredInstanceTraitTest
Tests \Drupal\Core\DependencyInjection\AutowiredInstanceTrait.

Namespace

Drupal\Tests\Core\DependencyInjection

Code

public function testAutowireMissingRequiredService() : void {
  $container = $this->createStub(ContainerInterface::class);
  $container->method('has')
    ->willReturn(FALSE);
  $this->expectException(AutowiringFailedException::class);
  $this->expectExceptionMessage('Cannot autowire service "stdClass": argument "$service" of method "Drupal\\Tests\\Core\\DependencyInjection\\AutowireRequiredServiceTestClass::__construct()". Check that either the argument type is correct or the Autowire attribute is passed a valid identifier. Otherwise configure its value explicitly if possible.');
  AutowireRequiredServiceTestClass::createInstanceAutowired($container);
}

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