function AutowiredInstanceTraitTest::testAutowireMissingRequiredService
Same name and namespace in other branches
- 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
Namespace
Drupal\Tests\Core\DependencyInjectionCode
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.