Skip to content

Commit c83b7e5

Browse files
committed
PHPUnit tests: fix deprecation notices on PHPUnit 10
PHPUnit 11 will be stricter about the data passed from data providers to test methods. * The amount of parameters passed has to match the expected number of parameters exactly. * If the data sets use keys, the parameter names have to match the keys as used in each data set (inner array). PHPUnit 10 warns about these changes via deprecation notices. As the success and fail tests use the same input and to avoid duplication, I've added some interim data provider methods to prevent the deprecation notices and allow for update to PHPUnit 11, while still avoiding data duplication.
1 parent 95c8c1d commit c83b7e5

File tree

1 file changed

+54
-6
lines changed

1 file changed

+54
-6
lines changed

tests/unit/PasswordHashEndToEndTest.php

+54-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class PasswordHashEndToEndTest extends TestCase {
1616
* Test using the stronger but system-specific hashes, with a possible fallback to
1717
* the weaker portable hashes.
1818
*
19-
* @dataProvider dataSets
19+
* @dataProvider dataSetsSuccess
2020
*
2121
* @param string $input The text to hash and compare with.
2222
*
@@ -33,7 +33,7 @@ public function testStrongerSystemSpecificHashSuccess($input) {
3333
* Test using the stronger but system-specific hashes, with a possible fallback to
3434
* the weaker portable hashes.
3535
*
36-
* @dataProvider dataSets
36+
* @dataProvider dataSetsFail
3737
*
3838
* @param string $input The text to hash.
3939
* @param string $compare The text to compare the hash with.
@@ -50,7 +50,7 @@ public function testStrongerSystemSpecificHashFail($input, $compare) {
5050
/**
5151
* Test using the weaker portable hashes.
5252
*
53-
* @dataProvider dataSets
53+
* @dataProvider dataSetsSuccess
5454
*
5555
* @param string $input The text to hash and compare with.
5656
*
@@ -67,7 +67,7 @@ public function testWeakerPortableHashSuccess($input) {
6767
/**
6868
* Test using the weaker portable hashes.
6969
*
70-
* @dataProvider dataSets
70+
* @dataProvider dataSetsFail
7171
*
7272
* @param string $input The text to hash.
7373
* @param string $compare The text to compare the hash with.
@@ -87,6 +87,30 @@ public function testWeakerPortableHashFail($input, $compare) {
8787
*
8888
* @return array
8989
*/
90+
public static function dataSetsSuccess() {
91+
$data = self::dataSets();
92+
foreach ($data as $key => $value) {
93+
// The `compare` parameter is only needed for the "fail" tests.
94+
unset($data[$key]['compare']);
95+
}
96+
97+
return $data;
98+
}
99+
100+
/**
101+
* Data provider.
102+
*
103+
* @return array
104+
*/
105+
public static function dataSetsFail() {
106+
return self::dataSets();
107+
}
108+
109+
/**
110+
* Data provider helper.
111+
*
112+
* @return array
113+
*/
90114
public static function dataSets() {
91115
return array(
92116
'initial test case' => array(
@@ -99,7 +123,7 @@ public static function dataSets() {
99123
/**
100124
* Test the generated hash is correctly calculated using the weaker portable hashes.
101125
*
102-
* @dataProvider dataGeneratedHash
126+
* @dataProvider dataGeneratedHashSuccess
103127
*
104128
* @param string $expected_hash The expected password hash output.
105129
* @param string $input The text to hash and compare with.
@@ -112,10 +136,25 @@ public function testGeneratedHashSuccess($expected_hash, $input) {
112136
$this->assertTrue($t_hasher->CheckPassword($input, $expected_hash));
113137
}
114138

139+
/**
140+
* Data provider.
141+
*
142+
* @return array
143+
*/
144+
public static function dataGeneratedHashSuccess() {
145+
$data = self::dataGeneratedHash();
146+
foreach ($data as $key => $value) {
147+
// The `compare` parameter is only needed for the "fail" tests.
148+
unset($data[$key]['compare']);
149+
}
150+
151+
return $data;
152+
}
153+
115154
/**
116155
* Test the generated hash is correctly calculated using the weaker portable hashes.
117156
*
118-
* @dataProvider dataGeneratedHash
157+
* @dataProvider dataGeneratedHashFail
119158
*
120159
* @param string $expected_hash The expected password hash output.
121160
* @param string $input Unused.
@@ -134,6 +173,15 @@ public function testGeneratedHashFail($expected_hash, $input, $compare) {
134173
*
135174
* @return array
136175
*/
176+
public static function dataGeneratedHashFail() {
177+
return self::dataGeneratedHash();
178+
}
179+
180+
/**
181+
* Data provider helper.
182+
*
183+
* @return array
184+
*/
137185
public static function dataGeneratedHash() {
138186
return array(
139187
'initial test case' => array(

0 commit comments

Comments
 (0)