1111use Magento \Framework \DB \Adapter \AdapterInterface ;
1212use Magento \Framework \DB \Logger \File ;
1313use Magento \Framework \DB \Logger \QueryAnalyzerException ;
14+ use Magento \Framework \DB \Logger \QueryAnalyzerInterface ;
1415use Magento \Framework \DB \Logger \QueryIndexAnalyzer ;
1516use Magento \Framework \DB \LoggerInterface ;
1617use Magento \Framework \Exception \FileSystemException ;
@@ -51,18 +52,27 @@ protected function setUp(): void
5152 /**
5253 * @param string $sql
5354 * @param array $bind
55+ * @param int $serializeCall
5456 * @param string $explainResult
5557 * @param mixed $expectedResult
5658 * @return void
57- * @throws Exception|\Magento\Framework\DB\Logger\QueryAnalyzerException|\Zend_Db_Statement_Exception
59+ * @throws Exception
60+ * @throws QueryAnalyzerException
61+ * @throws \Zend_Db_Statement_Exception
62+ * @testdox $sql with bindings $bind to get $expectedResult
5863 * @dataProvider statsDataProvider
5964 */
6065 public function testProcess (
6166 string $ sql ,
6267 array $ bind ,
68+ int $ serializeCall ,
6369 string $ explainResult ,
6470 mixed $ expectedResult
6571 ): void {
72+ $ this ->serializer ->expects ($ this ->exactly ($ serializeCall ))
73+ ->method ('serialize ' )
74+ ->with ($ bind )
75+ ->willReturn (json_encode ($ bind ));
6676 $ statement = $ this ->createMock (\Zend_Db_Statement_Interface::class);
6777 $ statement ->expects ($ this ->any ())->method ('fetchAll ' )->willReturn (json_decode ($ explainResult , true ));
6878 $ connection = $ this ->createMock (AdapterInterface::class);
@@ -91,29 +101,33 @@ public static function statsDataProvider(): array
91101 'no-stats-for-update-query ' => [
92102 "UPDATE `admin_user_session` SET `updated_at` = '2025-07-23 14:42:02' WHERE (id=5) " ,
93103 [],
104+ 0 ,
94105 '{} ' ,
95- new \ InvalidArgumentException ("Can't process query type " )
106+ new QueryAnalyzerException ("Can't process query type " )
96107 ],
97108 'no-stats-for-insert-query ' => [
98109 "INSERT INTO `table_logging_event` (`ip`, `x_forwarded_ip`, `event_code`, `time`, `action`, `info`,
99110 `status`, `user`, `user_id`, `fullaction`, `error_message`) VALUES
100111 (?, ?, ?, '2025-07-23 14:42:02', ?, ?, ?, ?, ?, ?, ?) " ,
101112 [],
113+ 0 ,
102114 '{} ' ,
103- new \ InvalidArgumentException ("Can't process query type " )
115+ new QueryAnalyzerException ("Can't process query type " )
104116 ],
105117 'no-stats-for-delete-query ' => [
106118 "DELETE FROM `sales_order_grid` WHERE (entity_id IN
107119 (SELECT `magento_sales_order_grid_archive`.`entity_id`
108120 FROM `magento_sales_order_grid_archive`)) " ,
109121 [],
122+ 0 ,
110123 '{} ' ,
111- new \ InvalidArgumentException ("Can't process query type " )
124+ new QueryAnalyzerException ("Can't process query type " )
112125 ],
113126 'small-table-query ' => [
114127 "SELECT `main_table`.* FROM `admin_system_messages` AS `main_table`
115128 ORDER BY severity ASC, created_at DESC " ,
116129 [],
130+ 1 ,
117131 '[{"id":"1","select_type":"SIMPLE","table":"admin_system_messages","partitions":null,"type":"ALL",
118132 "possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":"1","filtered":"100.00",
119133 "Extra":"Using filesort"}] ' ,
@@ -130,6 +144,7 @@ public static function statsDataProvider(): array
130144 )) AS `status` FROM `magento_bulk` AS `main_table` WHERE (`user_id` = '1')
131145 ORDER BY FIELD(status, 2,3,0,4,1), start_time DESC " ,
132146 [],
147+ 1 ,
133148 '[{"id":"1","select_type":"PRIMARY","table":"main_table","partitions":null,"type":"ref",
134149 "possible_keys":"MAGENTO_BULK_USER_ID","key":"MAGENTO_BULK_USER_ID","key_len":"5","ref":"const",
135150 "rows":"1","filtered":"100.00","Extra":"Using filesort"},{"id":"3","select_type":"DEPENDENT SUBQUERY",
@@ -140,18 +155,23 @@ public static function statsDataProvider(): array
140155 "type":"ref","possible_keys":"MAGENTO_OPERATION_BULK_UUID_ERROR_CODE","key":
141156 "MAGENTO_OPERATION_BULK_UUID_ERROR_CODE","key_len":"42","ref":
142157 "magento24i2.main_table.uuid","rows":"1","filtered":"100.00","Extra":"Using index"}] ' ,
143- ['FILESORT ' , 'PARTIAL INDEX USED ' , 'DEPENDENT SUBQUERY ' ]
158+ [
159+ QueryAnalyzerInterface::FILESORT ,
160+ QueryAnalyzerInterface::PARTIAL_INDEX ,
161+ QueryAnalyzerInterface::DEPENDENT_SUBQUERY
162+ ]
144163 ],
145- 'simple-qeury -partial-index ' => [
164+ 'simple-query -partial-index ' => [
146165 "SELECT `o`.`product_type`, COUNT(*) FROM `sales_order_item` AS `o` WHERE (o.order_id='67') AND
147166 (o.product_id IS NOT NULL) AND ((o.product_type NOT IN
148167 ('simple', 'virtual', 'bundle', 'downloadable', 'configurable', 'grouped')))
149168 GROUP BY `o`.`product_type` " ,
150169 [],
170+ 1 ,
151171 '[{"id":1,"select_type":"SIMPLE","table":"o","partitions":null,"type":"ref","possible_keys":
152172 "SALES_ORDER_ITEM_ORDER_ID","key":"SALES_ORDER_ITEM_ORDER_ID","key_len":"4","ref":"const",
153173 "rows":2,"filtered":45,"Extra":"Using where; Using temporary"}] ' ,
154- [' PARTIAL INDEX USED ' ]
174+ [QueryAnalyzerInterface:: PARTIAL_INDEX ]
155175 ],
156176 'full-table-scan-no-index ' => [
157177 "SELECT `main_table`.`entity_type_id`, `main_table`.`attribute_code`, `main_table`.`attribute_model`,
@@ -165,13 +185,14 @@ public static function statsDataProvider(): array
165185 OR (`is_visible_in_advanced_search` = '1') OR (((`is_filterable` = '1') OR (`is_filterable` = '2')))
166186 OR (`is_filterable_in_search` = '1')) " ,
167187 [],
188+ 1 ,
168189 '[{"id":1,"select_type":"SIMPLE","table":"additional_table","partitions":null,"type":"ALL",
169190 "possible_keys":"PRIMARY","key":null,"key_len":null,"ref":null,"rows":170,"filtered":40.95,"Extra":
170191 "Using where"},{"id":1,"select_type":"SIMPLE","table":"main_table","partitions":null,"type":"eq_ref",
171192 "possible_keys":"PRIMARY,EAV_ATTRIBUTE_ENTITY_TYPE_ID_ATTRIBUTE_CODE","key":"PRIMARY",
172193 "key_len":"2","ref":"magento24i2.additional_table.attribute_id","rows":1,"filtered":58.72,
173194 "Extra":"Using where"}] ' ,
174- [' FULL TABLE SCAN ' , ' NO INDEX ' ]
195+ [QueryAnalyzerInterface:: FULL_TABLE_SCAN , QueryAnalyzerInterface:: NO_INDEX ]
175196 ],
176197 ];
177198 }
0 commit comments