From 970a3d2ffff076ad46bd6d8b0640c7beec0c95aa Mon Sep 17 00:00:00 2001 From: Sukhendu Sekhar Guria Date: Mon, 25 May 2026 14:23:09 +0530 Subject: [PATCH] Tests: Fix MockAction::get_call_count() for filters --- tests/phpunit/includes/utils.php | 4 ++-- tests/phpunit/tests/rest-api/rest-controller.php | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/includes/utils.php b/tests/phpunit/includes/utils.php index a7c4466338b5d..b830162c1f68f 100644 --- a/tests/phpunit/includes/utils.php +++ b/tests/phpunit/includes/utils.php @@ -223,7 +223,7 @@ public function get_events() { } /** - * Returns a count of the number of times the action was called since the last reset. + * Returns a count of the number of times the hook was called since the last reset. * * @since UT (3.7.0) */ @@ -232,7 +232,7 @@ public function get_call_count( $hook_name = '' ) { $count = 0; foreach ( $this->events as $e ) { - if ( $e['action'] === $hook_name ) { + if ( $e['hook_name'] === $hook_name ) { ++$count; } } diff --git a/tests/phpunit/tests/rest-api/rest-controller.php b/tests/phpunit/tests/rest-api/rest-controller.php index 33ac4f3c814f7..bd976d56be8d3 100644 --- a/tests/phpunit/tests/rest-api/rest-controller.php +++ b/tests/phpunit/tests/rest-api/rest-controller.php @@ -467,13 +467,13 @@ public function test_get_fields_for_response_filters_by_context() { $controller->prepare_item_for_response( array(), $request ); - $this->assertSame( 0, $listener->get_call_count( $method ) ); + $this->assertSame( 0, $listener->get_call_count() ); $request->set_param( 'context', 'embed' ); $controller->prepare_item_for_response( array(), $request ); - $this->assertGreaterThan( 0, $listener->get_call_count( $method ) ); + $this->assertGreaterThan( 0, $listener->get_call_count() ); } public function test_filtering_fields_for_response_by_context_returns_fields_with_no_context() { @@ -501,7 +501,7 @@ public function test_filtering_fields_for_response_by_context_returns_fields_wit $controller->prepare_item_for_response( array(), $request ); - $this->assertGreaterThan( 0, $listener->get_call_count( $method ) ); + $this->assertGreaterThan( 0, $listener->get_call_count() ); } public function test_filtering_fields_for_response_by_context_returns_fields_with_no_schema() { @@ -526,7 +526,7 @@ public function test_filtering_fields_for_response_by_context_returns_fields_wit $controller->prepare_item_for_response( array(), $request ); - $this->assertGreaterThan( 0, $listener->get_call_count( $method ) ); + $this->assertGreaterThan( 0, $listener->get_call_count() ); } /** @@ -586,7 +586,7 @@ public function test_add_additional_fields_to_object_respects_fields_param() { $controller->prepare_item_for_response( $item, $request ); - $first_call_count = $listener->get_call_count( $method ); + $first_call_count = $listener->get_call_count(); $this->assertGreaterThan( 0, $first_call_count ); @@ -594,13 +594,13 @@ public function test_add_additional_fields_to_object_respects_fields_param() { $controller->prepare_item_for_response( $item, $request ); - $this->assertSame( $first_call_count, $listener->get_call_count( $method ) ); + $this->assertSame( $first_call_count, $listener->get_call_count() ); $request->set_param( '_fields', $field ); $controller->prepare_item_for_response( $item, $request ); - $this->assertGreaterThan( $first_call_count, $listener->get_call_count( $method ) ); + $this->assertGreaterThan( $first_call_count, $listener->get_call_count() ); } /**