function DiscoveryTraitTest::testHasDefinition

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php \Drupal\Tests\Component\Plugin\Discovery\DiscoveryTraitTest::testHasDefinition()
  2. 8.9.x core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php \Drupal\Tests\Component\Plugin\Discovery\DiscoveryTraitTest::testHasDefinition()
  3. 11.x core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php \Drupal\Tests\Component\Plugin\Discovery\DiscoveryTraitTest::testHasDefinition()

@covers ::hasDefinition @dataProvider providerHasDefinition

File

core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryTraitTest.php, line 134

Class

DiscoveryTraitTest
@group Plugin @coversDefaultClass \Drupal\Component\Plugin\Discovery\DiscoveryTrait

Namespace

Drupal\Tests\Component\Plugin\Discovery

Code

public function testHasDefinition($expected, $plugin_id) : void {
    $trait = $this->getMockBuilder(DiscoveryTraitMockableClass::class)
        ->onlyMethods([
        'getDefinition',
    ])
        ->getMock();
    // Set up our mocked getDefinition() to return TRUE for 'valid' and FALSE
    // for 'not_valid'.
    $trait->expects($this->once())
        ->method('getDefinition')
        ->willReturnMap([
        [
            'valid',
            FALSE,
            TRUE,
        ],
        [
            'not_valid',
            FALSE,
            FALSE,
        ],
    ]);
    // Call hasDefinition().
    $this->assertSame($expected, $trait->hasDefinition($plugin_id));
}

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