|
| 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; |
| 7 | + |
| 8 | +use Magento\AsynchronousOperations\Model\OperationStatusValidator; |
| 9 | +use Magento\AsynchronousOperations\Model\Operation; |
| 10 | +use Magento\AsynchronousOperations\Model\OperationStatusPool; |
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** |
| 15 | + * Class OperationStatusValidatorTest |
| 16 | + */ |
| 17 | +class OperationStatusValidatorTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var OperationStatusPool |
| 21 | + */ |
| 22 | + private $operationStatusPool; |
| 23 | + |
| 24 | + /** |
| 25 | + * @var OperationStatusValidator |
| 26 | + */ |
| 27 | + private $operationStatusValidator; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var Operation |
| 31 | + */ |
| 32 | + private $operation; |
| 33 | + |
| 34 | + protected function setUp() |
| 35 | + { |
| 36 | + $this->operationStatusPool = $this->getMockBuilder(OperationStatusPool::class) |
| 37 | + ->disableOriginalConstructor() |
| 38 | + ->getMock(); |
| 39 | + |
| 40 | + $objectManager = new ObjectManager($this); |
| 41 | + |
| 42 | + $this->operationStatusValidator = $objectManager->getObject( |
| 43 | + OperationStatusValidator::class, |
| 44 | + [ |
| 45 | + 'operationStatusPool' => $this->operationStatusPool |
| 46 | + ] |
| 47 | + ); |
| 48 | + |
| 49 | + $this->operation = $objectManager->getObject( |
| 50 | + Operation::class, |
| 51 | + [ |
| 52 | + 'operationStatusValidator' => $this->operationStatusValidator |
| 53 | + ] |
| 54 | + ); |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * @param string $status |
| 59 | + * @param array $statusPool |
| 60 | + * @param string $expectedResult |
| 61 | + * @dataProvider dataProviderForTestSetStatus |
| 62 | + */ |
| 63 | + public function testSetStatus ( |
| 64 | + string $status, |
| 65 | + array $statusPool, |
| 66 | + string $expectedResult |
| 67 | + ) { |
| 68 | + $this->operationStatusPool |
| 69 | + ->expects($this->any()) |
| 70 | + ->method('getStatuses') |
| 71 | + ->willReturn($statusPool); |
| 72 | + |
| 73 | + try { |
| 74 | + $this->operation->setStatus($status); |
| 75 | + $this->assertEquals($expectedResult, $this->operation->getStatus()); |
| 76 | + } catch (\Exception $exception) { |
| 77 | + $this->assertEquals($expectedResult, $exception->getMessage()); |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 83 | + */ |
| 84 | + public function dataProviderForTestSetStatus() |
| 85 | + { |
| 86 | + return [ |
| 87 | + [ |
| 88 | + 'status' => 0, |
| 89 | + 'statusPool' => [ |
| 90 | + 'complete' => 1, |
| 91 | + 'retriablyFailed' => 2, |
| 92 | + 'notRetriablyFailed' => 3, |
| 93 | + 'open' => 4, |
| 94 | + 'rejected' => 5 |
| 95 | + ], |
| 96 | + 'expectedResult' => 'Invalid Operation Status.' |
| 97 | + ], |
| 98 | + [ |
| 99 | + 'status' => 1, |
| 100 | + 'statusPool' => [ |
| 101 | + 'complete' => 1, |
| 102 | + 'retriablyFailed' => 2, |
| 103 | + 'notRetriablyFailed' => 3, |
| 104 | + 'open' => 4, |
| 105 | + 'rejected' => 5 |
| 106 | + ], |
| 107 | + 'expectedResult' => 1 |
| 108 | + ], |
| 109 | + [ |
| 110 | + 'status' => 2, |
| 111 | + 'statusPool' => [ |
| 112 | + 'complete' => 1, |
| 113 | + 'retriablyFailed' => 2, |
| 114 | + 'notRetriablyFailed' => 3, |
| 115 | + 'open' => 4, |
| 116 | + 'rejected' => 5 |
| 117 | + ], |
| 118 | + 'expectedResult' => 2 |
| 119 | + ], |
| 120 | + [ |
| 121 | + 'status' => 3, |
| 122 | + 'statusPool' => [ |
| 123 | + 'complete' => 1, |
| 124 | + 'retriablyFailed' => 2, |
| 125 | + 'notRetriablyFailed' => 3, |
| 126 | + 'open' => 4, |
| 127 | + 'rejected' => 5 |
| 128 | + ], |
| 129 | + 'expectedResult' => 3 |
| 130 | + ], |
| 131 | + [ |
| 132 | + 'status' => 4, |
| 133 | + 'statusPool' => [ |
| 134 | + 'complete' => 1, |
| 135 | + 'retriablyFailed' => 2, |
| 136 | + 'notRetriablyFailed' => 3, |
| 137 | + 'open' => 4, |
| 138 | + 'rejected' => 5 |
| 139 | + ], |
| 140 | + 'expectedResult' => 4 |
| 141 | + ], |
| 142 | + [ |
| 143 | + 'status' => 5, |
| 144 | + 'statusPool' => [ |
| 145 | + 'complete' => 1, |
| 146 | + 'retriablyFailed' => 2, |
| 147 | + 'notRetriablyFailed' => 3, |
| 148 | + 'open' => 4, |
| 149 | + 'rejected' => 5 |
| 150 | + ], |
| 151 | + 'expectedResult' => 5 |
| 152 | + ] |
| 153 | + ]; |
| 154 | + } |
| 155 | +} |
0 commit comments