Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SetManagementTest.php
Go to the documentation of this file.
1 <?php
9 
10 class SetManagementTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $model;
16 
21 
26 
30  protected $eavConfig;
31 
32  protected function setUp()
33  {
34  $this->attrSetManagementMock = $this->createMock(\Magento\Eav\Api\AttributeSetManagementInterface::class);
35  $this->attributeSetRepository = $this->createMock(\Magento\Eav\Api\AttributeSetRepositoryInterface::class);
36  $this->eavConfig = $this->createMock(\Magento\Eav\Model\Config::class);
37  $this->model = new \Magento\Catalog\Model\Product\Attribute\SetManagement(
38  $this->attrSetManagementMock,
39  $this->attributeSetRepository,
40  $this->eavConfig
41  );
42  }
43 
44  public function testCreate()
45  {
46  $skeletonId = 1;
47  $attributeSetMock = $this->createMock(\Magento\Eav\Api\Data\AttributeSetInterface::class);
48  $skeletonSetMock = $this->createMock(\Magento\Eav\Api\Data\AttributeSetInterface::class);
49 
50  $this->attributeSetRepository->expects($this->once())
51  ->method('get')
52  ->with($skeletonId)
53  ->willReturn($skeletonSetMock);
54 
55  $typeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
56  $typeMock->expects($this->once())->method('getId')->willReturn(4);
57  $this->eavConfig->expects($this->once())
58  ->method('getEntityType')
59  ->with(\Magento\Catalog\Model\Product::ENTITY)
60  ->willReturn($typeMock);
61  $skeletonSetMock->expects($this->once())->method('getEntityTypeId')->willReturn(4);
62 
63  $this->attrSetManagementMock->expects($this->once())
64  ->method('create')
65  ->with(
67  $attributeSetMock,
68  $skeletonId
69  )->willReturn($attributeSetMock);
70  $this->assertEquals($attributeSetMock, $this->model->create($attributeSetMock, $skeletonId));
71  }
72 
77  {
78  $skeletonId = 1;
79  $attributeSetMock = $this->createMock(\Magento\Eav\Api\Data\AttributeSetInterface::class);
80  $skeletonSetMock = $this->createMock(\Magento\Eav\Api\Data\AttributeSetInterface::class);
81  $this->attributeSetRepository->expects($this->once())
82  ->method('get')
83  ->with($skeletonId)
84  ->willReturn($skeletonSetMock);
85 
86  $typeMock = $this->createMock(\Magento\Eav\Model\Entity\Type::class);
87  $typeMock->expects($this->once())->method('getId')->willReturn(4);
88  $this->eavConfig->expects($this->once())
89  ->method('getEntityType')
90  ->with(\Magento\Catalog\Model\Product::ENTITY)
91  ->willReturn($typeMock);
92  $skeletonSetMock->expects($this->once())->method('getEntityTypeId')->willReturn(3);
93  $this->model->create($attributeSetMock, $skeletonId);
94 
95  $this->expectExceptionMessage(
96  "The attribute set couldn't be created because it's based on a non-product attribute set."
97  );
98  }
99 }