Skip to content

Commit 8cd8594

Browse files
Tests: Simplify the tests for force_ssl_admin().
Includes: * The `$forced` static variable is reset to `false` before each test, and the function always returns the previous value on the first call, so there is no need to pass the same value from the data provider. * Clarifying data provider keys by removing the “first call” references to avoid confusion, as the test method always calls the function twice for each input value. * Replacing unnecessarily redundant test method name for consistency with other tests. * Moving the data provider after the test method for consistency with other tests. * Adjusting DocBlock formatting as per the documentation standards. Follow-up to [59830]. See #63167. git-svn-id: https://develop.svn.wordpress.org/trunk@60137 602fd350-edb4-49c9-b593-d223f7449a82
1 parent e25505b commit 8cd8594

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

tests/phpunit/tests/functions/forceSslAdmin.php

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
/**
33
* Test cases for the `force_ssl_admin()` function.
44
*
5-
* @package WordPress\UnitTests
6-
*
75
* @since 6.8.0
86
*
97
* @group functions
@@ -12,44 +10,42 @@
1210
*/
1311
class Tests_Functions_ForceSslAdmin extends WP_UnitTestCase {
1412

15-
public function set_up(): void {
13+
public function set_up() {
1614
parent::set_up();
17-
// Reset the static variable before each test
15+
// Reset the `$forced` static variable before each test.
1816
force_ssl_admin( false );
1917
}
2018

2119
/**
22-
* Data provider for testing force_ssl_admin.
20+
* Tests that force_ssl_admin() returns expected values based on various inputs.
2321
*
24-
* Provides various inputs and expected outcomes for the function.
22+
* @dataProvider data_force_ssl_admin
2523
*
26-
* @return array[]
24+
* @param mixed $input The input value to test.
25+
* @param bool $expected The expected result for subsequent calls.
2726
*/
28-
public function data_should_return_expected_value_when_various_inputs_are_passed() {
29-
return array(
30-
'default' => array( null, false, false ),
31-
'first_call_true' => array( true, false, true ),
32-
'first_call_false' => array( false, false, false ),
33-
'first_call_non_empty_string' => array( 'some string', false, true ),
34-
'empty_string' => array( '', false, false ),
35-
'first_call_integer_1' => array( 1, false, true ),
36-
'integer_0' => array( 0, false, false ),
37-
);
27+
public function test_force_ssl_admin( $input, $expected ) {
28+
// The first call always returns the previous value.
29+
$this->assertFalse( force_ssl_admin( $input ), 'First call did not return the expected value' );
30+
31+
// Call again to check subsequent behavior.
32+
$this->assertSame( $expected, force_ssl_admin( $input ), 'Subsequent call did not return the expected value' );
3833
}
3934

4035
/**
41-
* Tests that force_ssl_admin returns expected values based on various inputs.
36+
* Data provider for testing force_ssl_admin().
4237
*
43-
* @dataProvider data_should_return_expected_value_when_various_inputs_are_passed
44-
*
45-
* @param mixed $input The input value to test.
46-
* @param bool $expected_first_call The expected result for the first call.
47-
* @param bool $expected_subsequent_call The expected result for subsequent calls.
38+
* @return array[]
4839
*/
49-
public function test_should_return_expected_value_when_various_inputs_are_passed( $input, $expected_first_call, $expected_subsequent_call ) {
50-
$this->assertSame( $expected_first_call, force_ssl_admin( $input ), 'First call did not return expected value' );
51-
52-
// Call again to check subsequent behavior
53-
$this->assertSame( $expected_subsequent_call, force_ssl_admin( $input ), 'Subsequent call did not return expected value' );
40+
public function data_force_ssl_admin() {
41+
return array(
42+
'default' => array( null, false ),
43+
'true' => array( true, true ),
44+
'false' => array( false, false ),
45+
'non-empty string' => array( 'some string', true ),
46+
'empty string' => array( '', false ),
47+
'integer 1' => array( 1, true ),
48+
'integer 0' => array( 0, false ),
49+
);
5450
}
5551
}

0 commit comments

Comments
 (0)