|
| 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\CatalogGraphQl\Test\Unit\Model\Resolver\Product; |
| 9 | + |
| 10 | +use Magento\CatalogGraphQl\Model\Resolver\Product\ProductCategories; |
| 11 | +use Magento\Framework\App\ResourceConnection; |
| 12 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 13 | +use Magento\Framework\DB\Select; |
| 14 | +use Magento\Framework\Indexer\DimensionFactory; |
| 15 | +use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver; |
| 16 | +use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use PHPUnit\Framework\TestCase; |
| 18 | + |
| 19 | +/** |
| 20 | + * @see ProductCategories |
| 21 | + */ |
| 22 | +class ProductCategoriesTest extends TestCase |
| 23 | +{ |
| 24 | + /** |
| 25 | + * @var ProductCategories |
| 26 | + */ |
| 27 | + private ProductCategories $productCategories; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var IndexScopeResolver|MockObject |
| 31 | + */ |
| 32 | + private IndexScopeResolver $indexScopeResolverMock; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var ResourceConnection|MockObject |
| 36 | + */ |
| 37 | + private ResourceConnection $resourceConnectionMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var AdapterInterface|MockObject |
| 41 | + */ |
| 42 | + private AdapterInterface $adapterInterfaceMock; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var DimensionFactory|MockObject |
| 46 | + */ |
| 47 | + private DimensionFactory $dimensionFactoryMock; |
| 48 | + |
| 49 | + /** |
| 50 | + * @var Select|MockObject |
| 51 | + */ |
| 52 | + private Select $selectMock; |
| 53 | + |
| 54 | + protected function setUp(): void |
| 55 | + { |
| 56 | + $this->indexScopeResolverMock = $this->createMock(IndexScopeResolver::class); |
| 57 | + $this->resourceConnectionMock = $this->createMock(ResourceConnection::class); |
| 58 | + $this->dimensionFactoryMock = $this->createMock(DimensionFactory::class); |
| 59 | + $this->adapterInterfaceMock = $this->createMock(AdapterInterface::class); |
| 60 | + $this->selectMock = $this->createMock(Select::class); |
| 61 | + $this->productCategories = new ProductCategories( |
| 62 | + $this->indexScopeResolverMock, |
| 63 | + $this->resourceConnectionMock, |
| 64 | + $this->dimensionFactoryMock |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + public function testGetCategoryIdsByProduct(): void |
| 69 | + { |
| 70 | + $this->selectMock |
| 71 | + ->expects($this->once()) |
| 72 | + ->method('from') |
| 73 | + ->willReturnSelf(); |
| 74 | + $this->selectMock |
| 75 | + ->expects($this->exactly(2)) |
| 76 | + ->method('joinInner') |
| 77 | + ->willReturnSelf(); |
| 78 | + $this->selectMock |
| 79 | + ->expects($this->once()) |
| 80 | + ->method('where') |
| 81 | + ->willReturnSelf(); |
| 82 | + $this->adapterInterfaceMock |
| 83 | + ->expects($this->once()) |
| 84 | + ->method('select') |
| 85 | + ->willReturn($this->selectMock); |
| 86 | + $this->adapterInterfaceMock |
| 87 | + ->expects($this->once()) |
| 88 | + ->method('fetchCol') |
| 89 | + ->willReturn([]); |
| 90 | + $this->adapterInterfaceMock |
| 91 | + ->expects($this->exactly(2)) |
| 92 | + ->method('quoteInto') |
| 93 | + ->willReturn(''); |
| 94 | + |
| 95 | + $this->resourceConnectionMock |
| 96 | + ->expects($this->once()) |
| 97 | + ->method('getConnection') |
| 98 | + ->willReturn($this->adapterInterfaceMock); |
| 99 | + $this->resourceConnectionMock->expects($this->exactly(2))->method('getTableName')->willReturn('TableName'); |
| 100 | + |
| 101 | + $this->productCategories->getCategoryIdsByProduct(1, 1); |
| 102 | + } |
| 103 | +} |
0 commit comments