Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateEntityRowTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class UpdateEntityRowTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
20  protected $metadataPoolMock;
21 
22  protected function setUp()
23  {
24  $objectManager = new ObjectManager($this);
25  $this->metadataPoolMock = $this->getMockBuilder(\Magento\Framework\EntityManager\MetadataPool::class)
26  ->disableOriginalConstructor()
27  ->getMock();
28  $this->model = $objectManager->getObject(
29  \Magento\Framework\Model\ResourceModel\Db\UpdateEntityRow::class,
30  ['metadataPool' => $this->metadataPoolMock]
31  );
32  }
33 
34  public function testExecute()
35  {
36  $entityType = 'Test_Entity';
37  $entityTable = 'test_table_1';
38  $linkField = 'test_table_2';
39  $describeTable = [
40  [
41  'DEFAULT' => 'CURRENT_TIMESTAMP'
42  ],
43  [
44  'DEFAULT' => 'NOT_CURRENT_TIMESTAMP',
45  'IDENTITY' => false,
46  'COLUMN_NAME' => 'test_column_name'
47  ]
48  ];
49  $data = [$linkField => $linkField, 'test_column_name' => 'test_column_name'];
50  $output['test_column_name'] = 'test_column_name';
51  $expectedResult = true;
52 
53  $entityMetadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadata::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56  $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
57  ->disableOriginalConstructor()
58  ->getMock();
59  $connectionMock->expects($this->once())
60  ->method('describeTable')
61  ->willReturn($describeTable);
62  $connectionMock->expects($this->once())
63  ->method('update')
64  ->with($entityTable, $output, [$linkField . ' = ?' => $data[$linkField]])
65  ->willReturn($expectedResult);
66 
67  $entityMetadataMock->expects($this->any())
68  ->method('getEntityConnection')
69  ->willReturn($connectionMock);
70  $entityMetadataMock->expects($this->any())
71  ->method('getEntityTable')
72  ->willReturn($entityTable);
73  $entityMetadataMock->expects($this->any())
74  ->method('getLinkField')
75  ->willReturn($linkField);
76 
77  $this->metadataPoolMock->expects($this->once())
78  ->method('getMetadata')
79  ->with($entityType)
80  ->willReturn($entityMetadataMock);
81  $result = $this->model->execute($entityType, $data);
82  $this->assertEquals($expectedResult, $result);
83  }
84 }
$objectManager
Definition: bootstrap.php:17
$entityTable
Definition: tablerates.php:11