ManagerTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesSequence\Test\Unit\Model;
  7. /**
  8. * Class ManagerTest
  9. */
  10. class ManagerTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * @var \Magento\SalesSequence\Model\ResourceModel\Meta | \PHPUnit_Framework_MockObject_MockObject
  14. */
  15. private $resourceSequenceMeta;
  16. /**
  17. * @var \Magento\SalesSequence\Model\SequenceFactory | \PHPUnit_Framework_MockObject_MockObject
  18. */
  19. private $sequenceFactory;
  20. /**
  21. * @var \Magento\SalesSequence\Model\Manager
  22. */
  23. private $sequenceManager;
  24. /**
  25. * @var \Magento\Store\Model\Store | \PHPUnit_Framework_MockObject_MockObject
  26. */
  27. private $store;
  28. /**
  29. * @var \Magento\SalesSequence\Model\Meta | \PHPUnit_Framework_MockObject_MockObject
  30. */
  31. private $meta;
  32. /**
  33. * @var \Magento\Framework\DB\Sequence\SequenceInterface | \PHPUnit_Framework_MockObject_MockObject
  34. */
  35. private $sequence;
  36. /**
  37. * Initialization
  38. */
  39. protected function setUp()
  40. {
  41. $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  42. $this->sequence = $this->getMockForAbstractClass(
  43. \Magento\Framework\DB\Sequence\SequenceInterface::class,
  44. [],
  45. '',
  46. false,
  47. false,
  48. true,
  49. []
  50. );
  51. $this->resourceSequenceMeta = $this->createPartialMock(
  52. \Magento\SalesSequence\Model\ResourceModel\Meta::class,
  53. ['loadByEntityTypeAndStore']
  54. );
  55. $this->sequenceFactory = $this->createPartialMock(
  56. \Magento\SalesSequence\Model\SequenceFactory::class,
  57. ['create']
  58. );
  59. $this->meta = $this->createMock(\Magento\SalesSequence\Model\Meta::class);
  60. $this->store = $this->createPartialMock(\Magento\Store\Model\Store::class, ['getId']);
  61. $this->sequenceManager = $helper->getObject(
  62. \Magento\SalesSequence\Model\Manager::class,
  63. [
  64. 'resourceSequenceMeta' => $this->resourceSequenceMeta,
  65. 'sequenceFactory' => $this->sequenceFactory
  66. ]
  67. );
  68. }
  69. public function testGetSequence()
  70. {
  71. $entityType = 'order';
  72. $storeId = 1;
  73. $this->resourceSequenceMeta->expects($this->once())
  74. ->method('loadByEntityTypeAndStore')
  75. ->with($entityType, $storeId)
  76. ->willReturn($this->meta);
  77. $this->sequenceFactory->expects($this->once())->method('create')->with([
  78. 'meta' => $this->meta
  79. ])->willReturn($this->sequence);
  80. $this->assertSame($this->sequence, $this->sequenceManager->getSequence($entityType, $storeId));
  81. }
  82. }