GuestCartTestHelper.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Quote\Test\Unit\Model\GuestCart;
  8. /**
  9. * Class GuestCartTestHelper
  10. *
  11. */
  12. class GuestCartTestHelper
  13. {
  14. /**
  15. * @var \PHPUnit\Framework\TestCase
  16. */
  17. protected $testCase;
  18. /**
  19. * Initialize helper
  20. *
  21. * @param \PHPUnit\Framework\TestCase $testCase
  22. */
  23. public function __construct(\PHPUnit\Framework\TestCase $testCase)
  24. {
  25. $this->testCase = $testCase;
  26. }
  27. /**
  28. * Return mocks with expected invokes
  29. *
  30. * First element is quoteIdMaskFactoryMock, second one is quoteIdMaskMock
  31. *
  32. * @param $maskedCartId
  33. * @param $cartId
  34. * @return array
  35. */
  36. public function mockQuoteIdMask($maskedCartId, $cartId)
  37. {
  38. $quoteIdMaskMock = $this->testCase->getMockBuilder(\Magento\Quote\Model\QuoteIdMask::class)
  39. ->setMethods(['load', 'getQuoteId', 'getMaskedId'])
  40. ->disableOriginalConstructor()
  41. ->getMock();
  42. $quoteIdMaskFactoryMock = $this->testCase->getMockBuilder(\Magento\Quote\Model\QuoteIdMaskFactory::class)
  43. ->setMethods(['create'])
  44. ->disableOriginalConstructor()
  45. ->getMock();
  46. $quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock);
  47. $quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf();
  48. $quoteIdMaskMock->expects($this->testCase->once())->method('getQuoteId')->willReturn($cartId);
  49. return [$quoteIdMaskFactoryMock, $quoteIdMaskMock];
  50. }
  51. }