Skip to content

Commit dffbaf4

Browse files
alexandre-dauboisnicolas-grekas
authored andcommitted
[Tests] Migrate tests to static data providers
1 parent c103bb2 commit dffbaf4

8 files changed

+98
-77
lines changed

Tests/Constraints/CountValidatorArrayTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
class CountValidatorArrayTest extends CountValidatorTestCase
1818
{
19-
protected function createCollection(array $content)
19+
protected static function createCollection(array $content)
2020
{
2121
return $content;
2222
}

Tests/Constraints/CountValidatorCountableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class CountValidatorCountableTest extends CountValidatorTestCase
2020
{
21-
protected function createCollection(array $content)
21+
protected static function createCollection(array $content)
2222
{
2323
return new Countable($content);
2424
}

Tests/Constraints/CountValidatorTestCase.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ protected function createValidator()
2727
return new CountValidator();
2828
}
2929

30-
abstract protected function createCollection(array $content);
30+
abstract protected static function createCollection(array $content);
3131

3232
public function testNullIsValid()
3333
{
@@ -42,30 +42,30 @@ public function testExpectsCountableType()
4242
$this->validator->validate(new \stdClass(), new Count(5));
4343
}
4444

45-
public function getThreeOrLessElements()
45+
public static function getThreeOrLessElements()
4646
{
4747
return [
48-
[$this->createCollection([1])],
49-
[$this->createCollection([1, 2])],
50-
[$this->createCollection([1, 2, 3])],
51-
[$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3])],
48+
[static::createCollection([1])],
49+
[static::createCollection([1, 2])],
50+
[static::createCollection([1, 2, 3])],
51+
[static::createCollection(['a' => 1, 'b' => 2, 'c' => 3])],
5252
];
5353
}
5454

55-
public function getFourElements()
55+
public static function getFourElements()
5656
{
5757
return [
58-
[$this->createCollection([1, 2, 3, 4])],
59-
[$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4])],
58+
[static::createCollection([1, 2, 3, 4])],
59+
[static::createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4])],
6060
];
6161
}
6262

63-
public function getFiveOrMoreElements()
63+
public static function getFiveOrMoreElements()
6464
{
6565
return [
66-
[$this->createCollection([1, 2, 3, 4, 5])],
67-
[$this->createCollection([1, 2, 3, 4, 5, 6])],
68-
[$this->createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])],
66+
[static::createCollection([1, 2, 3, 4, 5])],
67+
[static::createCollection([1, 2, 3, 4, 5, 6])],
68+
[static::createCollection(['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5])],
6969
];
7070
}
7171

@@ -82,6 +82,7 @@ public function testValidValuesMax($value)
8282

8383
/**
8484
* @requires PHP 8
85+
*
8586
* @dataProvider getThreeOrLessElements
8687
*/
8788
public function testValidValuesMaxNamed($value)
@@ -105,6 +106,7 @@ public function testValidValuesMin($value)
105106

106107
/**
107108
* @requires PHP 8
109+
*
108110
* @dataProvider getFiveOrMoreElements
109111
*/
110112
public function testValidValuesMinNamed($value)
@@ -128,6 +130,7 @@ public function testValidValuesExact($value)
128130

129131
/**
130132
* @requires PHP 8
133+
*
131134
* @dataProvider getFourElements
132135
*/
133136
public function testValidValuesExactNamed($value)
@@ -161,6 +164,7 @@ public function testTooManyValues($value)
161164

162165
/**
163166
* @requires PHP 8
167+
*
164168
* @dataProvider getFiveOrMoreElements
165169
*/
166170
public function testTooManyValuesNamed($value)
@@ -201,6 +205,7 @@ public function testTooFewValues($value)
201205

202206
/**
203207
* @requires PHP 8
208+
*
204209
* @dataProvider getThreeOrLessElements
205210
*/
206211
public function testTooFewValuesNamed($value)
@@ -242,6 +247,7 @@ public function testTooManyValuesExact($value)
242247

243248
/**
244249
* @requires PHP 8
250+
*
245251
* @dataProvider getFiveOrMoreElements
246252
*/
247253
public function testTooManyValuesExactNamed($value)

Tests/Constraints/IpValidatorTest.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testValidIpsV4($ip)
6464
$this->assertNoViolation();
6565
}
6666

