-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ACP2E-1003: Inventory indexer is cleaning all caches in scheduled mode
- Loading branch information
Showing
2 changed files
with
89 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
InventoryCache/Test/Unit/Model/FlushCacheByCacheTagTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventoryCache\Unit\Model; | ||
|
||
use Magento\Framework\App\CacheInterface; | ||
use Magento\Framework\EntityManager\EventManager; | ||
use Magento\Framework\Indexer\CacheContext; | ||
use Magento\Framework\Indexer\CacheContextFactory; | ||
use Magento\InventoryCache\Model\FlushCacheByCacheTag; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class FlushCacheByCacheTagTest extends TestCase | ||
{ | ||
/** | ||
* @var CacheContextFactory|MockObject | ||
*/ | ||
private $cacheContextFactory; | ||
|
||
/** | ||
* @var EventManager|MockObject | ||
*/ | ||
private $eventManager; | ||
|
||
/** | ||
* @var CacheInterface|MockObject | ||
*/ | ||
private $appCache; | ||
|
||
/** | ||
* @var FlushCacheByCacheTag | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->cacheContextFactory = $this->createMock(CacheContextFactory::class); | ||
$this->eventManager = $this->createMock(EventManager::class); | ||
$this->appCache = $this->createMock(CacheInterface::class); | ||
$this->model = new FlushCacheByCacheTag( | ||
$this->cacheContextFactory, | ||
$this->eventManager, | ||
$this->appCache | ||
); | ||
} | ||
|
||
/** | ||
* Checks that cache is not cleaned with empty tags which cleans all caches | ||
* | ||
* @return void | ||
*/ | ||
public function testExecuteWithEmptyEntityIds(): void | ||
{ | ||
$this->cacheContextFactory->expects($this->never())->method('create'); | ||
$this->eventManager->expects($this->never())->method('dispatch'); | ||
$this->appCache->expects($this->never())->method('clean'); | ||
$this->model->execute('test', []); | ||
} | ||
|
||
/** | ||
* Checks that cache is not cleaned with empty tags which cleans all caches | ||
* | ||
* @return void | ||
*/ | ||
public function testExecuteWithDeferredCacheContext(): void | ||
{ | ||
$cacheContextMock = $this->createMock(CacheContext::class); | ||
$cacheContextMock->method('getIdentities') | ||
->willReturn([]); | ||
$this->cacheContextFactory->expects($this->once()) | ||
->method('create') | ||
->willReturn($cacheContextMock); | ||
$this->appCache->expects($this->never())->method('clean'); | ||
$this->model->execute('test', ['1', '2']); | ||
} | ||
} |