@@ -4190,6 +4190,71 @@ public function testGetBroadcastStatsWithInvalidBroadcastID()
41904190 $ this ->api ->get_broadcast_stats (12345 );
41914191 }
41924192
4193+ /**
4194+ * Test that get_broadcasts_stats() returns the expected data.
4195+ *
4196+ * @since 2.2.1
4197+ *
4198+ * @return void
4199+ */
4200+ public function testGetBroadcastsStats ()
4201+ {
4202+ // Get broadcasts stats.
4203+ $ result = $ this ->api ->get_broadcasts_stats (
4204+ per_page: 1
4205+ );
4206+
4207+ // Assert broadcasts and pagination exist.
4208+ $ this ->assertDataExists ($ result , 'broadcasts ' );
4209+ $ this ->assertPaginationExists ($ result );
4210+
4211+ // Assert a single broadcast was returned.
4212+ $ this ->assertCount (1 , $ result ->broadcasts );
4213+
4214+ // Store the Broadcast ID to check it's different from the next broadcast.
4215+ $ id = $ result ->broadcasts [0 ]->id ;
4216+
4217+ // Assert has_previous_page and has_next_page are correct.
4218+ $ this ->assertFalse ($ result ->pagination ->has_previous_page );
4219+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
4220+
4221+ // Use pagination to fetch next page.
4222+ $ result = $ this ->api ->get_broadcasts_stats (
4223+ per_page: 1 ,
4224+ after_cursor: $ result ->pagination ->end_cursor
4225+ );
4226+
4227+ // Assert broadcasts and pagination exist.
4228+ $ this ->assertDataExists ($ result , 'broadcasts ' );
4229+ $ this ->assertPaginationExists ($ result );
4230+
4231+ // Assert a single broadcast was returned.
4232+ $ this ->assertCount (1 , $ result ->broadcasts );
4233+
4234+ // Assert the broadcast ID is different from the previous broadcast.
4235+ $ this ->assertNotEquals ($ id , $ result ->broadcasts [0 ]->id );
4236+
4237+ // Assert has_previous_page and has_next_page are correct.
4238+ $ this ->assertTrue ($ result ->pagination ->has_previous_page );
4239+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
4240+
4241+ // Use pagination to fetch previous page.
4242+ $ result = $ this ->api ->get_broadcasts_stats (
4243+ per_page: 1 ,
4244+ before_cursor: $ result ->pagination ->start_cursor
4245+ );
4246+
4247+ // Assert broadcasts and pagination exist.
4248+ $ this ->assertDataExists ($ result , 'broadcasts ' );
4249+ $ this ->assertPaginationExists ($ result );
4250+
4251+ // Assert a single webhook was returned.
4252+ $ this ->assertCount (1 , $ result ->broadcasts );
4253+
4254+ // Assert the broadcast ID matches the first broadcast.
4255+ $ this ->assertEquals ($ id , $ result ->broadcasts [0 ]->id );
4256+ }
4257+
41934258 /**
41944259 * Test that update_broadcast() throws a ClientException when an invalid
41954260 * broadcast ID is specified.
0 commit comments