|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver; |
| 9 | + |
| 10 | +use Magento\Framework\Exception\LocalizedException; |
| 11 | +use Magento\Framework\GraphQl\Config\Element\Field; |
| 12 | +use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; |
| 13 | +use Magento\GraphQl\Model\Query\Context; |
| 14 | +use Magento\Quote\Model\QuoteIdMaskFactory; |
| 15 | +use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface; |
| 16 | +use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel; |
| 17 | +use Magento\QuoteGraphQl\Model\Resolver\Cart; |
| 18 | +use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId; |
| 19 | +use PHPUnit\Framework\MockObject\MockObject; |
| 20 | +use PHPUnit\Framework\TestCase; |
| 21 | + |
| 22 | +class MaskedCartIdTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var MaskedCartId |
| 26 | + */ |
| 27 | + private MaskedCartId $maskedCartId; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var QuoteIdToMaskedQuoteIdInterface|MockObject |
| 31 | + */ |
| 32 | + private QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteIdMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var QuoteIdMaskFactory|MockObject |
| 36 | + */ |
| 37 | + private QuoteIdMaskFactory $quoteIdMaskFactoryMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var QuoteIdMaskResourceModel|MockObject |
| 41 | + */ |
| 42 | + private QuoteIdMaskResourceModel $quoteIdMaskResourceModelMock; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var Field|MockObject |
| 46 | + */ |
| 47 | + private Field $fieldMock; |
| 48 | + |
| 49 | + /** |
| 50 | + * @var ResolveInfo|MockObject |
| 51 | + */ |
| 52 | + private ResolveInfo $resolveInfoMock; |
| 53 | + |
| 54 | + /** |
| 55 | + * @var Context|MockObject |
| 56 | + */ |
| 57 | + private Context $contextMock; |
| 58 | + |
| 59 | + /** |
| 60 | + * @var cart|MockObject |
| 61 | + */ |
| 62 | + private Cart $cartMock; |
| 63 | + |
| 64 | + /** |
| 65 | + * @var array |
| 66 | + */ |
| 67 | + private array $valueMock = []; |
| 68 | + |
| 69 | + protected function setUp(): void |
| 70 | + { |
| 71 | + $this->quoteIdToMaskedQuoteIdMock = $this->createMock(QuoteIdToMaskedQuoteIdInterface::class); |
| 72 | + $this->quoteIdMaskFactoryMock = $this->createMock(QuoteIdMaskFactory::class); |
| 73 | + $this->quoteIdMaskResourceModelMock = $this->createMock(QuoteIdMaskResourceModel::class); |
| 74 | + $this->fieldMock = $this->createMock(Field::class); |
| 75 | + $this->resolveInfoMock = $this->createMock(ResolveInfo::class); |
| 76 | + $this->contextMock = $this->createMock(Context::class); |
| 77 | + $this->cartMock = $this->getMockBuilder(Cart::class) |
| 78 | + ->disableOriginalConstructor() |
| 79 | + ->addMethods(['getId']) |
| 80 | + ->getMock(); |
| 81 | + $this->quoteIdMaskResourceModelMock = $this->getMockBuilder(QuoteIdMaskResourceModel::class) |
| 82 | + ->disableOriginalConstructor() |
| 83 | + ->addMethods( |
| 84 | + [ |
| 85 | + 'getQuoteMaskId', |
| 86 | + 'ensureQuoteMaskExist' |
| 87 | + ] |
| 88 | + ) |
| 89 | + ->getMock(); |
| 90 | + $this->maskedCartId = new MaskedCartId( |
| 91 | + $this->quoteIdToMaskedQuoteIdMock, |
| 92 | + $this->quoteIdMaskFactoryMock, |
| 93 | + $this->quoteIdMaskResourceModelMock |
| 94 | + ); |
| 95 | + } |
| 96 | + public function testResolveWithoutModelInValueParameter(): void |
| 97 | + { |
| 98 | + $this->expectException(LocalizedException::class); |
| 99 | + $this->expectExceptionMessage('"model" value should be specified'); |
| 100 | + $this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock); |
| 101 | + } |
| 102 | + |
| 103 | + public function testResolve(): void |
| 104 | + { |
| 105 | + $this->valueMock = ['model' => $this->valueMock]; |
| 106 | + $this->cartMock |
| 107 | + ->expects($this->any()) |
| 108 | + ->method('getId'); |
| 109 | + $this->quoteIdMaskResourceModelMock |
| 110 | + ->expects($this->any()) |
| 111 | + ->method('getQuoteMaskId') |
| 112 | + ->willReturn('maskedId'); |
| 113 | + $this->quoteIdMaskResourceModelMock |
| 114 | + ->expects($this->any()) |
| 115 | + ->method('ensureQuoteMaskExist') |
| 116 | + ->willReturn('maskedId'); |
| 117 | + |
| 118 | + } |
| 119 | +} |
| 120 | + |
| 121 | + |
0 commit comments