OperationManagementTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Model;
  7. use Magento\AsynchronousOperations\Api\Data\OperationInterface;
  8. use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
  9. use Magento\Framework\EntityManager\EntityManager;
  10. class OperationManagementTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\AsynchronousOperations\Model\OperationManagement
  14. */
  15. private $model;
  16. /**
  17. * @var \Magento\AsynchronousOperations\Model\BulkStatus
  18. */
  19. private $bulkStatusManagement;
  20. /**
  21. * @var OperationInterfaceFactory
  22. */
  23. private $operationFactory;
  24. /**
  25. * @var EntityManager
  26. */
  27. private $entityManager;
  28. protected function setUp()
  29. {
  30. $this->model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  31. \Magento\AsynchronousOperations\Model\OperationManagement::class
  32. );
  33. $this->bulkStatusManagement = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  34. \Magento\AsynchronousOperations\Model\BulkStatus::class
  35. );
  36. $this->operationFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  37. OperationInterfaceFactory::class
  38. );
  39. $this->entityManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
  40. EntityManager::class
  41. );
  42. }
  43. /**
  44. * @magentoDataFixture Magento/AsynchronousOperations/_files/bulk.php
  45. */
  46. public function testGetBulkStatus()
  47. {
  48. $operations = $this->bulkStatusManagement->getFailedOperationsByBulkId('bulk-uuid-5', 3);
  49. if (empty($operations)) {
  50. $this->fail('Operation doesn\'t exist');
  51. }
  52. /** @var OperationInterface $operation */
  53. $operation = array_shift($operations);
  54. $operationId = $operation->getId();
  55. $this->assertTrue($this->model->changeOperationStatus($operationId, OperationInterface::STATUS_TYPE_OPEN));
  56. /** @var OperationInterface $updatedOperation */
  57. $updatedOperation = $this->operationFactory->create();
  58. $this->entityManager->load($updatedOperation, $operationId);
  59. $this->assertEquals(OperationInterface::STATUS_TYPE_OPEN, $updatedOperation->getStatus());
  60. $this->assertEquals(null, $updatedOperation->getResultMessage());
  61. $this->assertEquals(null, $updatedOperation->getSerializedData());
  62. }
  63. }