Skip to content

Commit

Permalink
minor #7 GitHub actions and php8 support (acrobat)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

I wanted to add php8 support to park-manager/hubkit and this was one the dependencies blocking php8 support.

You can see the build result here -> https://github.com/acrobat/version/actions/runs/416283590

So this PR does:
- Switch from travis-ci to github actions
- Allow and testing against php 8
- Fix phpstan errors after upgrading to 0.12 (that version is the earliest with php8 support)

If you want I can split this PR up into smaller PR's (all doing just one 1 thing)

Commits
-------

f8816f7 Switch CI from travis-ci to github actions
e190034 Allow php8
944cc1b PHPStan 0.12 fixes
  • Loading branch information
sstok authored Dec 15, 2020
2 parents a1b8fbd + 944cc1b commit 94b4d19
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 53 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
5 changes: 4 additions & 1 deletion src/ContinuesVersionsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ private function computePossibleVersionsFromLastExisting(): void
$this->possibleVersions = $version->getNextVersionCandidates();
}

private function getLastArrayIndex(array $array)
/**
* @param array<int, mixed> $array
*/
private function getLastArrayIndex(array $array): int
{
end($array);

Expand Down
4 changes: 2 additions & 2 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class Version
/**
* Higher means more stable.
*
* @var int[]
* @var array<string,int>
*/
private static $stabilityIndexes = [
'alpha' => self::STABILITY_ALPHA,
Expand Down Expand Up @@ -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 {
Expand Down
31 changes: 27 additions & 4 deletions tests/ContinuesVersionsValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

class ContinuesVersionsValidatorTest extends TestCase
{
/**
* @return array<int, string[]>
*/
public function provideInitialContinuesVersions(): iterable
{
yield ['0.1.0'];
Expand All @@ -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();

Expand All @@ -47,6 +50,9 @@ public function it_accepts_a_continues_version_with_no_pre_existing(string $new)
);
}

/**
* @return array<string, array<int, string[]|string>>
*/
public function provideContinuesVersions(): iterable
{
yield 'unstable #1' => ['0.3', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']];
Expand All @@ -63,15 +69,23 @@ public function provideContinuesVersions(): iterable
/**
* @test
* @dataProvider provideContinuesVersions
*
* @param array<int, string> $existing
* @param array<int, string> $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));

self::assertTrue($validator->isContinues(Version::fromString($new)));
self::assertEquals($this->createVersions($possible), array_merge([], $validator->getPossibleVersions()));
}

/**
* @param array<int, string> $existing
*
* @return array<int, Version>
*/
private function createVersions(array $existing): array
{
return array_map(
Expand All @@ -82,6 +96,9 @@ function (string $version) {
);
}

/**
* @return array<int, string[]>
*/
public function provideNotInitialContinuesVersions(): iterable
{
yield ['0.2.0'];
Expand All @@ -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();

Expand All @@ -111,6 +128,9 @@ public function it_rejects_non_continues_version_with_no_pre_existing(string $ne
);
}

/**
* @return array<string, array<int, string[]|string>>
*/
public function provideNonContinuesVersions(): iterable
{
yield 'unstable #1' => ['0.5', ['0.2', '0.1'], ['0.2.1', '0.3', '1.0-BETA1', '1.0']];
Expand All @@ -127,8 +147,11 @@ public function provideNonContinuesVersions(): iterable
/**
* @test
* @dataProvider provideNonContinuesVersions
*
* @param array<int, string> $existing
* @param array<int, string> $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));

Expand Down
31 changes: 21 additions & 10 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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');

Expand All @@ -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');

Expand All @@ -60,6 +60,9 @@ public function it_creates_without_patch()
self::assertEquals('1.0.0', (string) $version);
}

/**
* @return array<string,string[]>
*/
public function provideValidFormats(): array
{
return [
Expand All @@ -77,15 +80,15 @@ 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);

self::assertEquals($expectedOutput, (string) $version);
}

/** @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');
Expand All @@ -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"');
Expand All @@ -105,14 +108,17 @@ 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.');

Version::fromString('1.0.0-stable-5');
}

/**
* @return array<string,array<int, array<int, string>|string>>>
*/
public function provideExpectedNextVersionCandidates(): array
{
return [
Expand All @@ -132,15 +138,20 @@ public function provideExpectedNextVersionCandidates(): array
/**
* @test
* @dataProvider provideExpectedNextVersionCandidates
*
* @param array<int, string> $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);

self::assertEquals($expected, $candidates);
}

/**
* @return array<string,string[]>
*/
public function provideExpectedIncreasedVersion(): array
{
return [
Expand Down Expand Up @@ -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".');
Expand Down

0 comments on commit 94b4d19

Please sign in to comment.