function ContainerTest::testHas

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testHas()
  2. 10 core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testHas()
  3. 11.x core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php \Drupal\Tests\Component\DependencyInjection\ContainerTest::testHas()

Tests that Container::has() works properly.

@covers ::has

File

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

Class

ContainerTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21DependencyInjection%21Container.php/class/Container/9" title="Provides a container optimized for Drupal&#039;s needs." class="local">\Drupal\Component\DependencyInjection\Container</a> @group DependencyInjection

Namespace

Drupal\Tests\Component\DependencyInjection

Code

public function testHas() {
    $this->assertTrue($this->container
        ->has('other.service'));
    $this->assertFalse($this->container
        ->has('another.service'));
    // Set the service manually, ensure that its also respected.
    $mock_service = new MockService();
    $this->container
        ->set('another.service', $mock_service);
    $this->assertTrue($this->container
        ->has('another.service'));
}

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