Skip to content

Commit 560d18d

Browse files
Tests: Use assertSame() in absint() tests.
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Includes correcting a few erroneously duplicated test cases to match their intended purpose. Follow-up to [57724]. See #60706. git-svn-id: https://develop.svn.wordpress.org/trunk@58150 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 6f7cd05 commit 560d18d

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

tests/phpunit/tests/functions/absint.php

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,79 @@
11
<?php
22

33
/**
4-
* Tests for the absint function.
4+
* Tests for the absint() function.
55
*
66
* @group functions
77
*
88
* @covers ::absint
99
*/
10-
class Tests_Functions_absint extends WP_UnitTestCase {
10+
class Tests_Functions_Absint extends WP_UnitTestCase {
1111

1212
/**
1313
* @ticket 60101
1414
*
1515
* @dataProvider data_absint
1616
*/
17-
public function test_absint( $maybe_int, $expected_value ) {
18-
19-
$this->assertEquals( $expected_value, absint( $maybe_int ) );
17+
public function test_absint( $test_value, $expected_value ) {
18+
$this->assertSame( $expected_value, absint( $test_value ) );
2019
}
2120

2221
/**
23-
* @ticket 60101
24-
*
25-
* Returns an array of test data for the `data_absint` method.
22+
* Data provider.
2623
*
27-
* @return array[] An array of test data.
24+
* @return array[] Test parameters {
25+
* @type string $test_value Test value.
26+
* @type string $expected Expected return value.
27+
* }
2828
*/
2929
public function data_absint() {
3030
return array(
31-
'1_int' => array(
32-
'maybe_int' => 1,
31+
'1 int' => array(
32+
'test_value' => 1,
3333
'expected_value' => 1,
3434
),
35-
'9.1_int' => array(
36-
'maybe_int' => 9.1,
37-
'expected_value' => 9,
38-
),
39-
'9.9_int' => array(
40-
'maybe_int' => 9.9,
41-
'expected_value' => 9,
42-
),
43-
'1_string' => array(
44-
'maybe_int' => 1,
45-
'expected_value' => '1',
35+
'1 string' => array(
36+
'test_value' => '1',
37+
'expected_value' => 1,
4638
),
47-
'-1_int' => array(
48-
'maybe_int' => 1,
39+
'-1 int' => array(
40+
'test_value' => -1,
4941
'expected_value' => 1,
5042
),
51-
'-1_string' => array(
52-
'maybe_int' => 1,
43+
'-1 string' => array(
44+
'test_value' => '-1',
5345
'expected_value' => 1,
5446
),
47+
'9.1 float' => array(
48+
'test_value' => 9.1,
49+
'expected_value' => 9,
50+
),
51+
'9.9 float' => array(
52+
'test_value' => 9.9,
53+
'expected_value' => 9,
54+
),
5555
'string' => array(
56-
'maybe_int' => 'string',
56+
'test_value' => 'string',
5757
'expected_value' => 0,
5858
),
59-
'999_string' => array(
60-
'maybe_int' => '999_string',
61-
'expected_value' => 999,
62-
),
6359
'string_1' => array(
64-
'maybe_int' => 'string_1',
60+
'test_value' => 'string_1',
6561
'expected_value' => 0,
6662
),
63+
'999_string' => array(
64+
'test_value' => '999_string',
65+
'expected_value' => 999,
66+
),
6767
'99 string with spaces' => array(
68-
'maybe_int' => '99 string with spaces',
68+
'test_value' => '99 string with spaces',
6969
'expected_value' => 99,
7070
),
71-
'array(99)' => array(
72-
'maybe_int' => array( 99 ),
71+
'99 array' => array(
72+
'test_value' => array( 99 ),
7373
'expected_value' => 1,
7474
),
75-
'array("99")' => array(
76-
'maybe_int' => array( '99' ),
75+
'99 string array' => array(
76+
'test_value' => array( '99' ),
7777
'expected_value' => 1,
7878
),
7979
);

0 commit comments

Comments
 (0)