You are here

public function ContainerTest::testGetForFactoryClass in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testGetForFactoryClass()

Tests that Container::get() for factories via class works (Symfony 2.7.0).

@covers ::get @covers ::createService

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 482
Contains \Drupal\Tests\Component\DependencyInjection\ContainerTest.

Class

ContainerTest
@coversDefaultClass \Drupal\Component\DependencyInjection\Container @group DependencyInjection

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testGetForFactoryClass() {
  $service = $this->container
    ->get('service.provider');
  $factory_service = $this->container
    ->get('factory_class');
  $this
    ->assertInstanceOf(get_class($service), $factory_service);
  $this
    ->assertEquals('bar', $factory_service
    ->getSomeParameter(), 'Correct parameter was passed via the factory class instantiation.');
  $this
    ->assertEquals($this->container, $factory_service
    ->getContainer(), 'Container was injected via setter injection.');
}