diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..776c4f6 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,68 @@ +name: Full CI process +on: + push: + branches: + - master + pull_request: + branches: + - master + +jobs: + test: + name: PHP ${{ matrix.php-versions }} + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + matrix: + php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0'] + + steps: + # —— Setup Github actions 🐙 ————————————————————————————————————————————— + # https://github.com/actions/checkout (official) + - + name: Checkout + uses: actions/checkout@v2 + + # https://github.com/shivammathur/setup-php (community) + - + name: Setup PHP and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: none + + # —— Composer 🧙‍️ ————————————————————————————————————————————————————————— + - + name: Install Composer dependencies + run: composer update --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi + + ## —— Tests ✅ ——————————————————————————————————————————————————————————— + - + name: Run Tests + run: vendor/bin/phpunit --disallow-test-output --verbose + phpstan: + name: PHPStan + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - + name: Checkout + uses: actions/checkout@v2 + + # https://github.com/shivammathur/setup-php (community) + - + name: Setup PHP and composer with shivammathur/setup-php + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + coverage: none + + # —— Composer 🧙‍️ ————————————————————————————————————————————————————————— + - + name: Install Composer dependencies + run: composer update --no-progress --no-interaction --no-suggest --optimize-autoloader --ansi + + - + name: Run PHPStan + run: vendor/bin/phpstan analyse diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9be9efc..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -sudo: false - -branches: - only: - - master - -matrix: - include: - - php: '7.1' - - php: '7.2' - -cache: - directories: - - $HOME/.composer/cache - -before_install: - - phpenv config-rm xdebug.ini || echo "xdebug not available" - - export PATH="$PATH:$HOME/.composer/vendor/bin" - -install: - - composer install --no-progress --no-suggest --ansi - -script: - - ./vendor/bin/phpunit --disallow-test-output --verbose - - ./vendor/bin/phpstan analyse diff --git a/composer.json b/composer.json index 1ab0fb4..8ce597c 100644 --- a/composer.json +++ b/composer.json @@ -10,13 +10,13 @@ } ], "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "require-dev": { - "phpunit/phpunit": "^7.3.2", - "phpstan/phpstan": "^0.10.3", - "phpstan/phpstan-phpunit": "^0.10", - "symfony/phpunit-bridge": "^4.1" + "phpunit/phpunit": "^7.3.2|^8.5.12", + "phpstan/phpstan": "^0.12.33", + "phpstan/phpstan-phpunit": "^0.12.13", + "symfony/phpunit-bridge": "^5.2" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 1ed8567..c05fef4 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,10 +1,9 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + parameters: level: 7 paths: - src - tests - autoload_files: - - vendor/autoload.php ignoreErrors: - includes: - - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/ContinuesVersionsValidator.php b/src/ContinuesVersionsValidator.php index f34f350..d4868cc 100644 --- a/src/ContinuesVersionsValidator.php +++ b/src/ContinuesVersionsValidator.php @@ -106,7 +106,10 @@ private function computePossibleVersionsFromLastExisting(): void $this->possibleVersions = $version->getNextVersionCandidates(); } - private function getLastArrayIndex(array $array) + /** + * @param array $array + */ + private function getLastArrayIndex(array $array): int { end($array); diff --git a/src/Version.php b/src/Version.php index 2873a6c..7220c3e 100644 --- a/src/Version.php +++ b/src/Version.php @@ -50,7 +50,7 @@ final class Version /** * Higher means more stable. * - * @var int[] + * @var array */ private static $stabilityIndexes = [ 'alpha' => self::STABILITY_ALPHA, @@ -81,7 +81,7 @@ private function __construct(int $major, int $minor, int $patch, int $stability, $this->major, $this->minor, $this->patch, - strtoupper(array_search($this->stability, self::$stabilityIndexes, true)), + strtoupper(array_search($this->stability, self::$stabilityIndexes, true)), /** @phpstan-ignore-line */ $this->metaver ); } else { diff --git a/tests/ContinuesVersionsValidatorTest.php b/tests/ContinuesVersionsValidatorTest.php index a59a14a..2efb024 100644 --- a/tests/ContinuesVersionsValidatorTest.php +++ b/tests/ContinuesVersionsValidatorTest.php @@ -19,6 +19,9 @@ class ContinuesVersionsValidatorTest extends TestCase { + /** + * @return array + */ public function provideInitialContinuesVersions(): iterable { yield ['0.1.0']; @@ -31,7 +34,7 @@ public function provideInitialContinuesVersions(): iterable * @test * @dataProvider provideInitialContinuesVersions */ - public function it_accepts_a_continues_version_with_no_pre_existing(string $new) + public function it_accepts_a_continues_version_with_no_pre_existing(string $new): void { $validator = new ContinuesVersionsValidator(); @@ -47,6 +50,9 @@ public function it_accepts_a_continues_version_with_no_pre_existing(string $new) ); } + /** + * @return array> + */ public function provideContinuesVersions(): iterable { yield 'unstable #1' => ['0.3', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']]; @@ -63,8 +69,11 @@ public function provideContinuesVersions(): iterable /** * @test * @dataProvider provideContinuesVersions + * + * @param array $existing + * @param array $possible */ - public function it_accepts_a_continues_version(string $new, array $existing, array $possible) + public function it_accepts_a_continues_version(string $new, array $existing, array $possible): void { $validator = new ContinuesVersionsValidator(...$this->createVersions($existing)); @@ -72,6 +81,11 @@ public function it_accepts_a_continues_version(string $new, array $existing, arr self::assertEquals($this->createVersions($possible), array_merge([], $validator->getPossibleVersions())); } + /** + * @param array $existing + * + * @return array + */ private function createVersions(array $existing): array { return array_map( @@ -82,6 +96,9 @@ function (string $version) { ); } + /** + * @return array + */ public function provideNotInitialContinuesVersions(): iterable { yield ['0.2.0']; @@ -95,7 +112,7 @@ public function provideNotInitialContinuesVersions(): iterable * @test * @dataProvider provideNotInitialContinuesVersions */ - public function it_rejects_non_continues_version_with_no_pre_existing(string $new) + public function it_rejects_non_continues_version_with_no_pre_existing(string $new): void { $validator = new ContinuesVersionsValidator(); @@ -111,6 +128,9 @@ public function it_rejects_non_continues_version_with_no_pre_existing(string $ne ); } + /** + * @return array> + */ public function provideNonContinuesVersions(): iterable { yield 'unstable #1' => ['0.5', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']]; @@ -127,8 +147,11 @@ public function provideNonContinuesVersions(): iterable /** * @test * @dataProvider provideNonContinuesVersions + * + * @param array $existing + * @param array $possible */ - public function it_rejects_non_continues_version(string $new, array $existing, array $possible) + public function it_rejects_non_continues_version(string $new, array $existing, array $possible): void { $validator = new ContinuesVersionsValidator(...$this->createVersions($existing)); diff --git a/tests/VersionTest.php b/tests/VersionTest.php index fc57d22..90bfca9 100644 --- a/tests/VersionTest.php +++ b/tests/VersionTest.php @@ -19,7 +19,7 @@ class VersionTest extends TestCase { /** @test */ - public function it_creates_from_full_string() + public function it_creates_from_full_string(): void { $version = Version::fromString('1.0.0-beta-5'); @@ -33,7 +33,7 @@ public function it_creates_from_full_string() } /** @test */ - public function it_creates_with_explicit_stable() + public function it_creates_with_explicit_stable(): void { $version = Version::fromString('1.0.0-stable'); @@ -47,7 +47,7 @@ public function it_creates_with_explicit_stable() } /** @test */ - public function it_creates_without_patch() + public function it_creates_without_patch(): void { $version = Version::fromString('1.0'); @@ -60,6 +60,9 @@ public function it_creates_without_patch() self::assertEquals('1.0.0', (string) $version); } + /** + * @return array + */ public function provideValidFormats(): array { return [ @@ -77,7 +80,7 @@ public function provideValidFormats(): array * @test * @dataProvider provideValidFormats */ - public function it_supports_various_formats(string $version, string $expectedOutput) + public function it_supports_various_formats(string $version, string $expectedOutput): void { $version = Version::fromString($version); @@ -85,7 +88,7 @@ public function it_supports_various_formats(string $version, string $expectedOut } /** @test */ - public function it_compares_two_versions_are_equal() + public function it_compares_two_versions_are_equal(): void { $version = Version::fromString('1.0.0-beta-5'); $version2 = Version::fromString('1.0.0-beta5'); @@ -96,7 +99,7 @@ public function it_compares_two_versions_are_equal() } /** @test */ - public function it_fails_for_invalid_format() + public function it_fails_for_invalid_format(): void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Unable to parse version "1.0.0-WAT"'); @@ -105,7 +108,7 @@ public function it_fails_for_invalid_format() } /** @test */ - public function it_fails_with_stable_plus_metaver() + public function it_fails_with_stable_plus_metaver(): void { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Meta version of the stability flag cannot be set for stable.'); @@ -113,6 +116,9 @@ public function it_fails_with_stable_plus_metaver() Version::fromString('1.0.0-stable-5'); } + /** + * @return array|string>>> + */ public function provideExpectedNextVersionCandidates(): array { return [ @@ -132,8 +138,10 @@ public function provideExpectedNextVersionCandidates(): array /** * @test * @dataProvider provideExpectedNextVersionCandidates + * + * @param array $expected */ - public function it_provides_next_version_candidates($current, $expected) + public function it_provides_next_version_candidates(string $current, array $expected): void { $candidates = Version::fromString($current)->getNextVersionCandidates(); $expected = array_map([Version::class, 'fromString'], $expected); @@ -141,6 +149,9 @@ public function it_provides_next_version_candidates($current, $expected) self::assertEquals($expected, $candidates); } + /** + * @return array + */ public function provideExpectedIncreasedVersion(): array { return [ @@ -199,13 +210,13 @@ public function provideExpectedIncreasedVersion(): array * @test * @dataProvider provideExpectedIncreasedVersion */ - public function it_increases_to_next_version(string $current, string $expected, $stability) + public function it_increases_to_next_version(string $current, string $expected, string $stability): void { self::assertEquals(Version::fromString($expected), Version::fromString($current)->getNextIncreaseOf($stability)); } /** @test */ - public function it_cannot_increases_for_unsupported() + public function it_cannot_increases_for_unsupported(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Unknown stability "next-stable", accepts "alpha", "beta", "rc", "stable", "major", "next", "minor", "patch".');