|
8 | 8 | namespace Magento\QuoteGraphQl\Test\Unit\Model\Resolver;
|
9 | 9 |
|
10 | 10 | use Magento\Framework\Exception\LocalizedException;
|
| 11 | +use Magento\Framework\Exception\NoSuchEntityException; |
11 | 12 | use Magento\Framework\GraphQl\Config\Element\Field;
|
12 | 13 | use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
13 | 14 | use Magento\GraphQl\Model\Query\Context;
|
|
16 | 17 | use Magento\Quote\Model\QuoteIdMaskFactory;
|
17 | 18 | use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
|
18 | 19 | use Magento\Quote\Model\ResourceModel\Quote\QuoteIdMask as QuoteIdMaskResourceModel;
|
19 |
| -use Magento\QuoteGraphQl\Model\Resolver\Cart; |
20 | 20 | use Magento\QuoteGraphQl\Model\Resolver\MaskedCartId;
|
21 | 21 | use PHPUnit\Framework\MockObject\MockObject;
|
22 | 22 | use PHPUnit\Framework\TestCase;
|
@@ -134,4 +134,55 @@ public function testResolve(): void
|
134 | 134 | ->with($this->quoteIdMask);
|
135 | 135 | $this->maskedCartId->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $this->valueMock);
|
136 | 136 | }
|
| 137 | + |
| 138 | + /** |
| 139 | + * |
| 140 | + * @dataProvider resolveDataProvider |
| 141 | + * @param $cartId |
| 142 | + * @param $maskedId |
| 143 | + * @param $expectedResult |
| 144 | + * @return void |
| 145 | + * @throws \Exception |
| 146 | + */ |
| 147 | + public function testResolveForException($cartId, $maskedId, $expectedResult): void |
| 148 | + { |
| 149 | + $this->valueMock = ['model' => $this->quoteMock]; |
| 150 | + $this->quoteMock |
| 151 | + ->expects($this->once()) |
| 152 | + ->method('getId') |
| 153 | + ->willReturn($cartId); |
| 154 | + if ($cartId == 0) { |
| 155 | + $this->quoteIdToMaskedQuoteId->method('execute')->with($cartId)->willThrowException( |
| 156 | + new NoSuchEntityException( |
| 157 | + __( |
| 158 | + 'No such entity with %fieldName = %fieldValue', |
| 159 | + [ |
| 160 | + 'fieldName' => 'quoteId', |
| 161 | + 'fieldValue' => $cartId |
| 162 | + ] |
| 163 | + ) |
| 164 | + ) |
| 165 | + ); |
| 166 | + $this->expectExceptionMessage('Current user does not have an active cart.'); |
| 167 | + } |
| 168 | + $this->quoteIdToMaskedQuoteId->method('execute')->with($cartId)->willReturn($maskedId); |
| 169 | + $result = $this->maskedCartId->resolve( |
| 170 | + $this->fieldMock, |
| 171 | + $this->contextMock, |
| 172 | + $this->resolveInfoMock, |
| 173 | + $this->valueMock |
| 174 | + ); |
| 175 | + $this->assertEquals($expectedResult, $result); |
| 176 | + } |
| 177 | + |
| 178 | + /** |
| 179 | + * @return array |
| 180 | + */ |
| 181 | + public function resolveDataProvider(): array |
| 182 | + { |
| 183 | + return [ |
| 184 | + [0, 'noQuoteMaskId', ''], |
| 185 | + [1, 'quoteMaskId', 'quoteMaskId'] |
| 186 | + ]; |
| 187 | + } |
137 | 188 | }
|
0 commit comments