62d3c84005c775386867089e7e85a4616ed48444
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Annotation / Plugin / Discovery / AnnotationBridgeDecoratorTest.php
1 <?php
2
3 namespace Drupal\Tests\Component\Annotation\Plugin\Discovery;
4
5 use Drupal\Component\Annotation\Plugin;
6 use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator;
7 use Drupal\Component\Plugin\Definition\PluginDefinition;
8 use Drupal\Component\Plugin\Discovery\DiscoveryInterface;
9 use PHPUnit\Framework\TestCase;
10
11 /**
12  * @coversDefaultClass \Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator
13  * @group Plugin
14  */
15 class AnnotationBridgeDecoratorTest extends TestCase {
16
17   /**
18    * @covers ::getDefinitions
19    */
20   public function testGetDefinitions() {
21     $definitions = [];
22     $definitions['object'] = new ObjectDefinition(['id' => 'foo']);
23     $definitions['array'] = ['id' => 'bar'];
24     $discovery = $this->prophesize(DiscoveryInterface::class);
25     $discovery->getDefinitions()->willReturn($definitions);
26
27     $decorator = new AnnotationBridgeDecorator($discovery->reveal(), TestAnnotation::class);
28
29     $expected = [
30       'object' => new ObjectDefinition(['id' => 'foo']),
31       'array' => new ObjectDefinition(['id' => 'bar']),
32     ];
33     $this->assertEquals($expected, $decorator->getDefinitions());
34   }
35
36 }
37
38 class TestAnnotation extends Plugin {
39
40   /**
41    * {@inheritdoc}
42    */
43   public function get() {
44     return new ObjectDefinition($this->definition);
45   }
46
47 }
48 class ObjectDefinition extends PluginDefinition {
49
50   /**
51    * ObjectDefinition constructor.
52    *
53    * @param array $definition
54    */
55   public function __construct(array $definition) {
56     foreach ($definition as $property => $value) {
57       $this->{$property} = $value;
58     }
59   }
60
61 }