|
| 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\CatalogCustomerGraphQl\Test\Unit\Model\Resolver;; |
| 9 | + |
| 10 | +use Magento\CatalogCustomerGraphQl\Model\Resolver\Customer\GetCustomerGroup; |
| 11 | +use Magento\CatalogCustomerGraphQl\Model\Resolver\PriceTiers; |
| 12 | +use Magento\CatalogCustomerGraphQl\Model\Resolver\Product\Price\Tiers; |
| 13 | +use Magento\CatalogCustomerGraphQl\Model\Resolver\Product\Price\TiersFactory; |
| 14 | +use Magento\CatalogGraphQl\Model\Resolver\Product\Price\Discount; |
| 15 | +use Magento\CatalogGraphQl\Model\Resolver\Product\Price\ProviderPool; |
| 16 | +use Magento\Directory\Model\PriceCurrency; |
| 17 | +use Magento\Framework\GraphQl\Config\Element\Field; |
| 18 | +use Magento\Framework\GraphQl\Query\Resolver\ValueFactory; |
| 19 | +use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; |
| 20 | +use Magento\GraphQl\Model\Query\Context; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | +use PHPUnit\Framework\MockObject\MockObject; |
| 23 | + |
| 24 | +/** |
| 25 | + * Test Resolver for PriceTiers |
| 26 | + */ |
| 27 | +class PriceTiersTest extends TestCase |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var Field|MockObject |
| 31 | + */ |
| 32 | + private $fieldMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var ResolveInfo|MockObject |
| 36 | + */ |
| 37 | + private $resolveInfoMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var Context|MockObject |
| 41 | + */ |
| 42 | + private $contextMock; |
| 43 | + |
| 44 | + protected function setUp(): void |
| 45 | + { |
| 46 | + $valueFactory = $this->createMock(ValueFactory::class); |
| 47 | + $this->tiersFactory = $this->createMock(TiersFactory::class); |
| 48 | + $customerGroup = $this->createMock(GetCustomerGroup::class); |
| 49 | + $priceDiscount = $this->createMock(Discount::class); |
| 50 | + $providerPool = $this->createMock(ProviderPool::class); |
| 51 | + $priceCurrency = $this->createMock(PriceCurrency::class); |
| 52 | + $this->priceTiers = new PriceTiers( |
| 53 | + $valueFactory, |
| 54 | + $this->tiersFactory, |
| 55 | + $customerGroup, |
| 56 | + $priceDiscount, |
| 57 | + $providerPool, |
| 58 | + $priceCurrency |
| 59 | + ); |
| 60 | + |
| 61 | + $this->fieldMock = $this->createMock(Field::class); |
| 62 | + $this->resolveInfoMock = $this->createMock(ResolveInfo::class); |
| 63 | + $this->contextMock = $this->createMock(Context::class); |
| 64 | + } |
| 65 | + |
| 66 | + public function testResolve() |
| 67 | + { |
| 68 | + $tiers = $this->createMock(Tiers::class); |
| 69 | + $tiers->expects($this->once()) |
| 70 | + ->method('addProductFilter') |
| 71 | + ->willReturnSelf(); |
| 72 | + |
| 73 | + $this->tiersFactory->expects($this->once()) |
| 74 | + ->method('create') |
| 75 | + ->willReturn($tiers); |
| 76 | + |
| 77 | + $productMock = $this->createMock(\Magento\Catalog\Model\Product::class); |
| 78 | + $productMock->expects($this->never()) |
| 79 | + ->method('getTierPrices'); |
| 80 | + |
| 81 | + $productMock->expects($this->once()) |
| 82 | + ->method('getId') |
| 83 | + ->willReturn(1); |
| 84 | + |
| 85 | + $valueMock = ['model' => $productMock]; |
| 86 | + |
| 87 | + $this->priceTiers->resolve($this->fieldMock, $this->contextMock, $this->resolveInfoMock, $valueMock); |
| 88 | + } |
| 89 | +} |
0 commit comments