function StaticDiscoveryDecoratorTest::testCall

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php \Drupal\Tests\Component\Plugin\Discovery\StaticDiscoveryDecoratorTest::testCall()
  2. 8.9.x core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php \Drupal\Tests\Component\Plugin\Discovery\StaticDiscoveryDecoratorTest::testCall()
  3. 10 core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php \Drupal\Tests\Component\Plugin\Discovery\StaticDiscoveryDecoratorTest::testCall()

@covers ::__call @dataProvider providerCall

File

core/tests/Drupal/Tests/Component/Plugin/Discovery/StaticDiscoveryDecoratorTest.php, line 192

Class

StaticDiscoveryDecoratorTest
@group Plugin @coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Component%21Plugin%21Discovery%21StaticDiscoveryDecorator.php/class/StaticDiscoveryDecorator/11.x" title="A decorator that allows manual registration of undiscoverable definitions." class="local">\Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator</a>

Namespace

Drupal\Tests\Component\Plugin\Discovery

Code

public function testCall($method, $args) : void {
    // Mock a decorated object.
    $mock_decorated = $this->getMockBuilder(StaticDiscoveryTestDecoratedClass::class)
        ->onlyMethods([
        $method,
    ])
        ->getMock();
    // Our mocked method will return any arguments sent to it.
    $mock_decorated->expects($this->once())
        ->method($method)
        ->willReturnCallback(function () {
        return \func_get_args();
    });
    // Create the decorator.
    $decorator = new StaticDiscoveryDecorator($mock_decorated);
    // Exercise __call on the decorator.
    $this->assertEquals($args, \call_user_func_array([
        $decorator,
        $method,
    ], $args));
}

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