Skip to content

Commit

Permalink
#42 - enums fixed with SwitchCaseSemicolonToColonFixer update (#44)
Browse files Browse the repository at this point in the history
* #42 - enums fixed with SwitchCaseSemicolonToColonFixer update

* #42 - GHA PHP bumped

* #42 - GHA matrix

* #42 - ecsf

* #42 - more verbose exception messages

* #42 - ecsf
  • Loading branch information
krzysztofrewak authored Dec 16, 2021
1 parent 0b24f70 commit 9d8bda5
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 9 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
39 changes: 32 additions & 7 deletions tests/codestyle/CodestyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/codestyle/fixtures/enums/actual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

enum Status: string
{
case ACTIVE = "active";
case INACTIVE = "inactive";
}
9 changes: 9 additions & 0 deletions tests/codestyle/fixtures/enums/expected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

enum Status: string
{
case ACTIVE = "active";
case INACTIVE = "inactive";
}

0 comments on commit 9d8bda5

Please sign in to comment.