IncrementTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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;
  7. /**
  8. * Class IncrementTest
  9. */
  10. class IncrementTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\Sales\Model\Increment
  14. */
  15. protected $model;
  16. /**
  17. * @var \Magento\Eav\Model\Config|\PHPUnit_Framework_MockObject_MockObject
  18. */
  19. protected $eavConfig;
  20. /**
  21. * @var \Magento\Eav\Model\Entity\Type|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $type;
  24. protected function setUp()
  25. {
  26. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  27. $this->eavConfig = $this->createPartialMock(\Magento\Eav\Model\Config::class, ['getEntityType']);
  28. $this->model = $objectManager->getObject(
  29. \Magento\Sales\Model\Increment::class,
  30. ['eavConfig' => $this->eavConfig]
  31. );
  32. $this->type = $this->createPartialMock(\Magento\Eav\Model\Entity\Type::class, ['fetchNewIncrementId']);
  33. }
  34. public function testGetCurrentValue()
  35. {
  36. $this->type->expects($this->once())
  37. ->method('fetchNewIncrementId')
  38. ->with(1)
  39. ->willReturn(2);
  40. $this->eavConfig->expects($this->once())
  41. ->method('getEntityType')
  42. ->with('order')
  43. ->willReturn($this->type);
  44. $this->model->getNextValue(1);
  45. $this->assertEquals(2, $this->model->getCurrentValue());
  46. }
  47. public function testNextValue()
  48. {
  49. $this->type->expects($this->once())
  50. ->method('fetchNewIncrementId')
  51. ->with(1)
  52. ->willReturn(2);
  53. $this->eavConfig->expects($this->once())
  54. ->method('getEntityType')
  55. ->with('order')
  56. ->willReturn($this->type);
  57. $this->assertEquals(2, $this->model->getNextValue(1));
  58. }
  59. }