Skip to content

Commit b75838f

Browse files
Simplify URL Metric addition logic and remove unnecessary exception handling
Co-authored-by: Weston Ruter <[email protected]>
1 parent fe93912 commit b75838f

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

plugins/optimization-detective/tests/class-optimization-detective-test-helpers.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,7 @@ public function store_url_metric( string $slug, OD_URL_Metric $new_url_metric )
185185
od_get_url_metric_freshness_ttl()
186186
);
187187

188-
try {
189-
$group = $group_collection->get_group_for_viewport_width( $new_url_metric->get_viewport_width() );
190-
$group->add_url_metric( $new_url_metric );
191-
} catch ( InvalidArgumentException $e ) {
192-
return new WP_Error( 'invalid_url_metric', $e->getMessage() );
193-
}
188+
$group_collection->add_url_metric( $new_url_metric );
194189

195190
return OD_URL_Metrics_Post_Type::update_post( $slug, $group_collection );
196191
}

plugins/optimization-detective/tests/storage/test-class-od-url-metrics-post-type.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ public function test_update_post(): void {
217217
)
218218
);
219219

220-
$url_metric_group = $url_metric_group_collection->get_group_for_viewport_width( $validated_url_metric->get_viewport_width() );
221-
$url_metric_group->add_url_metric( $validated_url_metric );
220+
$url_metric_group = $url_metric_group_collection->add_url_metric( $validated_url_metric );
222221
$post_id = OD_URL_Metrics_Post_Type::update_post( $slug, $url_metric_group_collection );
223222
$this->assertIsInt( $post_id );
224223

@@ -232,8 +231,7 @@ public function test_update_post(): void {
232231
$url_metrics = OD_URL_Metrics_Post_Type::get_url_metrics_from_post( $post );
233232
$this->assertCount( 1, $url_metrics );
234233

235-
$url_metric_group = $url_metric_group_collection->get_group_for_viewport_width( $another_validated_url_metric->get_viewport_width() );
236-
$url_metric_group->add_url_metric( $another_validated_url_metric );
234+
$url_metric_group_collection->add_url_metric( $another_validated_url_metric );
237235
$again_post_id = OD_URL_Metrics_Post_Type::update_post( $slug, $url_metric_group_collection );
238236
$again_post = get_post( $again_post_id );
239237
$this->assertInstanceOf( WP_Post::class, $again_post );

0 commit comments

Comments
 (0)