11
11
use Magento \Framework \Indexer \ActionInterface ;
12
12
use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
13
13
use Magento \Framework \Api \SearchCriteriaBuilder ;
14
+ use Magento \Framework \Api \SearchCriteria ;
14
15
use Magento \Framework \Api \FilterBuilder ;
16
+ use Magento \Framework \Api \ExtensionAttributesInterface ;
17
+ use Magento \ConfigurableProduct \Model \Product \Type \Configurable \Attribute as ConfigurableAttribute ;
18
+ use Magento \Catalog \Model \ProductAttributeSearchResults ;
19
+ use Magento \Catalog \Model \ResourceModel \Eav \Attribute as EavAttribute ;
15
20
16
21
class ProductTest extends \PHPUnit \Framework \TestCase
17
22
{
@@ -37,31 +42,30 @@ class ProductTest extends \PHPUnit\Framework\TestCase
37
42
/**
38
43
* @var ProductAttributeRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
39
44
*/
40
- private $ prdAttributeRepository ;
45
+ private $ prdAttributeRepositoryMock ;
41
46
/**
42
47
* @var SearchCriteriaBuilder|\PHPUnit\Framework\MockObject\MockObject
43
48
*/
44
- private $ searchCriteriaBuilder ;
49
+ private $ searchCriteriaBuilderMock ;
45
50
/**
46
51
* @var FilterBuilder|\PHPUnit\Framework\MockObject\MockObject
47
52
*/
48
- private $ filterBuilder ;
53
+ private $ filterBuilderMock ;
49
54
50
55
public function setUp ()
51
56
{
52
57
$ this ->objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
53
58
$ this ->configurableMock = $ this ->createMock (Configurable::class);
54
59
$ this ->actionMock = $ this ->createMock (ActionInterface::class);
55
- // $this->prdAttributeRepository = $this->createMock(ProductAttributeRepositoryInterface::class);
56
- $ this ->prdAttributeRepository = $ this ->getMockBuilder (ProductAttributeRepositoryInterface::class)
60
+ $ this ->prdAttributeRepositoryMock = $ this ->getMockBuilder (ProductAttributeRepositoryInterface::class)
57
61
->disableOriginalConstructor ()
58
62
->setMethods (['getList ' ])
59
63
->getMockForAbstractClass ();
60
- $ this ->searchCriteriaBuilder = $ this ->createPartialMock (
64
+ $ this ->searchCriteriaBuilderMock = $ this ->createPartialMock (
61
65
SearchCriteriaBuilder::class,
62
66
['addFilters ' , 'create ' ]
63
67
);
64
- $ this ->filterBuilder = $ this ->createPartialMock (
68
+ $ this ->filterBuilderMock = $ this ->createPartialMock (
65
69
FilterBuilder::class,
66
70
['setField ' , 'setConditionType ' , 'setValue ' , 'create ' ]
67
71
);
@@ -71,9 +75,9 @@ public function setUp()
71
75
[
72
76
'configurable ' => $ this ->configurableMock ,
73
77
'productIndexer ' => $ this ->actionMock ,
74
- 'productAttributeRepository ' => $ this ->prdAttributeRepository ,
75
- 'searchCriteriaBuilder ' => $ this ->searchCriteriaBuilder ,
76
- 'filterBuilder ' => $ this ->filterBuilder
78
+ 'productAttributeRepository ' => $ this ->prdAttributeRepositoryMock ,
79
+ 'searchCriteriaBuilder ' => $ this ->searchCriteriaBuilderMock ,
80
+ 'filterBuilder ' => $ this ->filterBuilderMock
77
81
]
78
82
);
79
83
}
@@ -98,33 +102,33 @@ public function testBeforeSaveConfigurable()
98
102
);
99
103
100
104
$ extensionAttributes = $ this ->createPartialMock (
101
- \ Magento \ Framework \ Api \ ExtensionAttributesInterface::class,
105
+ ExtensionAttributesInterface::class,
102
106
['getConfigurableProductOptions ' ]
103
107
);
104
108
$ option = $ this ->createPartialMock (
105
- \ Magento \ ConfigurableProduct \ Model \ Product \ Type \ Configurable \Attribute ::class,
109
+ ConfigurableAttribute ::class,
106
110
['getAttributeId ' ]
107
111
);
108
112
$ extensionAttributes ->expects ($ this ->exactly (2 ))->method ('getConfigurableProductOptions ' )
109
113
->willReturn ([$ option ]);
110
114
$ object ->expects ($ this ->once ())->method ('getExtensionAttributes ' )
111
115
->willReturn ($ extensionAttributes );
112
116
113
- $ this ->filterBuilder ->expects ($ this ->atLeastOnce ())->method ('setField ' )->willReturnSelf ();
114
- $ this ->filterBuilder ->expects ($ this ->atLeastOnce ())->method ('setValue ' )->willReturnSelf ();
115
- $ this ->filterBuilder ->expects ($ this ->atLeastOnce ())->method ('setConditionType ' )->willReturnSelf ();
116
- $ this ->filterBuilder ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturnSelf ();
117
- $ searchCriteria = $ this ->createMock (\ Magento \ Framework \ Api \ SearchCriteria::class);
118
- $ this ->searchCriteriaBuilder ->expects ($ this ->once ())->method ('create ' )->willReturn ($ searchCriteria );
117
+ $ this ->filterBuilderMock ->expects ($ this ->atLeastOnce ())->method ('setField ' )->willReturnSelf ();
118
+ $ this ->filterBuilderMock ->expects ($ this ->atLeastOnce ())->method ('setValue ' )->willReturnSelf ();
119
+ $ this ->filterBuilderMock ->expects ($ this ->atLeastOnce ())->method ('setConditionType ' )->willReturnSelf ();
120
+ $ this ->filterBuilderMock ->expects ($ this ->atLeastOnce ())->method ('create ' )->willReturnSelf ();
121
+ $ searchCriteria = $ this ->createMock (SearchCriteria::class);
122
+ $ this ->searchCriteriaBuilderMock ->expects ($ this ->once ())->method ('create ' )->willReturn ($ searchCriteria );
119
123
120
124
$ searchResultMockClass = $ this ->createPartialMock (
121
- \ Magento \ Catalog \ Model \ ProductAttributeSearchResults::class,
125
+ ProductAttributeSearchResults::class,
122
126
['getItems ' ]
123
127
);
124
- $ this ->prdAttributeRepository ->expects ($ this ->once ())
128
+ $ this ->prdAttributeRepositoryMock ->expects ($ this ->once ())
125
129
->method ('getList ' )->with ($ searchCriteria )->willReturn ($ searchResultMockClass );
126
130
$ optionAttribute = $ this ->createPartialMock (
127
- \ Magento \ Catalog \ Model \ ResourceModel \ Eav \Attribute ::class,
131
+ EavAttribute ::class,
128
132
['getAttributeCode ' ]
129
133
);
130
134
$ searchResultMockClass ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([$ optionAttribute ]);
0 commit comments