Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
RelationCompositeTest.php
Go to the documentation of this file.
1 <?php
8 
12 class RelationCompositeTest extends \PHPUnit\Framework\TestCase
13 {
18 
22  protected $modelMock;
23 
28 
32  protected $eventManagerMock;
33 
34  protected function setUp()
35  {
36  $this->modelMock = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
37  ->disableOriginalConstructor()
38  ->setMethods(
39  [
40  'getEventPrefix'
41  ]
42  )
43  ->getMockForAbstractClass();
44  $this->relationProcessorMock = $this->getMockBuilder(\Magento\Framework\Model\AbstractModel::class)
45  ->disableOriginalConstructor()
46  ->getMockForAbstractClass();
47  $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
48  ->disableOriginalConstructor()
49  ->getMockForAbstractClass();
50  $this->relationProcessorMock = $this->getMockBuilder(
51  \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationInterface::class
52  )->disableOriginalConstructor()->getMockForAbstractClass();
53 
54  $this->entityRelationComposite = new \Magento\Framework\Model\ResourceModel\Db\VersionControl\RelationComposite(
55  $this->eventManagerMock,
56  [
57  'default' => $this->relationProcessorMock
58  ]
59  );
60  }
61 
62  public function testProcessRelations()
63  {
64  $this->relationProcessorMock->expects($this->once())
65  ->method('processRelation')
66  ->with($this->modelMock);
67  $this->modelMock->expects($this->once())
68  ->method('getEventPrefix')
69  ->willReturn('custom_event_prefix');
70  $this->eventManagerMock->expects($this->once())
71  ->method('dispatch')
72  ->with(
73  'custom_event_prefix_process_relation',
74  [
75  'object' => $this->modelMock
76  ]
77  );
78  $this->entityRelationComposite->processRelations($this->modelMock);
79  }
80 }