Skip to content

Commit

Permalink
Get rid of baseline, add types to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Feb 3, 2022
1 parent 66c6445 commit 43f8029
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 882 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
},
"scripts": {
"test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit",
"phpstan": "phpstan analyse"
"phpstan": "@php vendor/bin/phpstan analyse"
}
}
8 changes: 5 additions & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
includes:
- tests/baseline.neon

parameters:
level: 8
paths:
- src
- tests

ignoreErrors:
# Ignore some irrelevant errors in test files
- '~Method Composer\\Semver\\[^:]+::(setUp(BeforeClass)?|tearDown(AfterClass)?|test[^(]+)\(\) has no return type specified.~'
- '~Method Composer\\Semver\\[^:]+::(data\w+|provide\w+|\w+?Provider)\(\) has no return type specified.~'
14 changes: 7 additions & 7 deletions tests/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function testCompare($version1, $operator, $version2, $expected)
}

/**
* @return array
* @return array<mixed>
*/
public function greaterThanProvider()
{
Expand All @@ -141,7 +141,7 @@ public function greaterThanProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function greaterThanOrEqualToProvider()
{
Expand All @@ -153,7 +153,7 @@ public function greaterThanOrEqualToProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function lessThanProvider()
{
Expand All @@ -169,7 +169,7 @@ public function lessThanProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function lessThanOrEqualToProvider()
{
Expand All @@ -181,7 +181,7 @@ public function lessThanOrEqualToProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function equalToProvider()
{
Expand All @@ -196,7 +196,7 @@ public function equalToProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function notEqualToProvider()
{
Expand All @@ -208,7 +208,7 @@ public function notEqualToProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function compareProvider()
{
Expand Down
43 changes: 35 additions & 8 deletions tests/Constraint/ConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public function testGetPrettyString()
$this->assertSame($expectedVersion, $result);
}

/**
* @return array<mixed>
*/
public static function successfulVersionMatches()
{
return array(
Expand Down Expand Up @@ -161,6 +164,10 @@ public static function successfulVersionMatches()

/**
* @dataProvider successfulVersionMatches
* @param Constraint::STR_OP_* $requireOperator
* @param string $requireVersion
* @param Constraint::STR_OP_* $provideOperator
* @param string $provideVersion
*/
public function testVersionMatchSucceeds($requireOperator, $requireVersion, $provideOperator, $provideVersion)
{
Expand All @@ -178,6 +185,9 @@ public function testVersionMatchSucceeds($requireOperator, $requireVersion, $pro
$this->assertTrue(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($versionRequire)));
}

/**
* @return array<mixed>
*/
public static function failingVersionMatches()
{
return array(
Expand Down Expand Up @@ -331,6 +341,10 @@ public static function failingVersionMatches()

/**
* @dataProvider failingVersionMatches
* @param Constraint::STR_OP_* $requireOperator
* @param string $requireVersion
* @param Constraint::STR_OP_* $provideOperator
* @param string $provideVersion
*/
public function testVersionMatchFails($requireOperator, $requireVersion, $provideOperator, $provideVersion)
{
Expand Down Expand Up @@ -411,19 +425,18 @@ public function testComparableBranches()
* @dataProvider invalidOperators
*
* @param string $version
* @param string $operator
* @param string $expected
* @param Constraint::STR_OP_* $operator
* @param class-string $expected
*/
public function testInvalidOperators($version, $operator, $expected)
{
$this->doExpectException($expected);

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

/**
* @return array
* @return array<mixed>
*/
public function invalidOperators()
{
Expand All @@ -437,12 +450,10 @@ public function invalidOperators()
/**
* @dataProvider bounds
*
* @param string $operator
* @param Constraint::STR_OP_* $operator
* @param string $normalizedVersion
* @param Bound $expectedLower
* @param Bound $expectedUpper
*
* @phpstan-param Constraint::STR_OP_* $operator
*/
public function testBounds($operator, $normalizedVersion, Bound $expectedLower, Bound $expectedUpper)
{
Expand All @@ -453,7 +464,7 @@ public function testBounds($operator, $normalizedVersion, Bound $expectedLower,
}

/**
* @return array
* @return array<mixed>
*/
public function bounds()
{
Expand Down Expand Up @@ -496,6 +507,10 @@ public function bounds()

/**
* @dataProvider matrix
* @param Constraint::STR_OP_* $requireOperator
* @param string $requireVersion
* @param Constraint::STR_OP_* $provideOperator
* @param string $provideVersion
*/
public function testCompile($requireOperator, $requireVersion, $provideOperator, $provideVersion)
{
Expand All @@ -517,6 +532,9 @@ public function testCompile($requireOperator, $requireVersion, $provideOperator,
$this->assertSame($m, Intervals::haveIntersections($require, $provide));
}

/**
* @return array<mixed>
*/
public function matrix()
{
$versions = array('1.0', '2.0', 'dev-master', 'dev-foo', '3.0-b2', '3.0-beta2');
Expand All @@ -536,6 +554,11 @@ public function matrix()
return $matrix;
}

/**
* @param Constraint::STR_OP_* $operator
* @param string $version
* @return bool
*/
private function matchCompiled(ConstraintInterface $constraint, $operator, $version)
{
$map = array(
Expand All @@ -556,6 +579,10 @@ private function matchCompiled(ConstraintInterface $constraint, $operator, $vers
return eval("return $code;");
}

/**
* @param class-string $class
* @return void
*/
private function doExpectException($class)
{
if (method_exists($this, 'expectException')) {
Expand Down
22 changes: 15 additions & 7 deletions tests/Constraint/MultiConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testMultiVersionMatchSucceeds()

$this->assertTrue($multiRequire->matches($versionProvide));
$this->assertTrue($versionProvide->matches($multiRequire));
$this->assertTrue($this->matchCompiled($multiRequire, '==', 1.1));
$this->assertTrue($this->matchCompiled($multiRequire, '==', '1.1'));
$this->assertTrue(Intervals::haveIntersections($multiRequire, $versionProvide));
$this->assertTrue(Intervals::compactConstraint($multiRequire)->matches(Intervals::compactConstraint($versionProvide)));
$this->assertTrue(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($multiRequire)));
Expand Down Expand Up @@ -113,7 +113,7 @@ public function testMultiVersionMatchFails()

$this->assertFalse($multiRequire->matches($versionProvide));
$this->assertFalse($versionProvide->matches($multiRequire));
$this->assertFalse($this->matchCompiled($multiRequire, '==', 1.2));
$this->assertFalse($this->matchCompiled($multiRequire, '==', '1.2'));
$this->assertFalse(Intervals::haveIntersections($multiRequire, $versionProvide));
$this->assertFalse(Intervals::compactConstraint($multiRequire)->matches(Intervals::compactConstraint($versionProvide)));
$this->assertFalse(Intervals::compactConstraint($versionProvide)->matches(Intervals::compactConstraint($multiRequire)));
Expand All @@ -138,7 +138,7 @@ public function testGetPrettyString()
/**
* @dataProvider bounds
*
* @param array $constraints
* @param array<ConstraintInterface> $constraints
* @param bool $conjunctive
* @param Bound $expectedLower
* @param Bound $expectedUpper
Expand All @@ -152,7 +152,7 @@ public function testBounds(array $constraints, $conjunctive, Bound $expectedLowe
}

/**
* @return array
* @return array<mixed>
*/
public function bounds()
{
Expand Down Expand Up @@ -224,7 +224,7 @@ public function testBoundsIntegrationWithVersionParser($constraints, Bound $expe
}

/**
* @return array
* @return array<mixed>
*/
public function boundsIntegration()
{
Expand Down Expand Up @@ -304,6 +304,9 @@ public function testMultiConstraintOptimizations($constraints, ConstraintInterfa
$this->assertSame((string) $expectedConstraint, (string) $parser->parseConstraints($constraints));
}

/**
* @return array<mixed>
*/
public function multiConstraintOptimizations()
{
return array(
Expand Down Expand Up @@ -516,7 +519,7 @@ public function testMultiConstraintNotconjunctiveFillWithFalse()

$this->assertFalse($multiRequire->matches($versionProvide));
$this->assertFalse($versionProvide->matches($multiRequire));
$this->assertFalse($this->matchCompiled($multiRequire, '==', 1.1));
$this->assertFalse($this->matchCompiled($multiRequire, '==', '1.1'));
$this->assertFalse(Intervals::haveIntersections($multiRequire, $versionProvide));
}

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

$this->assertTrue($multiRequire->matches($versionProvide));
$this->assertTrue($versionProvide->matches($multiRequire));
$this->assertTrue($this->matchCompiled($multiRequire, '!=', 1.1));
$this->assertTrue($this->matchCompiled($multiRequire, '!=', '1.1'));
$this->assertTrue(Intervals::haveIntersections($multiRequire, $versionProvide));
}

/**
* @param Constraint::STR_OP_* $operator
* @param string $version
* @return bool
*/
private function matchCompiled(ConstraintInterface $constraint, $operator, $version)
{
$map = array(
Expand Down
5 changes: 5 additions & 0 deletions tests/IntervalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class IntervalsTest extends TestCase

/**
* @dataProvider compactProvider
* @param string $expected
* @param array<string> $toCompact
* @param bool $conjunctive
*/
public function testCompactConstraint($expected, $toCompact, $conjunctive)
{
Expand Down Expand Up @@ -191,6 +194,8 @@ public function compactProvider()

/**
* @dataProvider intervalsProvider
* @param array<mixed>|self::INTERVAL_* $expected
* @param string $constraint
*/
public function testGetIntervals($expected, $constraint)
{
Expand Down
20 changes: 10 additions & 10 deletions tests/SemverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function testSatisfies($expected, $version, $constraint)
* @dataProvider satisfiedByProvider
*
* @param string $constraint
* @param array $versions
* @param array $expected
* @param array<string> $versions
* @param array<string> $expected
*/
public function testSatisfiedBy($constraint, $versions, $expected)
{
Expand All @@ -50,9 +50,9 @@ public function testSatisfiedBy($constraint, $versions, $expected)
* @covers ::usort
* @dataProvider sortProvider
*
* @param array $versions
* @param array $sorted
* @param array $rsorted
* @param array<string> $versions
* @param array<string> $sorted
* @param array<string> $rsorted
*/
public function testSort(array $versions, array $sorted, array $rsorted)
{
Expand All @@ -77,7 +77,7 @@ public function testUsortShouldInitialVersionParserClass()
}

/**
* @return array
* @return array<mixed>
*/
public function sortProvider()
{
Expand All @@ -96,7 +96,7 @@ public function sortProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function satisfiesProvider()
{
Expand All @@ -116,7 +116,7 @@ public function satisfiesProvider()
}

/**
* @return array
* @return array<mixed>
*/
public function satisfiesProviderPositive()
{
Expand Down Expand Up @@ -198,7 +198,7 @@ public function satisfiesProviderPositive()
}

/**
* @return array
* @return array<mixed>
*/
public function satisfiesProviderNegative()
{
Expand Down Expand Up @@ -252,7 +252,7 @@ public function satisfiesProviderNegative()
}

/**
* @return array
* @return array<mixed>
*/
public function satisfiedByProvider()
{
Expand Down
Loading

0 comments on commit 43f8029

Please sign in to comment.