5
5
*/
6
6
namespace Magento \CatalogSearch \Test \Unit \Model \Adapter \Aggregation ;
7
7
8
- use Magento \Catalog \Api \Data \ProductAttributeInterface ;
9
- use Magento \Catalog \Api \Data \ProductAttributeSearchResultsInterface ;
10
8
use Magento \CatalogSearch \Model \Adapter \Aggregation \AggregationResolver ;
11
9
use Magento \Catalog \Api \AttributeSetFinderInterface ;
12
- use Magento \Catalog \Api \ProductAttributeRepositoryInterface ;
13
10
use Magento \Framework \Api \SearchCriteriaBuilder ;
14
- use Magento \Framework \Api \SearchCriteriaInterface ;
15
11
use Magento \Framework \Search \Request \BucketInterface ;
16
12
use Magento \Framework \Search \Request \Config ;
17
13
use Magento \Framework \Search \RequestInterface ;
@@ -27,11 +23,6 @@ class AggregationResolverTest extends \PHPUnit_Framework_TestCase
27
23
*/
28
24
private $ attributeSetFinder ;
29
25
30
- /**
31
- * @var ProductAttributeRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject
32
- */
33
- private $ productAttributeRepository ;
34
-
35
26
/**
36
27
* @var SearchCriteriaBuilder|\PHPUnit_Framework_MockObject_MockObject
37
28
*/
@@ -47,28 +38,44 @@ class AggregationResolverTest extends \PHPUnit_Framework_TestCase
47
38
*/
48
39
private $ config ;
49
40
41
+ /**
42
+ * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection|\PHPUnit_Framework_MockObject_MockObject
43
+ */
44
+ private $ attributeCollection ;
45
+
50
46
/**
51
47
* @var AggregationResolver
52
48
*/
53
49
private $ aggregationResolver ;
54
50
51
+ /**
52
+ * @inheritdoc
53
+ */
55
54
protected function setUp ()
56
55
{
57
- $ this ->attributeSetFinder = $ this ->getMock (AttributeSetFinderInterface::class);
58
- $ this ->productAttributeRepository = $ this ->getMock (ProductAttributeRepositoryInterface::class);
56
+ $ this ->attributeSetFinder = $ this ->getMockBuilder (AttributeSetFinderInterface::class)
57
+ ->disableOriginalConstructor ()
58
+ ->getMockForAbstractClass ();
59
59
$ this ->searchCriteriaBuilder = $ this ->getMockBuilder (SearchCriteriaBuilder::class)
60
60
->disableOriginalConstructor ()
61
61
->getMock ();
62
- $ this ->request = $ this ->getMock (RequestInterface::class);
62
+ $ this ->request = $ this ->getMockBuilder (RequestInterface::class)
63
+ ->disableOriginalConstructor ()
64
+ ->getMockForAbstractClass ();
63
65
$ this ->config = $ this ->getMockBuilder (Config::class)->disableOriginalConstructor ()->getMock ();
66
+ $ this ->attributeCollection = $ this ->getMockBuilder (
67
+ \Magento \Catalog \Model \ResourceModel \Product \Attribute \Collection::class
68
+ )
69
+ ->disableOriginalConstructor ()
70
+ ->getMock ();
64
71
65
72
$ this ->aggregationResolver = (new ObjectManager ($ this ))->getObject (
66
73
AggregationResolver::class,
67
74
[
68
75
'attributeSetFinder ' => $ this ->attributeSetFinder ,
69
- 'productAttributeRepository ' => $ this ->productAttributeRepository ,
70
76
'searchCriteriaBuilder ' => $ this ->searchCriteriaBuilder ,
71
77
'config ' => $ this ->config ,
78
+ 'attributeCollection ' => $ this ->attributeCollection ,
72
79
]
73
80
);
74
81
}
@@ -78,54 +85,50 @@ public function testResolve()
78
85
$ documentIds = [1 , 2 , 3 ];
79
86
$ attributeSetIds = [4 , 5 ];
80
87
$ requestName = 'request_name ' ;
81
-
88
+ $ select = $ this ->searchCriteriaBuilder = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
89
+ ->disableOriginalConstructor ()
90
+ ->getMock ();
91
+ $ adapter = $ this ->searchCriteriaBuilder = $ this ->getMockBuilder (
92
+ \Magento \Framework \DB \Adapter \AdapterInterface::class
93
+ )
94
+ ->disableOriginalConstructor ()
95
+ ->getMockForAbstractClass ();
82
96
$ this ->attributeSetFinder
83
97
->expects ($ this ->once ())
84
98
->method ('findAttributeSetIdsByProductIds ' )
85
99
->with ($ documentIds )
86
100
->willReturn ($ attributeSetIds );
87
-
88
- $ searchCriteria = $ this ->getMock (SearchCriteriaInterface::class);
89
-
90
- $ this ->searchCriteriaBuilder
91
- ->expects ($ this ->once ())
92
- ->method ('addFilter ' )
93
- ->with ('attribute_set_id ' , $ attributeSetIds , 'in ' )
101
+ $ this ->attributeCollection ->expects ($ this ->once ())
102
+ ->method ('setAttributeSetFilter ' )
103
+ ->with ($ attributeSetIds )
94
104
->willReturnSelf ();
95
- $ this ->searchCriteriaBuilder
96
- ->expects ($ this ->once ())
97
- ->method ('create ' )
98
- ->willReturn ($ searchCriteria );
99
-
100
- $ attributeFirst = $ this ->getMock (ProductAttributeInterface::class);
101
- $ attributeFirst ->expects ($ this ->once ())
102
- ->method ('getAttributeCode ' )
103
- ->willReturn ('code_1 ' );
104
- $ attributeSecond = $ this ->getMock (ProductAttributeInterface::class);
105
- $ attributeSecond ->expects ($ this ->once ())
106
- ->method ('getAttributeCode ' )
107
- ->willReturn ('code_2 ' );
108
-
109
- $ searchResult = $ this ->getMock (ProductAttributeSearchResultsInterface::class);
110
- $ searchResult ->expects ($ this ->once ())
111
- ->method ('getItems ' )
112
- ->willReturn ([$ attributeFirst , $ attributeSecond ]);
113
-
114
- $ this ->productAttributeRepository
115
- ->expects ($ this ->once ())
116
- ->method ('getList ' )
117
- ->with ($ searchCriteria )
118
- ->willReturn ($ searchResult );
119
-
120
- $ bucketFirst = $ this ->getMock (BucketInterface::class);
105
+ $ this ->attributeCollection ->expects ($ this ->once ())
106
+ ->method ('setEntityTypeFilter ' )
107
+ ->with (\Magento \Catalog \Api \Data \ProductAttributeInterface::ENTITY_TYPE_CODE )
108
+ ->willReturnSelf ();
109
+ $ this ->attributeCollection ->expects ($ this ->atLeastOnce ())
110
+ ->method ('getSelect ' )
111
+ ->willReturn ($ select );
112
+ $ select ->expects ($ this ->once ())->method ('reset ' )->with (\Magento \Framework \DB \Select::COLUMNS )->willReturnSelf ();
113
+ $ select ->expects ($ this ->once ())->method ('columns ' )->with ('attribute_code ' )->willReturnSelf ();
114
+ $ this ->attributeCollection ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ adapter );
115
+ $ adapter ->expects ($ this ->once ())->method ('fetchCol ' )->with ($ select )->willReturn (['code_1 ' , 'code_2 ' ]);
116
+
117
+ $ bucketFirst = $ this ->getMockBuilder (BucketInterface::class)
118
+ ->disableOriginalConstructor ()
119
+ ->getMockForAbstractClass ();
121
120
$ bucketFirst ->expects ($ this ->once ())
122
121
->method ('getField ' )
123
122
->willReturn ('code_1 ' );
124
- $ bucketSecond = $ this ->getMock (BucketInterface::class);
123
+ $ bucketSecond = $ this ->getMockBuilder (BucketInterface::class)
124
+ ->disableOriginalConstructor ()
125
+ ->getMockForAbstractClass ();
125
126
$ bucketSecond ->expects ($ this ->once ())
126
127
->method ('getField ' )
127
128
->willReturn ('some_another_code ' );
128
- $ bucketThird = $ this ->getMock (BucketInterface::class);
129
+ $ bucketThird = $ this ->getMockBuilder (BucketInterface::class)
130
+ ->disableOriginalConstructor ()
131
+ ->getMockForAbstractClass ();
129
132
$ bucketThird ->expects ($ this ->once ())
130
133
->method ('getName ' )
131
134
->willReturn ('custom_not_attribute_field ' );
0 commit comments