77
88namespace Magento \CatalogGraphQl \Test \Unit \Model \Resolver \Products \Query ;
99
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 ;
1016use Magento \Framework \Api \Search \SearchCriteriaInterface ;
1117use Magento \Framework \Api \Search \SearchResultInterface ;
1218use Magento \Framework \GraphQl \Query \Resolver \ArgumentsProcessorInterface ;
1319use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
14- use Magento \GraphQl \Model \Query \ContextInterface ;
1520use 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 ;
2422use Magento \Search \Api \SearchInterface ;
23+ use Magento \Search \Model \Search \PageSizeProvider ;
2524use Magento \Store \Api \Data \StoreInterface ;
2625use PHPUnit \Framework \MockObject \MockObject ;
2726use PHPUnit \Framework \TestCase ;
2827
29-
3028/**
3129 * Test for fulltext search query
3230 */
@@ -68,9 +66,9 @@ class SearchTest extends TestCase
6866 private $ searchCriteriaBuilder ;
6967
7068 /**
71- * @var QueryFactory |MockObject
69+ * @var QueryPopularity |MockObject
7270 */
73- private $ queryFactory ;
71+ private $ queryPopularity ;
7472
7573 /**
7674 * @var Search
@@ -104,7 +102,7 @@ protected function setUp(): void
104102 $ this ->searchCriteriaBuilder = $ this ->getMockBuilder (SearchCriteriaBuilder::class)
105103 ->disableOriginalConstructor ()
106104 ->getMock ();
107- $ this ->queryFactory = $ this ->getMockBuilder (QueryFactory ::class)
105+ $ this ->queryPopularity = $ this ->getMockBuilder (QueryPopularity ::class)
108106 ->disableOriginalConstructor ()
109107 ->getMock ();
110108 $ this ->model = new Search (
@@ -115,21 +113,20 @@ protected function setUp(): void
115113 $ this ->productsProvider ,
116114 $ this ->searchCriteriaBuilder ,
117115 $ this ->argsSelection ,
118- $ this ->queryFactory
116+ $ this ->queryPopularity
119117 );
120118 }
121119
122120 public function testPopulateSearchQueryStats (): void
123121 {
124122 $ args = ['search ' => 'test ' ];
125- $ storeId = 1 ;
126-
127123 $ context = $ this ->getMockBuilder (ContextInterface::class)
128124 ->disableOriginalConstructor ()
129125 ->getMockForAbstractClass ();
130126 $ resolveInfo = $ this ->getMockBuilder (ResolveInfo::class)
131127 ->disableOriginalConstructor ()
132128 ->getMock ();
129+
133130 $ searchCriteria = $ this ->getMockBuilder (SearchCriteriaInterface::class)
134131 ->disableOriginalConstructor ()
135132 ->getMockForAbstractClass ();
@@ -143,29 +140,13 @@ public function testPopulateSearchQueryStats(): void
143140 ->method ('search ' )
144141 ->with ($ searchCriteria )
145142 ->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 );
166143 $ this ->productsProvider ->expects ($ this ->any ())->method ('getList ' )->willReturn ($ results );
167144 $ results ->expects ($ this ->any ())->method ('getItems ' )->willReturn ([]);
168145
146+ $ this ->queryPopularity ->expects ($ this ->once ())
147+ ->method ('execute ' )
148+ ->with ($ context , $ args ['search ' ], 0 );
149+
169150 $ this ->model ->getResult ($ args , $ resolveInfo , $ context );
170151 }
171152}
0 commit comments