Spamworldpro Mini Shell
Spamworldpro


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-swatches/Test/Unit/Plugin/Catalog/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-swatches/Test/Unit/Plugin/Catalog/CacheInvalidateTest.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
declare(strict_types=1);

namespace Magento\Swatches\Test\Unit\Plugin\Catalog;

use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Framework\App\Cache\TypeListInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Swatches\Helper\Data;
use Magento\Swatches\Plugin\Catalog\CacheInvalidate;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class CacheInvalidateTest extends TestCase
{
    /**
     * @var TypeListInterface|MockObject
     */
    private $typeList;

    /**
     * @var Data|MockObject
     */
    private $swatchHelper;

    /**
     * @var Attribute|MockObject
     */
    private $attribute;

    /**
     * @var CacheInvalidate
     */
    private $cacheInvalidate;

    /**
     * @inheritdoc
     */
    protected function setUp(): void
    {
        $this->typeList = $this->getMockForAbstractClass(TypeListInterface::class);
        $this->swatchHelper = $this->createMock(Data::class);
        $this->attribute = $this->createMock(Attribute::class);

        $objectManager = new ObjectManager($this);
        $this->cacheInvalidate = $objectManager->getObject(
            CacheInvalidate::class,
            [
                'typeList' => $this->typeList,
                'swatchHelper' => $this->swatchHelper
            ]
        );
    }

    /**
     * @return void
     */
    public function testAfterSaveSwatch(): void
    {
        $this->swatchHelper->expects($this->atLeastOnce())->method('isSwatchAttribute')->with($this->attribute)
            ->willReturn(true);
        $this->typeList
            ->method('invalidate')
            ->withConsecutive(['block_html'], ['collections']);
        $this->assertSame($this->attribute, $this->cacheInvalidate->afterSave($this->attribute, $this->attribute));
    }

    /**
     * @return void
     */
    public function testAfterSaveNotSwatch(): void
    {
        $this->swatchHelper->expects($this->atLeastOnce())->method('isSwatchAttribute')->with($this->attribute)
            ->willReturn(false);
        $this->typeList->expects($this->never())->method('invalidate');
        $this->assertSame($this->attribute, $this->cacheInvalidate->afterSave($this->attribute, $this->attribute));
    }
}

Spamworldpro Mini