Skip to content
Prev Previous commit
Fix test assertions to match actual WP_Error behavior
Co-authored-by: dognose24 <[email protected]>
  • Loading branch information
Copilot and dognose24 committed Dec 9, 2025
commit e80c38bc36c2a8e3ff47faa79a3c6e70bf0d1cad
8 changes: 6 additions & 2 deletions projects/packages/stats/tests/php/WPCOM_Stats_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,10 +936,13 @@ public function test_fetch_post_stats_returns_cached_wp_error_within_expiration(

$stats = $this->wpcom_stats->get_post_views( $post_id, array(), true );

// Should return the cached WP_Error with cached_at timestamp.
// Should return the cached WP_Error as an array with cached_at timestamp.
// When a WP_Error is cached, it's converted to array and merged with cached_at.
$this->assertTrue( is_array( $stats ) );
$this->assertArrayHasKey( 'cached_at', $stats );
$this->assertSame( $time, $stats['cached_at'] );
// WP_Error properties are converted to array keys.
$this->assertArrayHasKey( 'errors', $stats );
}

/**
Expand Down Expand Up @@ -1045,8 +1048,9 @@ public function test_refresh_post_stats_cache_caches_error_response() {

$stats = $this->wpcom_stats->get_post_views( $post_id, array(), true );

// Should return the error.
// Should return the fresh WP_Error directly (not wrapped in array).
$this->assertTrue( is_wp_error( $stats ) );
$this->assertSame( 'stats_error', $stats->get_error_code() );

// Verify the error was cached.
$meta_name = '_' . WPCOM_Stats::STATS_CACHE_TRANSIENT_PREFIX;
Expand Down