From 9d8bda54e8a6e8dd20b50e18454a656274470fbb Mon Sep 17 00:00:00 2001 From: Krzysztof Rewak Date: Thu, 16 Dec 2021 12:11:18 +0100 Subject: [PATCH] #42 - enums fixed with SwitchCaseSemicolonToColonFixer update (#44) * #42 - enums fixed with SwitchCaseSemicolonToColonFixer update * #42 - GHA PHP bumped * #42 - GHA matrix * #42 - ecsf * #42 - more verbose exception messages * #42 - ecsf --- .github/workflows/check.yml | 10 ++++++ composer.json | 2 +- docker-compose.yml | 2 +- tests/codestyle/CodestyleTest.php | 39 +++++++++++++++++---- tests/codestyle/fixtures/enums/actual.php | 7 ++++ tests/codestyle/fixtures/enums/expected.php | 9 +++++ 6 files changed, 60 insertions(+), 9 deletions(-) create mode 100644 tests/codestyle/fixtures/enums/actual.php create mode 100644 tests/codestyle/fixtures/enums/expected.php diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index d04cd4d..78221bc 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -10,9 +10,19 @@ jobs: build: runs-on: ubuntu-20.04 + strategy: + matrix: + php: ["8.0", "8.1"] + steps: - uses: actions/checkout@v2 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + - name: Cache composer dependencies uses: actions/cache@v2 with: diff --git a/composer.json b/composer.json index f4bef31..95d387f 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "type": "library", "require": { "php": "^8.0", - "symplify/easy-coding-standard": "9.4.70" + "symplify/easy-coding-standard": "10.0.2" }, "require-dev": { "composer/composer": "2.*", diff --git a/docker-compose.yml b/docker-compose.yml index a61ead4..1818c96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.7" services: php: - image: ghcr.io/blumilksoftware/php:8.0.3.1 + image: ghcr.io/blumilksoftware/php:8.1.0.0 container_name: blumilk-codestyle-php working_dir: /application user: ${CURRENT_UID:-1000} diff --git a/tests/codestyle/CodestyleTest.php b/tests/codestyle/CodestyleTest.php index 0c3d63d..ac316c9 100644 --- a/tests/codestyle/CodestyleTest.php +++ b/tests/codestyle/CodestyleTest.php @@ -17,12 +17,36 @@ protected function tearDown(): void } /** + * @requires PHP >= 8.0 * @throws Exception */ - public function testFixtures(): void + public function testPhp80Fixtures(): void { - $fixtures = scandir(__DIR__ . "/fixtures"); - $fixtures = array_filter($fixtures, fn(string $dir): bool => !str_contains($dir, ".")); + $fixtures = [ + "noExtraBlankLines", + "noExtraBlankLines", + "nullableTypeForDefaultNull", + "operatorSpacing", + "singleQuotes", + "strictTypes", + "trailingCommas", + "unionTypes", + ]; + + foreach ($fixtures as $fixture) { + $this->testFixture($fixture); + } + } + + /** + * @requires PHP >= 8.1 + * @throws Exception + */ + public function testPhp81Fixtures(): void + { + $fixtures = [ + "enums", + ]; foreach ($fixtures as $fixture) { $this->testFixture($fixture); @@ -38,7 +62,7 @@ protected function runComposerEcsCommand(bool $fix = false): bool $result = 0; $output = null; - exec("./vendor/bin/composer " . $command, $output, $result); + exec("./vendor/bin/composer " . $command . " 2> /dev/null", $output, $result); return $result === 0; } @@ -49,9 +73,10 @@ protected function runComposerEcsCommand(bool $fix = false): bool protected function testFixture(string $name): void { copy(__DIR__ . "/fixtures/${name}/actual.php", __DIR__ . "/tmp/${name}.php"); - $this->assertFalse($this->runComposerEcsCommand()); - $this->assertTrue($this->runComposerEcsCommand(true)); - $this->assertFileEquals(__DIR__ . "/fixtures/${name}/expected.php", __DIR__ . "/tmp/${name}.php"); + + $this->assertFalse($this->runComposerEcsCommand(), "Fixture fixtures/${name} returned invalid true result."); + $this->assertTrue($this->runComposerEcsCommand(true), "Fixture fixtures/${name} was not proceeded properly."); + $this->assertFileEquals(__DIR__ . "/fixtures/${name}/expected.php", __DIR__ . "/tmp/${name}.php", "Result of proceeded fixture fixtures/${name} is not equal to expected."); } protected function clearTempDirectory(): void diff --git a/tests/codestyle/fixtures/enums/actual.php b/tests/codestyle/fixtures/enums/actual.php new file mode 100644 index 0000000..d77670f --- /dev/null +++ b/tests/codestyle/fixtures/enums/actual.php @@ -0,0 +1,7 @@ +