11
11
use Magento \Framework \DB \Adapter \AdapterInterface ;
12
12
use Magento \Framework \DB \Logger \File ;
13
13
use Magento \Framework \DB \Logger \QueryAnalyzerException ;
14
+ use Magento \Framework \DB \Logger \QueryAnalyzerInterface ;
14
15
use Magento \Framework \DB \Logger \QueryIndexAnalyzer ;
15
16
use Magento \Framework \DB \LoggerInterface ;
16
17
use Magento \Framework \Exception \FileSystemException ;
@@ -51,18 +52,27 @@ protected function setUp(): void
51
52
/**
52
53
* @param string $sql
53
54
* @param array $bind
55
+ * @param int $serializeCall
54
56
* @param string $explainResult
55
57
* @param mixed $expectedResult
56
58
* @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
58
63
* @dataProvider statsDataProvider
59
64
*/
60
65
public function testProcess (
61
66
string $ sql ,
62
67
array $ bind ,
68
+ int $ serializeCall ,
63
69
string $ explainResult ,
64
70
mixed $ expectedResult
65
71
): void {
72
+ $ this ->serializer ->expects ($ this ->exactly ($ serializeCall ))
73
+ ->method ('serialize ' )
74
+ ->with ($ bind )
75
+ ->willReturn (json_encode ($ bind ));
66
76
$ statement = $ this ->createMock (\Zend_Db_Statement_Interface::class);
67
77
$ statement ->expects ($ this ->any ())->method ('fetchAll ' )->willReturn (json_decode ($ explainResult , true ));
68
78
$ connection = $ this ->createMock (AdapterInterface::class);
@@ -91,29 +101,33 @@ public static function statsDataProvider(): array
91
101
'no-stats-for-update-query ' => [
92
102
"UPDATE `admin_user_session` SET `updated_at` = '2025-07-23 14:42:02' WHERE (id=5) " ,
93
103
[],
104
+ 0 ,
94
105
'{} ' ,
95
- new \ InvalidArgumentException ("Can't process query type " )
106
+ new QueryAnalyzerException ("Can't process query type " )
96
107
],
97
108
'no-stats-for-insert-query ' => [
98
109
"INSERT INTO `table_logging_event` (`ip`, `x_forwarded_ip`, `event_code`, `time`, `action`, `info`,
99
110
`status`, `user`, `user_id`, `fullaction`, `error_message`) VALUES
100
111
(?, ?, ?, '2025-07-23 14:42:02', ?, ?, ?, ?, ?, ?, ?) " ,
101
112
[],
113
+ 0 ,
102
114
'{} ' ,
103
- new \ InvalidArgumentException ("Can't process query type " )
115
+ new QueryAnalyzerException ("Can't process query type " )
104
116
],
105
117
'no-stats-for-delete-query ' => [
106
118
"DELETE FROM `sales_order_grid` WHERE (entity_id IN
107
119
(SELECT `magento_sales_order_grid_archive`.`entity_id`
108
120
FROM `magento_sales_order_grid_archive`)) " ,
109
121
[],
122
+ 0 ,
110
123
'{} ' ,
111
- new \ InvalidArgumentException ("Can't process query type " )
124
+ new QueryAnalyzerException ("Can't process query type " )
112
125
],
113
126
'small-table-query ' => [
114
127
"SELECT `main_table`.* FROM `admin_system_messages` AS `main_table`
115
128
ORDER BY severity ASC, created_at DESC " ,
116
129
[],
130
+ 1 ,
117
131
'[{"id":"1","select_type":"SIMPLE","table":"admin_system_messages","partitions":null,"type":"ALL",
118
132
"possible_keys":null,"key":null,"key_len":null,"ref":null,"rows":"1","filtered":"100.00",
119
133
"Extra":"Using filesort"}] ' ,
@@ -130,6 +144,7 @@ public static function statsDataProvider(): array
130
144
)) AS `status` FROM `magento_bulk` AS `main_table` WHERE (`user_id` = '1')
131
145
ORDER BY FIELD(status, 2,3,0,4,1), start_time DESC " ,
132
146
[],
147
+ 1 ,
133
148
'[{"id":"1","select_type":"PRIMARY","table":"main_table","partitions":null,"type":"ref",
134
149
"possible_keys":"MAGENTO_BULK_USER_ID","key":"MAGENTO_BULK_USER_ID","key_len":"5","ref":"const",
135
150
"rows":"1","filtered":"100.00","Extra":"Using filesort"},{"id":"3","select_type":"DEPENDENT SUBQUERY",
@@ -140,18 +155,23 @@ public static function statsDataProvider(): array
140
155
"type":"ref","possible_keys":"MAGENTO_OPERATION_BULK_UUID_ERROR_CODE","key":
141
156
"MAGENTO_OPERATION_BULK_UUID_ERROR_CODE","key_len":"42","ref":
142
157
"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
+ ]
144
163
],
145
- 'simple-qeury -partial-index ' => [
164
+ 'simple-query -partial-index ' => [
146
165
"SELECT `o`.`product_type`, COUNT(*) FROM `sales_order_item` AS `o` WHERE (o.order_id='67') AND
147
166
(o.product_id IS NOT NULL) AND ((o.product_type NOT IN
148
167
('simple', 'virtual', 'bundle', 'downloadable', 'configurable', 'grouped')))
149
168
GROUP BY `o`.`product_type` " ,
150
169
[],
170
+ 1 ,
151
171
'[{"id":1,"select_type":"SIMPLE","table":"o","partitions":null,"type":"ref","possible_keys":
152
172
"SALES_ORDER_ITEM_ORDER_ID","key":"SALES_ORDER_ITEM_ORDER_ID","key_len":"4","ref":"const",
153
173
"rows":2,"filtered":45,"Extra":"Using where; Using temporary"}] ' ,
154
- [' PARTIAL INDEX USED ' ]
174
+ [QueryAnalyzerInterface:: PARTIAL_INDEX ]
155
175
],
156
176
'full-table-scan-no-index ' => [
157
177
"SELECT `main_table`.`entity_type_id`, `main_table`.`attribute_code`, `main_table`.`attribute_model`,
@@ -165,13 +185,14 @@ public static function statsDataProvider(): array
165
185
OR (`is_visible_in_advanced_search` = '1') OR (((`is_filterable` = '1') OR (`is_filterable` = '2')))
166
186
OR (`is_filterable_in_search` = '1')) " ,
167
187
[],
188
+ 1 ,
168
189
'[{"id":1,"select_type":"SIMPLE","table":"additional_table","partitions":null,"type":"ALL",
169
190
"possible_keys":"PRIMARY","key":null,"key_len":null,"ref":null,"rows":170,"filtered":40.95,"Extra":
170
191
"Using where"},{"id":1,"select_type":"SIMPLE","table":"main_table","partitions":null,"type":"eq_ref",
171
192
"possible_keys":"PRIMARY,EAV_ATTRIBUTE_ENTITY_TYPE_ID_ATTRIBUTE_CODE","key":"PRIMARY",
172
193
"key_len":"2","ref":"magento24i2.additional_table.attribute_id","rows":1,"filtered":58.72,
173
194
"Extra":"Using where"}] ' ,
174
- [' FULL TABLE SCAN ' , ' NO INDEX ' ]
195
+ [QueryAnalyzerInterface:: FULL_TABLE_SCAN , QueryAnalyzerInterface:: NO_INDEX ]
175
196
],
176
197
];
177
198
}
0 commit comments