DetailsTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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\Operation;
  7. use Magento\Framework\Bulk\OperationInterface;
  8. class DetailsTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /**
  11. * @var \PHPUnit_Framework_MockObject_MockObject
  12. */
  13. private $bulkStatusMock;
  14. /**
  15. * @var \Magento\AsynchronousOperations\Model\Operation\Details
  16. */
  17. private $model;
  18. protected function setUp()
  19. {
  20. $this->bulkStatusMock = $this->getMockBuilder(\Magento\Framework\Bulk\BulkStatusInterface::class)
  21. ->getMock();
  22. $this->model = new \Magento\AsynchronousOperations\Model\Operation\Details($this->bulkStatusMock);
  23. }
  24. public function testGetDetails()
  25. {
  26. $uuid = 'some_uuid_string';
  27. $completed = 100;
  28. $failedRetriable = 23;
  29. $failedNotRetriable = 45;
  30. $open = 303;
  31. $rejected = 0;
  32. $expectedResult = [
  33. 'operations_total' => $completed + $failedRetriable + $failedNotRetriable + $open,
  34. 'operations_successful' => $completed,
  35. 'operations_failed' => $failedRetriable + $failedNotRetriable,
  36. 'failed_retriable' => $failedRetriable,
  37. 'failed_not_retriable' => $failedNotRetriable,
  38. 'rejected' => $rejected,
  39. 'open' => $open,
  40. ];
  41. $this->bulkStatusMock->method('getOperationsCountByBulkIdAndStatus')
  42. ->willReturnMap([
  43. [$uuid, OperationInterface::STATUS_TYPE_COMPLETE, $completed],
  44. [$uuid, OperationInterface::STATUS_TYPE_RETRIABLY_FAILED, $failedRetriable],
  45. [$uuid, OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED, $failedNotRetriable],
  46. [$uuid, OperationInterface::STATUS_TYPE_OPEN, $open],
  47. [$uuid, OperationInterface::STATUS_TYPE_REJECTED, $rejected],
  48. ]);
  49. $result = $this->model->getDetails($uuid);
  50. $this->assertEquals($expectedResult, $result);
  51. }
  52. }