![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-catalog-rule/Test/Unit/Cron/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\CatalogRule\Test\Unit\Cron; use Magento\CatalogRule\Cron\DailyCatalogUpdate; use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor; use Magento\CatalogRule\Model\ResourceModel\Rule\Collection as RuleCollection; use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class DailyCatalogUpdateTest extends TestCase { /** * @var RuleProductProcessor|MockObject */ private $ruleProductProcessor; /** * @var RuleCollectionFactory|MockObject */ private $ruleCollectionFactory; /** * @var DailyCatalogUpdate */ private $cron; protected function setUp(): void { $this->ruleProductProcessor = $this->createMock(RuleProductProcessor::class); $this->ruleCollectionFactory = $this->createMock(RuleCollectionFactory::class); $this->cron = new DailyCatalogUpdate($this->ruleProductProcessor, $this->ruleCollectionFactory); } /** * @dataProvider executeDataProvider * @param int $activeRulesCount * @param bool $isInvalidationNeeded */ public function testExecute(int $activeRulesCount, bool $isInvalidationNeeded) { $ruleCollection = $this->createMock(RuleCollection::class); $this->ruleCollectionFactory->expects($this->once()) ->method('create') ->willReturn($ruleCollection); $ruleCollection->expects($this->once()) ->method('addIsActiveFilter') ->willReturn($ruleCollection); $ruleCollection->expects($this->once()) ->method('getSize') ->willReturn($activeRulesCount); $this->ruleProductProcessor->expects($isInvalidationNeeded ? $this->once() : $this->never()) ->method('markIndexerAsInvalid'); $this->cron->execute(); } /** * @return array */ public function executeDataProvider(): array { return [ [2, true], [0, false], ]; } }