7
7
8
8
namespace Magento \CatalogGraphQl \Test \Unit \Model \Resolver \Products \Query ;
9
9
10
+ use Magento \CatalogGraphQl \DataProvider \Product \SearchCriteriaBuilder ;
11
+ use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \ProductSearch ;
12
+ use Magento \CatalogGraphQl \Model \Resolver \Products \Query \FieldSelection ;
13
+ use Magento \CatalogGraphQl \Model \Resolver \Products \Query \Search ;
14
+ use Magento \CatalogGraphQl \Model \Resolver \Products \Query \Search \QueryPopularity ;
15
+ use Magento \CatalogGraphQl \Model \Resolver \Products \SearchResultFactory ;
10
16
use Magento \Framework \Api \Search \SearchCriteriaInterface ;
11
17
use Magento \Framework \Api \Search \SearchResultInterface ;
12
18
use Magento \Framework \GraphQl \Query \Resolver \ArgumentsProcessorInterface ;
13
19
use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14
- use Magento \GraphQl \Model \Query \ContextInterface ;
15
20
use Magento \GraphQl \Model \Query \ContextExtensionInterface ;
16
- use Magento \CatalogGraphQl \Model \Resolver \Products \SearchResultFactory ;
17
- use Magento \CatalogGraphQl \Model \Resolver \Products \Query \FieldSelection ;
18
- use Magento \CatalogGraphQl \Model \Resolver \Products \DataProvider \ProductSearch ;
19
- use Magento \CatalogGraphQl \DataProvider \Product \SearchCriteriaBuilder ;
20
- use Magento \CatalogGraphQl \Model \Resolver \Products \Query \Search ;
21
- use Magento \Search \Model \QueryFactory ;
22
- use Magento \Search \Model \Query ;
23
- use Magento \Search \Model \Search \PageSizeProvider ;
21
+ use Magento \GraphQl \Model \Query \ContextInterface ;
24
22
use Magento \Search \Api \SearchInterface ;
23
+ use Magento \Search \Model \Search \PageSizeProvider ;
25
24
use Magento \Store \Api \Data \StoreInterface ;
26
25
use PHPUnit \Framework \MockObject \MockObject ;
27
26
use PHPUnit \Framework \TestCase ;
28
27
29
-
30
28
/**
31
29
* Test for fulltext search query
32
30
*/
@@ -68,9 +66,9 @@ class SearchTest extends TestCase
68
66
private $ searchCriteriaBuilder ;
69
67
70
68
/**
71
- * @var QueryFactory |MockObject
69
+ * @var QueryPopularity |MockObject
72
70
*/
73
- private $ queryFactory ;
71
+ private $ queryPopularity ;
74
72
75
73
/**
76
74
* @var Search
@@ -104,7 +102,7 @@ protected function setUp(): void
104
102
$ this ->searchCriteriaBuilder = $ this ->getMockBuilder (SearchCriteriaBuilder::class)
105
103
->disableOriginalConstructor ()
106
104
->getMock ();
107
- $ this ->queryFactory = $ this ->getMockBuilder (QueryFactory ::class)
105
+ $ this ->queryPopularity = $ this ->getMockBuilder (QueryPopularity ::class)
108
106
->disableOriginalConstructor ()
109
107
->getMock ();
110
108
$ this ->model = new Search (
@@ -115,21 +113,20 @@ protected function setUp(): void
115
113
$ this ->productsProvider ,
116
114
$ this ->searchCriteriaBuilder ,
117
115
$ this ->argsSelection ,
118
- $ this ->queryFactory
116
+ $ this ->queryPopularity
119
117
);
120
118
}
121
119
122
120
public function testPopulateSearchQueryStats (): void
123
121
{
124
122
$ args = ['search ' => 'test ' ];
125
- $ storeId = 1 ;
126
-
127
123
$ context = $ this ->getMockBuilder (ContextInterface::class)
128
124
->disableOriginalConstructor ()
129
125
->getMockForAbstractClass ();
130
126
$ resolveInfo = $ this ->getMockBuilder (ResolveInfo::class)
131
127
->disableOriginalConstructor ()
132
128
->getMock ();
129
+
133
130
$ searchCriteria = $ this ->getMockBuilder (SearchCriteriaInterface::class)
134
131
->disableOriginalConstructor ()
135
132
->getMockForAbstractClass ();
@@ -143,29 +140,13 @@ public function testPopulateSearchQueryStats(): void
143
140
->method ('search ' )
144
141
->with ($ searchCriteria )
145
142
->willReturn ($ results );
146
- $ query = $ this ->getMockBuilder (Query::class)
147
- ->disableOriginalConstructor ()
148
- ->getMock ();
149
- $ query ->expects ($ this ->once ())->method ('setStoreId ' )->with ($ storeId );
150
- $ query ->expects ($ this ->once ())->method ('saveIncrementalPopularity ' );
151
- $ query ->expects ($ this ->once ())->method ('saveNumResults ' );
152
- $ this ->queryFactory ->expects ($ this ->once ())
153
- ->method ('get ' )
154
- ->willReturn ($ query );
155
- $ extensionAttributes = $ this ->getMockBuilder (ContextExtensionInterface::class)
156
- ->disableOriginalConstructor ()
157
- ->getMockForAbstractClass ();
158
- $ context ->expects ($ this ->any ())
159
- ->method ('getExtensionAttributes ' )
160
- ->willReturn ($ extensionAttributes );
161
- $ store = $ this ->getMockBuilder (StoreInterface::class)
162
- ->disableOriginalConstructor ()
163
- ->getMockForAbstractClass ();
164
- $ store ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ storeId );
165
- $ extensionAttributes ->expects ($ this ->any ())->method ('getStore ' )->willReturn ($ store );
166
143
$ this ->productsProvider ->expects ($ this ->any ())->method ('getList ' )->willReturn ($ results );
167
144
$ results ->expects ($ this ->any ())->method ('getItems ' )->willReturn ([]);
168
145
146
+ $ this ->queryPopularity ->expects ($ this ->once ())
147
+ ->method ('execute ' )
148
+ ->with ($ context , $ args ['search ' ], 0 );
149
+
169
150
$ this ->model ->getResult ($ args , $ resolveInfo , $ context );
170
151
}
171
152
}
0 commit comments