function ContainerTest::testIterator

Same name in other branches
  1. 11.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testIterator()

Tests that service iterators are lazily instantiated.

File

core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php, line 703

Class

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

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testIterator() : void {
    $iterator = $this->container
        ->get('service_iterator')
        ->getArguments()[0];
    $this->assertIsIterable($iterator);
    $this->assertFalse($this->container
        ->initialized('other.service'));
    foreach ($iterator as $service) {
        $this->assertIsObject($service);
    }
    $this->assertTrue($this->container
        ->initialized('other.service'));
}

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