class AttributeBridgeDecoratorTest

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Component/Plugin/Discovery/AttributeBridgeDecoratorTest.php \Drupal\Tests\Component\Plugin\Discovery\AttributeBridgeDecoratorTest

@coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator @group Plugin

Hierarchy

Expanded class hierarchy of AttributeBridgeDecoratorTest

File

core/tests/Drupal/Tests/Component/Plugin/Discovery/AttributeBridgeDecoratorTest.php, line 17

Namespace

Drupal\Tests\Component\Plugin\Discovery
View source
class AttributeBridgeDecoratorTest extends TestCase {
    
    /**
     * @covers ::getDefinitions
     */
    public function testGetDefinitions() : void {
        // Normally the attribute classes would be autoloaded.
        include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';
        include_once __DIR__ . '/../../../../../fixtures/plugins/Plugin/PluginNamespace/AttributeDiscoveryTest1.php';
        $definitions = [];
        $definitions['object'] = new ObjectDefinition([
            'id' => 'foo',
        ]);
        $definitions['array'] = [
            'id' => 'bar',
            'class' => 'com\\example\\PluginNamespace\\AttributeDiscoveryTest1',
        ];
        $discovery = $this->createMock(DiscoveryInterface::class);
        $discovery->expects($this->any())
            ->method('getDefinitions')
            ->willReturn($definitions);
        $decorator = new AttributeBridgeDecorator($discovery, TestAttribute::class);
        $expected = [
            'object' => new ObjectDefinition([
                'id' => 'foo',
            ]),
            'array' => (new ObjectDefinition([
                'id' => 'bar',
            ]))->setClass('com\\example\\PluginNamespace\\AttributeDiscoveryTest1'),
        ];
        $this->assertEquals($expected, $decorator->getDefinitions());
    }
    
    /**
     * Tests that the decorator of other methods works.
     *
     * @covers ::__call
     */
    public function testOtherMethod() : void {
        // Normally the attribute classes would be autoloaded.
        include_once __DIR__ . '/../../../../../fixtures/plugins/CustomPlugin.php';
        include_once __DIR__ . '/../../../../../fixtures/plugins/Plugin/PluginNamespace/AttributeDiscoveryTest1.php';
        $discovery = $this->createMock(ExtendedDiscoveryInterface::class);
        $discovery->expects($this->exactly(2))
            ->method('otherMethod')
            ->willReturnCallback(fn($id) => $id === 'foo');
        $decorator = new AttributeBridgeDecorator($discovery, TestAttribute::class);
        $this->assertTrue($decorator->otherMethod('foo'));
        $this->assertFalse($decorator->otherMethod('bar'));
    }

}

Members

Title Sort descending Modifiers Object type Summary
AttributeBridgeDecoratorTest::testGetDefinitions public function @covers ::getDefinitions
AttributeBridgeDecoratorTest::testOtherMethod public function Tests that the decorator of other methods works.

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