diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationStatusValidatorTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationStatusValidatorTest.php new file mode 100644 index 0000000000000..2209564d03aee --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/OperationStatusValidatorTest.php @@ -0,0 +1,155 @@ +operationStatusPool = $this->getMockBuilder(OperationStatusPool::class) + ->disableOriginalConstructor() + ->getMock(); + + $objectManager = new ObjectManager($this); + + $this->operationStatusValidator = $objectManager->getObject( + OperationStatusValidator::class, + [ + 'operationStatusPool' => $this->operationStatusPool + ] + ); + + $this->operation = $objectManager->getObject( + Operation::class, + [ + 'operationStatusValidator' => $this->operationStatusValidator + ] + ); + } + + /** + * @param string $status + * @param array $statusPool + * @param string $expectedResult + * @dataProvider dataProviderForTestSetStatus + */ + public function testSetStatus ( + string $status, + array $statusPool, + string $expectedResult + ) { + $this->operationStatusPool + ->expects($this->any()) + ->method('getStatuses') + ->willReturn($statusPool); + + try { + $this->operation->setStatus($status); + $this->assertEquals($expectedResult, $this->operation->getStatus()); + } catch (\Exception $exception) { + $this->assertEquals($expectedResult, $exception->getMessage()); + } + } + + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function dataProviderForTestSetStatus() + { + return [ + [ + 'status' => 0, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 'Invalid Operation Status.' + ], + [ + 'status' => 1, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 1 + ], + [ + 'status' => 2, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 2 + ], + [ + 'status' => 3, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 3 + ], + [ + 'status' => 4, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 4 + ], + [ + 'status' => 5, + 'statusPool' => [ + 'complete' => 1, + 'retriablyFailed' => 2, + 'notRetriablyFailed' => 3, + 'open' => 4, + 'rejected' => 5 + ], + 'expectedResult' => 5 + ] + ]; + } +}