BulkSummaryMapperTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Test\Unit\Model\Entity;
  7. use Magento\AsynchronousOperations\Model\Entity\BulkSummaryMapper;
  8. /**
  9. * Class BulkSummaryMapperTest
  10. */
  11. class BulkSummaryMapperTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\AsynchronousOperations\Model\Entity\BulkSummaryMapper
  15. */
  16. private $model;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $metadataPoolMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $resourceConnectionMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $entityMetadataMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. private $connectionMock;
  33. /**
  34. * @var \PHPUnit_Framework_MockObject_MockObject
  35. */
  36. private $selectMock;
  37. protected function setUp()
  38. {
  39. $this->metadataPoolMock = $this->createMock(\Magento\Framework\EntityManager\MetadataPool::class);
  40. $this->resourceConnectionMock = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
  41. $this->entityMetadataMock = $this->createMock(\Magento\Framework\EntityManager\EntityMetadataInterface::class);
  42. $this->connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
  43. $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  44. $this->model = new BulkSummaryMapper(
  45. $this->metadataPoolMock,
  46. $this->resourceConnectionMock
  47. );
  48. }
  49. /**
  50. * @param int $identifier
  51. * @param array|false $result
  52. * @dataProvider entityToDatabaseDataProvider
  53. */
  54. public function testEntityToDatabase($identifier, $result)
  55. {
  56. $entityType = 'entityType';
  57. $data = ['uuid' => 'bulk-1'];
  58. $connectionName = 'connection_name';
  59. $entityTable = 'table_name';
  60. $this->metadataPoolMock
  61. ->expects($this->once())
  62. ->method('getMetadata')
  63. ->with($entityType)
  64. ->willReturn($this->entityMetadataMock);
  65. $this->entityMetadataMock
  66. ->expects($this->once())
  67. ->method('getEntityConnectionName')
  68. ->willReturn($connectionName);
  69. $this->resourceConnectionMock
  70. ->expects($this->once())
  71. ->method('getConnectionByName')
  72. ->with($connectionName)
  73. ->willReturn($this->connectionMock);
  74. $this->connectionMock->expects($this->once())->method('select')->willReturn($this->selectMock);
  75. $this->entityMetadataMock->expects($this->once())->method('getEntityTable')->willReturn($entityTable);
  76. $this->selectMock->expects($this->once())->method('from')->with($entityTable, 'id')->willReturnSelf();
  77. $this->selectMock->expects($this->once())->method('where')->with("uuid = ?", 'bulk-1')->willReturnSelf();
  78. $this->connectionMock
  79. ->expects($this->once())
  80. ->method('fetchOne')
  81. ->with($this->selectMock)
  82. ->willReturn($identifier);
  83. $this->assertEquals($result, $this->model->entityToDatabase($entityType, $data));
  84. }
  85. /**
  86. * @return array
  87. */
  88. public function entityToDatabaseDataProvider()
  89. {
  90. return [
  91. [1, ['uuid' => 'bulk-1', 'id' => 1]],
  92. [false, ['uuid' => 'bulk-1']]
  93. ];
  94. }
  95. }