![]() 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/Model/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\Swatches\Test\Unit\Model; use Magento\Catalog\Model\ResourceModel\Eav\Attribute; use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection; use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory; use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource; use Magento\Swatches\Helper\Data; use Magento\Swatches\Model\AttributesList; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; class AttributesListTest extends TestCase { /** * @var AttributesList */ protected $attributeListModel; /** * @var Collection|MockObject */ protected $collectionMock; /** * @var Attribute|MockObject */ protected $attributeMock; /** @var Data|MockObject */ protected $swatchHelper; protected function setUp(): void { $this->swatchHelper = $this->createMock(Data::class); $this->collectionMock = $this->createMock( Collection::class ); /** @var CollectionFactory $collectionFactoryMock */ $collectionFactoryMock = $this->createPartialMock( CollectionFactory::class, ['create'] ); $collectionFactoryMock->expects($this->once())->method('create')->willReturn($this->collectionMock); $this->attributeMock = $this->getMockBuilder(Attribute::class) ->onlyMethods(['getId', 'getAttributeCode', 'getSource']) ->addMethods(['getFrontendLabel']) ->disableOriginalConstructor() ->getMock(); $this->collectionMock ->expects($this->once()) ->method('getItems') ->willReturn(['id' => $this->attributeMock]); $this->attributeListModel = new AttributesList( $collectionFactoryMock, $this->swatchHelper ); } public function testGetAttributes() { $ids = [1, 2, 3]; $result = [ [ 'id' => 'id', 'label' => 'label', 'code' => 'code', 'options' => ['options'], 'canCreateOption' => false ] ]; $this->collectionMock ->expects($this->any()) ->method('addFieldToFilter') ->with('main_table.attribute_id', $ids); $this->attributeMock->expects($this->once())->method('getId')->willReturn('id'); $this->attributeMock->expects($this->once())->method('getFrontendLabel')->willReturn('label'); $this->attributeMock->expects($this->once())->method('getAttributeCode')->willReturn('code'); $source = $this->createMock(AbstractSource::class); $source->expects($this->once())->method('getAllOptions')->with(false)->willReturn(['options']); $this->attributeMock->expects($this->once())->method('getSource')->willReturn($source); $this->swatchHelper->expects($this->once())->method('isSwatchAttribute') ->with($this->attributeMock) ->willReturn(true); $this->assertEquals($result, $this->attributeListModel->getAttributes($ids)); } }