StatusResolverTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Model\Order;
  7. use Magento\Payment\Model\MethodInterface;
  8. use Magento\Sales\Api\Data\OrderInterface;
  9. use Magento\Sales\Api\Data\OrderPaymentInterface;
  10. use Magento\Sales\Model\Order\Config;
  11. use Magento\Sales\Model\Order\StatusResolver;
  12. use PHPUnit_Framework_MockObject_MockObject as MockObject;
  13. class StatusResolverTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @param OrderInterface|MockObject $order
  17. * @param string $expectedReturn
  18. *
  19. * @dataProvider statesDataProvider
  20. */
  21. public function testGetOrderStatusByState($order, $expectedReturn)
  22. {
  23. $actualReturn = (new StatusResolver())->getOrderStatusByState($order, 'new');
  24. self::assertEquals($expectedReturn, $actualReturn);
  25. }
  26. /**
  27. * @return array
  28. */
  29. public function statesDataProvider()
  30. {
  31. return [
  32. [
  33. $this->getOrder('pending', ['pending' => 'pending']),
  34. 'pending'
  35. ],
  36. [
  37. $this->getOrder('processing', ['pending' => 'pending']),
  38. 'processing'
  39. ],
  40. ];
  41. }
  42. /**
  43. * @param string $newOrderStatus
  44. * @param array $stateStatuses
  45. * @return OrderInterface|MockObject
  46. */
  47. private function getOrder($newOrderStatus, $stateStatuses)
  48. {
  49. $order = $this->getMockBuilder(OrderInterface::class)
  50. ->setMethods(['getConfig'])
  51. ->getMockForAbstractClass();
  52. $order->method('getPayment')
  53. ->willReturn($this->getPayment($newOrderStatus));
  54. $order->method('getConfig')
  55. ->willReturn($this->getConfig($stateStatuses));
  56. return $order;
  57. }
  58. /**
  59. * @param string $newOrderStatus
  60. * @return MockObject
  61. */
  62. private function getPayment($newOrderStatus)
  63. {
  64. $payment = $this->getMockBuilder(OrderPaymentInterface::class)
  65. ->setMethods(['getMethodInstance'])
  66. ->getMockForAbstractClass();
  67. $payment->method('getMethodInstance')
  68. ->willReturn($this->getMethodInstance($newOrderStatus));
  69. return $payment;
  70. }
  71. /**
  72. * @param string $newOrderStatus
  73. * @return MethodInterface|MockObject
  74. */
  75. private function getMethodInstance($newOrderStatus)
  76. {
  77. $methodInstance = $this->getMockBuilder(MethodInterface::class)
  78. ->getMockForAbstractClass();
  79. $methodInstance->method('getConfigData')
  80. ->with('order_status')
  81. ->willReturn($newOrderStatus);
  82. return $methodInstance;
  83. }
  84. /**
  85. * @param array $stateStatuses
  86. * @return Config|MockObject
  87. */
  88. private function getConfig($stateStatuses)
  89. {
  90. $config = $this->getMockBuilder(Config::class)
  91. ->disableOriginalConstructor()
  92. ->getMock();
  93. $config->method('getStateStatuses')
  94. ->willReturn($stateStatuses);
  95. $config->method('getStateDefaultStatus')
  96. ->willReturn('processing');
  97. return $config;
  98. }
  99. }