File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed
plugins/optimization-detective/tests Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change @@ -443,20 +443,26 @@ public function data_provider_test_get_lcp_element_when_group_half_stale(): arra
443
443
* @param bool $order_reversed Whether the order of URL Metrics should be reversed.
444
444
*/
445
445
public function test_get_lcp_element_when_group_half_stale ( bool $ order_reversed ): void {
446
- $ current_etag = 'f8527651f96776745f88cc49df70b62d ' ;
447
-
448
446
$ url_metrics_data = json_decode ( file_get_contents ( __DIR__ . '/data/url-metrics/tablet-viewport-half-stale.json ' ), true );
449
447
if ( $ order_reversed ) {
450
448
$ url_metrics_data = array_reverse ( $ url_metrics_data );
451
449
}
450
+ $ url_metrics = array ();
451
+ $ etag_counts = array ();
452
+ foreach ( $ url_metrics_data as $ url_metric_data ) {
453
+ $ url_metric = new OD_URL_Metric ( $ url_metric_data );
454
+ $ etag = $ url_metric ->get_etag ();
455
+ if ( ! isset ( $ etag_counts [ $ etag ] ) ) {
456
+ $ etag_counts [ $ etag ] = 0 ;
457
+ }
458
+ ++$ etag_counts [ $ etag ];
459
+ $ url_metrics [] = $ url_metric ;
460
+ }
461
+ arsort ( $ etag_counts );
462
+ $ current_etag = key ( $ etag_counts ); // The ETag used most often.
452
463
453
464
$ collection = new OD_URL_Metric_Group_Collection (
454
- array_map (
455
- static function ( array $ url_metric_data ): OD_URL_Metric {
456
- return new OD_URL_Metric ( $ url_metric_data );
457
- },
458
- $ url_metrics_data
459
- ),
465
+ $ url_metrics ,
460
466
$ current_etag ,
461
467
array ( 480 , 600 , 782 ),
462
468
3 ,
You can’t perform that action at this time.
0 commit comments