OrderIncrementIdCheckerTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Sales\Test\Unit\Model;
  8. /**
  9. * Unit test for \Magento\Sales\Model\OrderIncrementIdChecker.
  10. */
  11. class OrderIncrementIdCheckerTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Sales\Model\OrderIncrementIdChecker
  15. */
  16. private $model;
  17. /**
  18. * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
  19. */
  20. private $resourceMock;
  21. /**
  22. * @var \Magento\Framework\DB\Adapter\Pdo\Mysql|\PHPUnit_Framework_MockObject_MockObject
  23. */
  24. private $adapterMock;
  25. /**
  26. * @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
  27. */
  28. private $selectMock;
  29. /**
  30. * @inheritdoc
  31. */
  32. protected function setUp()
  33. {
  34. $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  35. $this->selectMock = $this->createMock(\Magento\Framework\DB\Select::class);
  36. $this->selectMock->expects($this->any())->method('from')->will($this->returnSelf());
  37. $this->selectMock->expects($this->any())->method('where');
  38. $this->adapterMock = $this->createMock(\Magento\Framework\DB\Adapter\Pdo\Mysql::class);
  39. $this->adapterMock->expects($this->any())->method('select')->will($this->returnValue($this->selectMock));
  40. $this->resourceMock = $this->createMock(\Magento\Sales\Model\ResourceModel\Order::class);
  41. $this->resourceMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock);
  42. $this->model = $objectManagerHelper->getObject(
  43. \Magento\Sales\Model\OrderIncrementIdChecker::class,
  44. [
  45. 'resourceModel' => $this->resourceMock,
  46. ]
  47. );
  48. }
  49. /**
  50. * Unit test to verify if isOrderIncrementIdUsed method works with different types increment ids.
  51. *
  52. * @param string|int $value
  53. * @return void
  54. * @dataProvider isOrderIncrementIdUsedDataProvider
  55. */
  56. public function testIsIncrementIdUsed($value): void
  57. {
  58. $expectedBind = [':increment_id' => $value];
  59. $this->adapterMock->expects($this->once())->method('fetchOne')->with($this->selectMock, $expectedBind);
  60. $this->model->isIncrementIdUsed($value);
  61. }
  62. /**
  63. * @return array
  64. */
  65. public function isOrderIncrementIdUsedDataProvider(): array
  66. {
  67. return [[100000001], ['10000000001'], ['M10000000001']];
  68. }
  69. }