67-
public function getValidIpsV4()
67+
public static function getValidIpsV4()
6868
{
6969
return [
7070
['0.0.0.0'],
@@ -104,7 +104,7 @@ public function testValidIpV6WithWhitespacesNamed()
104104
$this->assertNoViolation();
105105
}
106106

107-
public function getValidIpsV4WithWhitespaces()
107+
public static function getValidIpsV4WithWhitespaces()
108108
{
109109
return [
110110
["\x200.0.0.0"],
@@ -128,7 +128,7 @@ public function testValidIpsV6($ip)
128128
$this->assertNoViolation();
129129
}
130130

131-
public function getValidIpsV6()
131+
public static function getValidIpsV6()
132132
{
133133
return [
134134
['2001:0db8:85a3:0000:0000:8a2e:0370:7334'],
@@ -165,9 +165,9 @@ public function testValidIpsAll($ip)
165165
$this->assertNoViolation();
166166
}
167167

168-
public function getValidIpsAll()
168+
public static function getValidIpsAll()
169169
{
170-
return array_merge($this->getValidIpsV4(), $this->getValidIpsV6());
170+
return array_merge(self::getValidIpsV4(), self::getValidIpsV6());
171171
}
172172

173173
/**
@@ -188,7 +188,7 @@ public function testInvalidIpsV4($ip)
188188
->assertRaised();
189189
}
190190

191-
public function getInvalidIpsV4()
191+
public static function getInvalidIpsV4()
192192
{
193193
return [
194194
['0'],
@@ -221,7 +221,7 @@ public function testInvalidPrivateIpsV4($ip)
221221
->assertRaised();
222222
}
223223

224-
public function getInvalidPrivateIpsV4()
224+
public static function getInvalidPrivateIpsV4()
225225
{
226226
return [
227227
['10.0.0.0'],
@@ -248,7 +248,7 @@ public function testInvalidReservedIpsV4($ip)
248248
->assertRaised();
249249
}
250250

251-
public function getInvalidReservedIpsV4()
251+
public static function getInvalidReservedIpsV4()
252252
{
253253
return [
254254
['0.0.0.0'],
@@ -275,9 +275,9 @@ public function testInvalidPublicIpsV4($ip)
275275
->assertRaised();
276276
}
277277

278-
public function getInvalidPublicIpsV4()
278+
public static function getInvalidPublicIpsV4()
279279
{
280-
return array_merge($this->getInvalidPrivateIpsV4(), $this->getInvalidReservedIpsV4());
280+
return array_merge(self::getInvalidPrivateIpsV4(), self::getInvalidReservedIpsV4());
281281
}
282282

283283
/**
@@ -298,7 +298,7 @@ public function testInvalidIpsV6($ip)
298298
->assertRaised();
299299
}
300300

301-
public function getInvalidIpsV6()
301+
public static function getInvalidIpsV6()
302302
{
303303
return [
304304
['z001:0db8:85a3:0000:0000:8a2e:0370:7334'],
@@ -335,7 +335,7 @@ public function testInvalidPrivateIpsV6($ip)
335335
->assertRaised();
336336
}
337337

338-
public function getInvalidPrivateIpsV6()
338+
public static function getInvalidPrivateIpsV6()
339339
{
340340
return [
341341
['fdfe:dcba:9876:ffff:fdc6:c46b:bb8f:7d4c'],
@@ -362,12 +362,12 @@ public function testInvalidReservedIpsV6($ip)
362362
->assertRaised();
363363
}
364364

365-
public function getInvalidReservedIpsV6()
365+
public static function getInvalidReservedIpsV6()
366366
{
367367
// Quoting after official filter documentation:
368368
// "FILTER_FLAG_NO_RES_RANGE = This flag does not apply to IPv6 addresses."
369369
// Full description: https://php.net/filter.filters.flags
370-
return $this->getInvalidIpsV6();
370+
return self::getInvalidIpsV6();
371371
}
372372

373373
/**
@@ -388,9 +388,9 @@ public function testInvalidPublicIpsV6($ip)
388388
->assertRaised();
389389
}
390390

391-
public function getInvalidPublicIpsV6()
391+
public static function getInvalidPublicIpsV6()
392392
{
393-
return array_merge($this->getInvalidPrivateIpsV6(), $this->getInvalidReservedIpsV6());
393+
return array_merge(self::getInvalidPrivateIpsV6(), self::getInvalidReservedIpsV6());
394394
}
395395

396396
/**
@@ -411,9 +411,9 @@ public function testInvalidIpsAll($ip)
411411
->assertRaised();
412412
}
413413

414-
public function getInvalidIpsAll()
414+
public static function getInvalidIpsAll()
415415
{
416-
return array_merge($this->getInvalidIpsV4(), $this->getInvalidIpsV6());
416+
return array_merge(self::getInvalidIpsV4(), self::getInvalidIpsV6());
417417
}
418418

419419
/**
@@ -434,9 +434,9 @@ public function testInvalidPrivateIpsAll($ip)
434434
->assertRaised();
435435
}
436436

437-
public function getInvalidPrivateIpsAll()
437+
public static function getInvalidPrivateIpsAll()
438438
{
439-
return array_merge($this->getInvalidPrivateIpsV4(), $this->getInvalidPrivateIpsV6());
439+
return array_merge(self::getInvalidPrivateIpsV4(), self::getInvalidPrivateIpsV6());
440440
}
441441

442442
/**
@@ -457,9 +457,9 @@ public function testInvalidReservedIpsAll($ip)
457457
->assertRaised();
458458
}
459459

460-
public function getInvalidReservedIpsAll()
460+
public static function getInvalidReservedIpsAll()
461461
{
462-
return array_merge($this->getInvalidReservedIpsV4(), $this->getInvalidReservedIpsV6());
462+
return array_merge(self::getInvalidReservedIpsV4(), self::getInvalidReservedIpsV6());
463463
}
464464

465465
/**
@@ -480,8 +480,8 @@ public function testInvalidPublicIpsAll($ip)
480480
->assertRaised();
481481
}
482482

483-
public function getInvalidPublicIpsAll()
483+
public static function getInvalidPublicIpsAll()
484484
{
485-
return array_merge($this->getInvalidPublicIpsV4(), $this->getInvalidPublicIpsV6());
485+
return array_merge(self::getInvalidPublicIpsV4(), self::getInvalidPublicIpsV6());
486486
}
487487
}

Tests/Constraints/IsbnValidatorTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function createValidator()
2626
return new IsbnValidator();
2727
}
2828

29-
public function getValidIsbn10()
29+
public static function getValidIsbn10()
3030
{
3131
return [
3232
['2723442284'],
@@ -45,7 +45,7 @@ public function getValidIsbn10()
4545
];
4646
}
4747

48-
public function getInvalidIsbn10()
48+
public static function getInvalidIsbn10()
4949
{
5050
return [
5151
['27234422841', Isbn::TOO_LONG_ERROR],
@@ -65,7 +65,7 @@ public function getInvalidIsbn10()
6565
];
6666
}
6767

68-
public function getValidIsbn13()
68+
public static function getValidIsbn13()
6969
{
7070
return [
7171
['978-2723442282'],
@@ -83,7 +83,7 @@ public function getValidIsbn13()
8383
];
8484
}
8585

86-
public function getInvalidIsbn13()
86+
public static function getInvalidIsbn13()
8787
{
8888
return [
8989
['978-27234422821', Isbn::TOO_LONG_ERROR],
@@ -103,19 +103,19 @@ public function getInvalidIsbn13()
103103
];
104104
}
105105

106-
public function getValidIsbn()
106+
public static function getValidIsbn()
107107
{
108108
return array_merge(
109-
$this->getValidIsbn10(),
110-
$this->getValidIsbn13()
109+
self::getValidIsbn10(),
110+
self::getValidIsbn13()
111111
);
112112
}
113113

114-
public function getInvalidIsbn()
114+
public static function getInvalidIsbn()
115115
{
116116
return array_merge(
117-
$this->getInvalidIsbn10(),
118-
$this->getInvalidIsbn13()
117+
self::getInvalidIsbn10(),
118+
self::getInvalidIsbn13()
119119
);
120120
}
121121

Tests/Constraints/IssnValidatorTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function createValidator()
2626
return new IssnValidator();
2727
}
2828

29-
public function getValidLowerCasedIssn()
29+
public static function getValidLowerCasedIssn()
3030
{
3131
return [
3232
['2162-321x'],
@@ -39,7 +39,7 @@ public function getValidLowerCasedIssn()
3939
];
4040
}
4141

42-
public function getValidNonHyphenatedIssn()
42+
public static function getValidNonHyphenatedIssn()
4343
{
4444
return [
4545
['2162321X'],
@@ -52,7 +52,7 @@ public function getValidNonHyphenatedIssn()
5252
];
5353
}
5454

55-
public function getFullValidIssn()
55+
public static function getFullValidIssn()
5656
{
5757
return [
5858
['1550-7416'],
@@ -66,16 +66,16 @@ public function getFullValidIssn()
6666
];
6767
}
6868

69-
public function getValidIssn()
69+
public static function getValidIssn()
7070
{
7171
return array_merge(
72-
$this->getValidLowerCasedIssn(),
73-
$this->getValidNonHyphenatedIssn(),
74-
$this->getFullValidIssn()
72+
self::getValidLowerCasedIssn(),
73+
self::getValidNonHyphenatedIssn(),
74+
self::getFullValidIssn()
7575
);
7676
}
7777

78-
public function getInvalidIssn()
78+
public static function getInvalidIssn()
7979
{
8080
return [
8181
[0, Issn::TOO_SHORT_ERROR],

0 commit comments

Comments
 (0)