From e2be1be6e4c2b451edac70ebd6f10e8f82b345d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20W=C3=BCnsch?= Date: Fri, 14 Aug 2026 13:34:02 +0200 Subject: [PATCH] Tests: Use the modern PHPUnit stubbing and matcher shorthands. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces `will( $this->returnValue( … ) )` with `willReturn( … )` and drops a redundant `$this->equalTo()` wrapper from a `with()` call. Both are pure shorthands: `with()` wraps non-constraint arguments in `equalTo()` itself, and `willReturn()` has been available since PHPUnit 5.4, while the test suite requires 5.7.21 as a minimum. The `willReturn()` call in `PluralFormsTest::test_cache()` was originally written that way and switched to the long form in [41725] for compatibility with the PHPUnit versions supported at the time. That constraint no longer applies. The `$this->identicalTo()` matcher in the same block is deliberately left in place, as it asserts strict rather than loose equality. These were the last remaining occurrences of the legacy stub API in the test suite. --- tests/phpunit/tests/pomo/pluralForms.php | 2 +- tests/phpunit/tests/rest-api/rest-server.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/pomo/pluralForms.php b/tests/phpunit/tests/pomo/pluralForms.php index 0329374e94df8..8813336e37069 100644 --- a/tests/phpunit/tests/pomo/pluralForms.php +++ b/tests/phpunit/tests/pomo/pluralForms.php @@ -233,7 +233,7 @@ public function test_cache() { $mock->expects( $this->once() ) ->method( 'execute' ) ->with( $this->identicalTo( 2 ) ) - ->will( $this->returnValue( 1 ) ); + ->willReturn( 1 ); $first = $mock->get( 2 ); $second = $mock->get( 2 ); diff --git a/tests/phpunit/tests/rest-api/rest-server.php b/tests/phpunit/tests/rest-api/rest-server.php index b8e8cc6f5adcb..dce5a045f73db 100644 --- a/tests/phpunit/tests/rest-api/rest-server.php +++ b/tests/phpunit/tests/rest-api/rest-server.php @@ -652,7 +652,7 @@ public function test_json_error_with_status() { $stub->expects( $this->once() ) ->method( 'set_status' ) - ->with( $this->equalTo( 400 ) ); + ->with( 400 ); $data = array( 'code' => 'wp-api-test-error',