Skip to content

Commit 43f8029

Browse files
committed
Get rid of baseline, add types to tests
1 parent 66c6445 commit 43f8029

File tree

10 files changed

+135
-882
lines changed

10 files changed

+135
-882
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@
5454
},
5555
"scripts": {
5656
"test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit",
57-
"phpstan": "phpstan analyse"
57+
"phpstan": "@php vendor/bin/phpstan analyse"
5858
}
5959
}

phpstan.neon.dist

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
includes:
2-
- tests/baseline.neon
3-
41
parameters:
52
level: 8
63
paths:
74
- src
85
- tests
6+
7+
ignoreErrors:
8+
# Ignore some irrelevant errors in test files
9+
- '~Method Composer\\Semver\\[^:]+::(setUp(BeforeClass)?|tearDown(AfterClass)?|test[^(]+)\(\) has no return type specified.~'
10+
- '~Method Composer\\Semver\\[^:]+::(data\w+|provide\w+|\w+?Provider)\(\) has no return type specified.~'

tests/ComparatorTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function testCompare($version1, $operator, $version2, $expected)
126126
}
127127

128128
/**
129-
* @return array
129+
* @return array<mixed>
130130
*/
131131
public function greaterThanProvider()
132132
{
@@ -141,7 +141,7 @@ public function greaterThanProvider()
141141
}
142142

143143
/**
144-
* @return array
144+
* @return array<mixed>
145145
*/
146146
public function greaterThanOrEqualToProvider()
147147
{
@@ -153,7 +153,7 @@ public function greaterThanOrEqualToProvider()
153153
}
154154

155155
/**
156-
* @return array
156+
* @return array<mixed>
157157
*/
158158
public function lessThanProvider()
159159
{
@@ -169,7 +169,7 @@ public function lessThanProvider()
169169
}
170170

171171
/**
172-
* @return array
172+
* @return array<mixed>
173173
*/
174174
public function lessThanOrEqualToProvider()
175175
{
@@ -181,7 +181,7 @@ public function lessThanOrEqualToProvider()
181181
}
182182

183183
/**
184-
* @return array
184+
* @return array<mixed>
185185
*/
186186
public function equalToProvider()
187187
{
@@ -196,7 +196,7 @@ public function equalToProvider()
196196
}
197197

198198
/**
199-
* @return array
199+
* @return array<mixed>
200200
*/
201201
public function notEqualToProvider()
202202
{
@@ -208,7 +208,7 @@ public function notEqualToProvider()
208208
}
209209

210210
/**
211-
* @return array
211+
* @return array<mixed>
212212
*/
213213
public function compareProvider()
214214
{

tests/Constraint/ConstraintTest.php

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function testGetPrettyString()
5353
$this->assertSame($expectedVersion, $result);
5454
}
5555

