Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteEntityRowTest.php
Go to the documentation of this file.
1 <?php
7 
11 class DeleteEntityRowTest extends \PHPUnit\Framework\TestCase
12 {
18  protected $subject;
19 
23  protected $connection;
24 
28  protected $metadataPool;
29 
30  protected function setUp()
31  {
32  $this->connection = $this->getMockForAbstractClass(
33  \Magento\Framework\DB\Adapter\AdapterInterface::class,
34  [],
35  '',
36  false,
37  false,
38  true,
39  []
40  );
41 
42  $metadata = $this->createMock(\Magento\Framework\EntityManager\EntityMetadata::class);
43 
44  $metadata->expects($this->any())
45  ->method('getLinkField')
46  ->willReturn('entity_id');
47 
48  $metadata->expects($this->any())
49  ->method('getEntityTable')
50  ->willReturn('entity_table');
51 
52  $metadata->expects($this->any())
53  ->method('getEntityConnection')
54  ->willReturn($this->connection);
55 
56  $this->metadataPool = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
57 
58  $this->metadataPool->expects($this->any())
59  ->method('getMetadata')
60  ->with('Test\Entity\Type')
61  ->willReturn($metadata);
62 
63  $this->subject = new \Magento\Framework\Model\ResourceModel\Db\DeleteEntityRow(
64  $this->metadataPool
65  );
66  }
67 
68  public function testExecute()
69  {
70  $data = [
71  'entity_id' => 1
72  ];
73 
74  $this->connection->expects($this->once())
75  ->method('delete')
76  ->with('entity_table', ['entity_id = ?' => 1]);
77 
78  $this->subject->execute('Test\Entity\Type', $data);
79  }
80 }