|
10 | 10 | */
|
11 | 11 | namespace Magento\Catalog\Test\Unit\Model\ResourceModel;
|
12 | 12 |
|
13 |
| -use Magento\Catalog\Model\Factory; |
14 | 13 | use Magento\Catalog\Model\Product;
|
15 | 14 | use Magento\Catalog\Model\ResourceModel\AbstractResource;
|
16 | 15 | use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
|
17 |
| -use Magento\Eav\Model\Entity\Attribute\Set; |
18 |
| -use Magento\Eav\Model\Entity\Attribute\UniqueValidationInterface; |
19 |
| -use Magento\Eav\Model\Entity\Context; |
20 | 16 | use Magento\Framework\DataObject;
|
21 |
| -use Magento\Store\Model\StoreManagerInterface; |
22 |
| -use PHPUnit\Framework\MockObject\MockObject; |
| 17 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
23 | 18 | use PHPUnit\Framework\TestCase;
|
24 | 19 |
|
25 | 20 | class AbstractTest extends TestCase
|
26 | 21 | {
|
27 |
| - /** |
28 |
| - * @var Context|MockObject |
29 |
| - */ |
30 |
| - private $context; |
31 |
| - |
32 |
| - /** |
33 |
| - * @var StoreManagerInterface|MockObject |
34 |
| - */ |
35 |
| - private $storeManager; |
36 |
| - |
37 |
| - /** |
38 |
| - * @var Factory|MockObject |
39 |
| - */ |
40 |
| - private $modelFactory; |
41 |
| - |
42 |
| - /** |
43 |
| - * @var UniqueValidationInterface|MockObject |
44 |
| - */ |
45 |
| - private $uniqueValidator; |
46 |
| - |
47 |
| - /** |
48 |
| - * @var AbstractResource|MockObject |
49 |
| - */ |
50 |
| - private $model; |
51 |
| - |
52 |
| - /** |
53 |
| - * @inheritDoc |
54 |
| - */ |
55 |
| - protected function setUp(): void |
56 |
| - { |
57 |
| - parent::setUp(); |
58 |
| - $this->context = $this->createMock(Context::class); |
59 |
| - $this->storeManager = $this->createMock(StoreManagerInterface::class); |
60 |
| - $this->modelFactory = $this->createMock(Factory::class); |
61 |
| - $this->uniqueValidator = $this->createMock(UniqueValidationInterface::class); |
62 |
| - } |
63 |
| - |
64 | 22 | /**
|
65 | 23 | * Get attribute list
|
66 | 24 | *
|
@@ -89,6 +47,8 @@ protected function _getAttributes()
|
89 | 47 |
|
90 | 48 | public function testWalkAttributes()
|
91 | 49 | {
|
| 50 | + $objectManager = new ObjectManager($this); |
| 51 | + |
92 | 52 | $code = 'test_attr';
|
93 | 53 | $set = 10;
|
94 | 54 | $storeId = 100;
|
@@ -125,33 +85,17 @@ public function testWalkAttributes()
|
125 | 85 |
|
126 | 86 | $attributes[$code] = $attribute;
|
127 | 87 |
|
128 |
| - $attrSetEntity = $this->createMock(Set::class); |
129 |
| - $this->context->method('getAttributeSetEntity') |
130 |
| - ->willReturn($attrSetEntity); |
131 |
| - $attrSetEntity->expects($this->once()) |
132 |
| - ->method('addSetInfo') |
133 |
| - ->with($entityType, $attributes, $set); |
134 |
| - |
135 |
| - $this->model = $this->getMockBuilder(AbstractResource::class) |
136 |
| - ->setConstructorArgs( |
137 |
| - [ |
138 |
| - $this->context, |
139 |
| - $this->storeManager, |
140 |
| - $this->modelFactory, |
141 |
| - [], |
142 |
| - $this->uniqueValidator |
143 |
| - ] |
144 |
| - ) |
145 |
| - ->onlyMethods(['getAttributesByCode', 'getEntityType']) |
146 |
| - ->getMockForAbstractClass(); |
147 |
| - |
148 |
| - $this->model->expects($this->once()) |
149 |
| - ->method('getAttributesByCode') |
150 |
| - ->willReturn($attributes); |
151 |
| - $this->model->expects($this->once()) |
152 |
| - ->method('getEntityType') |
153 |
| - ->willReturn($entityType); |
154 |
| - |
155 |
| - $this->model->walkAttributes('backend/afterSave', [$object]); |
| 88 | + /** @var AbstractResource $model */ |
| 89 | + $arguments = $objectManager->getConstructArguments( |
| 90 | + AbstractResource::class |
| 91 | + ); |
| 92 | + $model = $this->getMockBuilder(AbstractResource::class) |
| 93 | + ->setMethods(['getAttributesByCode']) |
| 94 | + ->setConstructorArgs($arguments) |
| 95 | + ->getMock(); |
| 96 | + |
| 97 | + $model->expects($this->once())->method('getAttributesByCode')->willReturn($attributes); |
| 98 | + |
| 99 | + $model->walkAttributes('backend/afterSave', [$object]); |
156 | 100 | }
|
157 | 101 | }
|
0 commit comments