56+
/**
57+
* @return array<mixed>
58+
*/
5659
public static function successfulVersionMatches()
5760
{
5861
return array(
@@ -161,6 +164,10 @@ public static function successfulVersionMatches()
161164

162165
/**
163166
* @dataProvider successfulVersionMatches
167+
* @param Constraint::STR_OP_* $requireOperator
168+
* @param string $requireVersion
169+
* @param Constraint::STR_OP_* $provideOperator
170+
* @param string $provideVersion
164171
*/
165172
public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
166173
{
@@ -178,6 +185,9 @@ public function testVersionMatchSucceeds($requireOperator, $requireVersion, $pro
178185
$this->assertTrue(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($versionRequire)));
179186
}
180187

188+
/**
189+
* @return array<mixed>
190+
*/
181191
public static function failingVersionMatches()
182192
{
183193
return array(
@@ -331,6 +341,10 @@ public static function failingVersionMatches()
331341

332342
/**
333343
* @dataProvider failingVersionMatches
344+
* @param Constraint::STR_OP_* $requireOperator
345+
* @param string $requireVersion
346+
* @param Constraint::STR_OP_* $provideOperator
347+
* @param string $provideVersion
334348
*/
335349
public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
336350
{
@@ -411,19 +425,18 @@ public function testComparableBranches()
411425
* @dataProvider invalidOperators
412426
*
413427
* @param string $version
414-
* @param string $operator
415-
* @param string $expected
428+
* @param Constraint::STR_OP_* $operator
429+
* @param class-string $expected
416430
*/
417431
public function testInvalidOperators($version, $operator, $expected)
418432
{
419433
$this->doExpectException($expected);
420434

421-
/** @phpstan-ignore-next-line */
422435
new Constraint($operator, $version);
423436
}
424437

425438
/**
426-
* @return array
439+
* @return array<mixed>
427440
*/
428441
public function invalidOperators()
429442
{
@@ -437,12 +450,10 @@ public function invalidOperators()
437450
/**
438451
* @dataProvider bounds
439452
*
440-
* @param string $operator
453+
* @param Constraint::STR_OP_* $operator
441454
* @param string $normalizedVersion
442455
* @param Bound $expectedLower
443456
* @param Bound $expectedUpper
444-
*
445-
* @phpstan-param Constraint::STR_OP_* $operator
446457
*/
447458
public function testBounds($operator, $normalizedVersion, Bound $expectedLower, Bound $expectedUpper)
448459
{
@@ -453,7 +464,7 @@ public function testBounds($operator, $normalizedVersion, Bound $expectedLower,
453464
}
454465

455466
/**
456-
* @return array
467+
* @return array<mixed>
457468
*/
458469
public function bounds()
459470
{
@@ -496,6 +507,10 @@ public function bounds()
496507

497508
/**
498509
* @dataProvider matrix
510+
* @param Constraint::STR_OP_* $requireOperator
511+
* @param string $requireVersion
512+
* @param Constraint::STR_OP_* $provideOperator
513+
* @param string $provideVersion
499514
*/
500515
public function testCompile($requireOperator, $requireVersion, $provideOperator, $provideVersion)
501516
{
@@ -517,6 +532,9 @@ public function testCompile($requireOperator, $requireVersion, $provideOperator,
517532
$this->assertSame($m, Intervals::haveIntersections($require, $provide));
518533
}
519534

535+
/**
536+
* @return array<mixed>
537+
*/
520538
public function matrix()
521539
{
522540
$versions = array('1.0', '2.0', 'dev-master', 'dev-foo', '3.0-b2', '3.0-beta2');
@@ -536,6 +554,11 @@ public function matrix()
536554
return $matrix;
537555
}
538556

557+
/**
558+
* @param Constraint::STR_OP_* $operator
559+
* @param string $version
560+
* @return bool
561+
*/
539562
private function matchCompiled(ConstraintInterface $constraint, $operator, $version)
540563
{
541564
$map = array(
@@ -556,6 +579,10 @@ private function matchCompiled(ConstraintInterface $constraint, $operator, $vers
556579
return eval("return $code;");
557580
}
558581

582+
/**
583+
* @param class-string $class
584+
* @return void
585+
*/
559586
private function doExpectException($class)
560587
{
561588
if (method_exists($this, 'expectException')) {

tests/Constraint/MultiConstraintTest.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testMultiVersionMatchSucceeds()
5454

5555
$this->assertTrue($multiRequire->matches($versionProvide));
5656
$this->assertTrue($versionProvide->matches($multiRequire));
57-
$this->assertTrue($this->matchCompiled($multiRequire, '==', 1.1));
57+
$this->assertTrue($this->matchCompiled($multiRequire, '==', '1.1'));
5858
$this->assertTrue(Intervals::haveIntersections($multiRequire, $versionProvide));
5959
$this->assertTrue(Intervals::compactConstraint($multiRequire)->matches(Intervals::compactConstraint($versionProvide)));
6060
$this->assertTrue(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($multiRequire)));
@@ -113,7 +113,7 @@ public function testMultiVersionMatchFails()
113113

114114
$this->assertFalse($multiRequire->matches($versionProvide));
115115
$this->assertFalse($versionProvide->matches($multiRequire));
116-
$this->assertFalse($this->matchCompiled($multiRequire, '==', 1.2));
116+
$this->assertFalse($this->matchCompiled($multiRequire, '==', '1.2'));
117117
$this->assertFalse(Intervals::haveIntersections($multiRequire, $versionProvide));
118118
$this->assertFalse(Intervals::compactConstraint($multiRequire)->matches(Intervals::compactConstraint($versionProvide)));
119119
$this->assertFalse(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($multiRequire)));
@@ -138,7 +138,7 @@ public function testGetPrettyString()
138138
/**
139139
* @dataProvider bounds
140140
*
141-
* @param array $constraints
141+
* @param array<ConstraintInterface> $constraints
142142
* @param bool $conjunctive
143143
* @param Bound $expectedLower
144144
* @param Bound $expectedUpper
@@ -152,7 +152,7 @@ public function testBounds(array $constraints, $conjunctive, Bound $expectedLowe
152152
}
153153

154154
/**
155-
* @return array
155+
* @return array<mixed>
156156
*/
157157
public function bounds()
158158
{
@@ -224,7 +224,7 @@ public function testBoundsIntegrationWithVersionParser($constraints, Bound $expe
224224
}
225225

226226
/**
227-
* @return array
227+
* @return array<mixed>
228228
*/
229229
public function boundsIntegration()
230230
{
@@ -304,6 +304,9 @@ public function testMultiConstraintOptimizations($constraints, ConstraintInterfa
304304
$this->assertSame((string) $expectedConstraint, (string) $parser->parseConstraints($constraints));
305305
}
306306

307+
/**
308+
* @return array<mixed>
309+
*/
307310
public function multiConstraintOptimizations()
308311
{
309312
return array(
@@ -516,7 +519,7 @@ public function testMultiConstraintNotconjunctiveFillWithFalse()
516519

517520
$this->assertFalse($multiRequire->matches($versionProvide));
518521
$this->assertFalse($versionProvide->matches($multiRequire));
519-
$this->assertFalse($this->matchCompiled($multiRequire, '==', 1.1));
522+
$this->assertFalse($this->matchCompiled($multiRequire, '==', '1.1'));
520523
$this->assertFalse(Intervals::haveIntersections($multiRequire, $versionProvide));
521524
}
522525

@@ -530,10 +533,15 @@ public function testMultiConstraintConjunctiveFillWithTrue()
530533

531534
$this->assertTrue($multiRequire->matches($versionProvide));
532535
$this->assertTrue($versionProvide->matches($multiRequire));
533-
$this->assertTrue($this->matchCompiled($multiRequire, '!=', 1.1));
536+
$this->assertTrue($this->matchCompiled($multiRequire, '!=', '1.1'));
534537
$this->assertTrue(Intervals::haveIntersections($multiRequire, $versionProvide));
535538
}
536539

540+
/**
541+
* @param Constraint::STR_OP_* $operator
542+
* @param string $version
543+
* @return bool
544+
*/
537545
private function matchCompiled(ConstraintInterface $constraint, $operator, $version)
538546
{
539547
$map = array(

tests/IntervalsTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ class IntervalsTest extends TestCase
2828

2929
/**
3030
* @dataProvider compactProvider
31+
* @param string $expected
32+
* @param array<string> $toCompact
33+
* @param bool $conjunctive
3134
*/
3235
public function testCompactConstraint($expected, $toCompact, $conjunctive)
3336
{
@@ -191,6 +194,8 @@ public function compactProvider()
191194

192195
/**
193196
* @dataProvider intervalsProvider
197+
* @param array<mixed>|self::INTERVAL_* $expected
198+
* @param string $constraint
194199
*/
195200
public function testGetIntervals($expected, $constraint)
196201
{

tests/SemverTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function testSatisfies($expected, $version, $constraint)
3636
* @dataProvider satisfiedByProvider
3737
*
3838
* @param string $constraint
39-
* @param array $versions
40-
* @param array $expected
39+
* @param array<string> $versions
40+
* @param array<string> $expected
4141
*/
4242
public function testSatisfiedBy($constraint, $versions, $expected)
4343
{
@@ -50,9 +50,9 @@ public function testSatisfiedBy($constraint, $versions, $expected)
5050
* @covers ::usort
5151
* @dataProvider sortProvider
5252
*
53-
* @param array $versions
54-
* @param array $sorted
55-
* @param array $rsorted
53+
* @param array<string> $versions
54+
* @param array<string> $sorted
55+
* @param array<string> $rsorted
5656
*/
5757
public function testSort(array $versions, array $sorted, array $rsorted)
5858
{
@@ -77,7 +77,7 @@ public function testUsortShouldInitialVersionParserClass()
7777
}
7878

7979
/**
80-
* @return array
80+
* @return array<mixed>
8181
*/
8282
public function sortProvider()
8383
{
@@ -96,7 +96,7 @@ public function sortProvider()
9696
}
9797

9898
/**
99-
* @return array
99+
* @return array<mixed>
100100
*/
101101
public function satisfiesProvider()
102102
{
@@ -116,7 +116,7 @@ public function satisfiesProvider()
116116
}
117117

118118
/**
119-
* @return array
119+
* @return array<mixed>
120120
*/
121121
public function satisfiesProviderPositive()
122122
{
@@ -198,7 +198,7 @@ public function satisfiesProviderPositive()
198198
}
199199

200200
/**
201-
* @return array
201+
* @return array<mixed>
202202
*/
203203
public function satisfiesProviderNegative()
204204
{
@@ -252,7 +252,7 @@ public function satisfiesProviderNegative()
252252
}
253253

254254
/**
255-
* @return array
255+
* @return array<mixed>
256256
*/
257257
public function satisfiedByProvider()
258258
{

0 commit comments

Comments
 (0)