|
| 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\Catalog\Test\Unit\Model\ResourceModel\Category; |
| 9 | + |
| 10 | +use Magento\Catalog\Model\Category; |
| 11 | +use Magento\Catalog\Model\ResourceModel\Category\AggregateCount; |
| 12 | +use Magento\Catalog\Model\ResourceModel\Category as ResourceCategory; |
| 13 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 14 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 15 | +use PHPUnit\Framework\MockObject\MockObject; |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | + |
| 18 | +/** |
| 19 | + * Aggregate count model test |
| 20 | + */ |
| 21 | +class AggregateCountTest extends TestCase |
| 22 | +{ |
| 23 | + |
| 24 | + /** |
| 25 | + * @var AggregateCount |
| 26 | + */ |
| 27 | + protected $aggregateCount; |
| 28 | + |
| 29 | + /** |
| 30 | + * @var ObjectManagerHelper |
| 31 | + */ |
| 32 | + protected $objectManagerHelper; |
| 33 | + |
| 34 | + /** |
| 35 | + * @var Category|MockObject |
| 36 | + */ |
| 37 | + protected $categoryMock; |
| 38 | + |
| 39 | + /** |
| 40 | + * @var ResourceCategory|MockObject |
| 41 | + */ |
| 42 | + protected $resourceCategoryMock; |
| 43 | + |
| 44 | + /** |
| 45 | + * @var AdapterInterface|MockObject |
| 46 | + */ |
| 47 | + protected $connectionMock; |
| 48 | + |
| 49 | + /** |
| 50 | + * {@inheritdoc} |
| 51 | + */ |
| 52 | + public function setUp() |
| 53 | + { |
| 54 | + $this->categoryMock = $this->createMock(Category::class); |
| 55 | + $this->resourceCategoryMock = $this->createMock(ResourceCategory::class); |
| 56 | + $this->connectionMock = $this->getMockBuilder(AdapterInterface::class) |
| 57 | + ->getMockForAbstractClass(); |
| 58 | + $this->objectManagerHelper = new ObjectManagerHelper($this); |
| 59 | + $this->aggregateCount = $this->objectManagerHelper->getObject(AggregateCount::class); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * @return void |
| 64 | + */ |
| 65 | + public function testProcessDelete(): void |
| 66 | + { |
| 67 | + $parentIds = 3; |
| 68 | + $table = 'catalog_category_entity'; |
| 69 | + |
| 70 | + $this->categoryMock->expects($this->once()) |
| 71 | + ->method('getResource') |
| 72 | + ->willReturn($this->resourceCategoryMock); |
| 73 | + $this->categoryMock->expects($this->once()) |
| 74 | + ->method('getParentIds') |
| 75 | + ->willReturn($parentIds); |
| 76 | + $this->resourceCategoryMock->expects($this->any()) |
| 77 | + ->method('getEntityTable') |
| 78 | + ->willReturn($table); |
| 79 | + $this->resourceCategoryMock->expects($this->once()) |
| 80 | + ->method('getConnection') |
| 81 | + ->willReturn($this->connectionMock); |
| 82 | + $this->connectionMock->expects($this->once()) |
| 83 | + ->method('update') |
| 84 | + ->with( |
| 85 | + $table, |
| 86 | + ['children_count' => new \Zend_Db_Expr('children_count - 1')], |
| 87 | + ['entity_id IN(?)' => $parentIds] |
| 88 | + ); |
| 89 | + $this->aggregateCount->processDelete($this->categoryMock); |
| 90 | + } |
| 91 | +} |
0 commit comments