Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BulkSummaryMapperTest.php
Go to the documentation of this file.
1 <?php
8 
10 
14 class BulkSummaryMapperTest extends \PHPUnit\Framework\TestCase
15 {
19  private $model;
20 
24  private $metadataPoolMock;
25 
29  private $resourceConnectionMock;
30 
34  private $entityMetadataMock;
35 
39  private $connectionMock;
40 
44  private $selectMock;
45 
46  protected function setUp()
47  {
48  $this->metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
49  $this->resourceConnectionMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
50  $this->entityMetadataMock = $this->createMock(\Magento\Framework\EntityManager\EntityMetadataInterface::class);
51  $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
52  $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
53  $this->model = new BulkSummaryMapper(
54  $this->metadataPoolMock,
55  $this->resourceConnectionMock
56  );
57  }
58 
64  public function testEntityToDatabase($identifier, $result)
65  {
66  $entityType = 'entityType';
67  $data = ['uuid' => 'bulk-1'];
68  $connectionName = 'connection_name';
69  $entityTable = 'table_name';
70  $this->metadataPoolMock
71  ->expects($this->once())
72  ->method('getMetadata')
73  ->with($entityType)
74  ->willReturn($this->entityMetadataMock);
75  $this->entityMetadataMock
76  ->expects($this->once())
77  ->method('getEntityConnectionName')
78  ->willReturn($connectionName);
79 
80  $this->resourceConnectionMock
81  ->expects($this->once())
82  ->method('getConnectionByName')
83  ->with($connectionName)
84  ->willReturn($this->connectionMock);
85  $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
86  $this->entityMetadataMock->expects($this->once())->method('getEntityTable')->willReturn($entityTable);
87  $this->selectMock->expects($this->once())->method('from')->with($entityTable, 'id')->willReturnSelf();
88  $this->selectMock->expects($this->once())->method('where')->with("uuid = ?", 'bulk-1')->willReturnSelf();
89  $this->connectionMock
90  ->expects($this->once())
91  ->method('fetchOne')
92  ->with($this->selectMock)
93  ->willReturn($identifier);
94 
95  $this->assertEquals($result, $this->model->entityToDatabase($entityType, $data));
96  }
97 
102  {
103  return [
104  [1, ['uuid' => 'bulk-1', 'id' => 1]],
105  [false, ['uuid' => 'bulk-1']]
106  ];
107  }
108 }
$entityTable
Definition: tablerates.php:11