Skip to content

Commit

Permalink
Merge pull request #130 from Seldaek/update-phpstan
Browse files Browse the repository at this point in the history
Updates to latest phpstan / CI
  • Loading branch information
Seldaek committed Feb 3, 2022
2 parents deac270 + b4e5118 commit a3e5e14
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 891 deletions.
9 changes: 1 addition & 8 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,12 @@ jobs:
- "7.3"
- "7.4"
- "8.0"
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Choose PHPUnit version"
run: |
if [ "${{ matrix.php-version }}" = "7.4" ]; then
echo "SYMFONY_PHPUNIT_VERSION=7.5" >> $GITHUB_ENV;
elif [ "${{ matrix.php-version }}" = "8.0" ]; then
echo "SYMFONY_PHPUNIT_VERSION=9.4" >> $GITHUB_ENV;
fi
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
"require-dev": {
"symfony/phpunit-bridge": "^4.2 || ^5",
"phpstan/phpstan": "^0.12.54"
"phpstan/phpstan": "^1.4"
},
"autoload": {
"psr-4": {
Expand All @@ -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

0 comments on commit a3e5e14

Please sign in to comment.