Skip to content

Commit 5ee4148

Browse files
authored
Merge pull request #1701 from equalizedigital/william/add-some-tests-for-rest-api-callbacks
Fix some phpcs issues in merged tests
2 parents 1bea54e + 6622d54 commit 5ee4148

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

tests/phpunit/includes/classes/RestApiEndpointsTest.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class RestApiEndpointsTest extends WP_UnitTestCase {
5151
*
5252
* @return void
5353
*/
54-
protected function setUp(): void {
54+
public function setUp(): void {
5555
parent::setUp();
5656
// Initialize REST routes for each test.
5757
do_action( 'init' );
@@ -64,7 +64,7 @@ protected function setUp(): void {
6464
*
6565
* @return void
6666
*/
67-
protected function tearDown(): void {
67+
public function tearDown(): void {
6868
// Reset current user between tests.
6969
wp_set_current_user( 0 );
7070
parent::tearDown();
@@ -241,8 +241,11 @@ public function test_scans_stats_permissions_and_payload() {
241241
$this->assertArrayHasKey( 'success', $data );
242242
$this->assertTrue( $data['success'] );
243243
$this->assertArrayHasKey( 'stats', $data );
244-
// Verify stats structure is an array.
244+
// Verify stats structure is an array and includes a stable summary metric key.
245245
$this->assertIsArray( $data['stats'] );
246+
if ( ! empty( $data['stats'] ) ) {
247+
$this->assertArrayHasKey( 'scannable_posts_count', $data['stats'] );
248+
}
246249

247250
wp_set_current_user( self::$subscriber_id );
248251
$request2 = new WP_REST_Request( 'GET', '/accessibility-checker/v1/scans-stats' );
@@ -317,12 +320,14 @@ public function test_scans_stats_by_post_types_permissions_and_payload() {
317320
$this->assertArrayHasKey( 'success', $data );
318321
$this->assertTrue( $data['success'] );
319322
$this->assertArrayHasKey( 'stats', $data );
320-
// Verify stats structure is an array keyed by post type.
323+
// Verify stats structure is a keyed map where each key is a post type slug.
321324
$this->assertIsArray( $data['stats'] );
322325
if ( ! empty( $data['stats'] ) ) {
323326
foreach ( $data['stats'] as $post_type => $stat ) {
324327
$this->assertIsString( $post_type );
325-
$this->assertTrue( $stat === false || is_array( $stat ) );
328+
$this->assertNotSame( '', $post_type );
329+
// Each value is either false (non-scannable) or a summary array (scannable).
330+
$this->assertTrue( false === $stat || is_array( $stat ) );
326331
}
327332
}
328333

0 commit comments

Comments
 (0)