-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #5 - testing configuration options * #5 - unpacking options * #5 - changing Ubuntu to 20.04 * #5 - changing blumilksoftware/php to 8.0.2.1
- Loading branch information
1 parent
d35147f
commit 57206c9
Showing
16 changed files
with
480 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: "Checking the package: testing and linting" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Validate composer.json | ||
run: composer validate | ||
|
||
- name: Run the Docker containers | ||
run: docker-compose up -d | ||
|
||
- name: Cache composer dependencies | ||
uses: actions/cache@v2 | ||
with: | ||
path: vendor | ||
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-composer- | ||
- name: Install dependencies | ||
run: docker-compose run php composer install --prefer-dist --no-progress --no-suggest | ||
|
||
- name: Run code style checker | ||
run: docker-compose run php composer ecs | ||
|
||
- name: Run tests | ||
run: docker-compose run php composer test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,8 @@ public function filter(string ...$paths): self | |
} | ||
} | ||
|
||
$this->paths = array_values($this->paths); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\Codestyle\Configuration\Defaults; | ||
|
||
use Blumilk\Codestyle\Configuration\Utils\Rule; | ||
|
||
class Rules | ||
{ | ||
protected array $rules = []; | ||
|
||
public function get(): array | ||
{ | ||
return $this->rules; | ||
} | ||
|
||
public function add(Rule ...$rules): self | ||
{ | ||
foreach ($rules as $rule) { | ||
if (!in_array($rule->getFixerClassName(), array_keys($this->rules), true)) { | ||
$this->rules[$rule->getFixerClassName()] = $rule->getOptions(); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
public function clear(): self | ||
{ | ||
$this->rules = []; | ||
|
||
return $this; | ||
} | ||
|
||
public function filter(string ...$rules): self | ||
{ | ||
foreach (array_keys($this->rules) as $rule) { | ||
if (in_array($rule, $rules, true)) { | ||
unset($this->rules[$rule]); | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\Codestyle\Configuration\Utils; | ||
|
||
class Rule | ||
{ | ||
protected string $fixer; | ||
protected ?array $options; | ||
|
||
public function __construct(string $fixer, ?array $options = null) | ||
{ | ||
$this->fixer = $fixer; | ||
$this->options = $options; | ||
} | ||
|
||
public function getFixerClassName(): string | ||
{ | ||
return $this->fixer; | ||
} | ||
|
||
public function getOptions(): ?array | ||
{ | ||
return $this->options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Blumilk\Codestyle\Config; | ||
use Blumilk\Codestyle\Configuration\Defaults\CommonAdditionalRules; | ||
use Blumilk\Codestyle\Configuration\Utils\Rule; | ||
use Blumilk\Codestyle\Fixers\DoubleQuoteFixer; | ||
use PhpCsFixer\Fixer\Alias\NoMixedEchoPrintFixer; | ||
use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; | ||
use PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer; | ||
use PhpCsFixer\Fixer\StringNotation\HeredocToNowdocFixer; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AdditionalRulesConfigurationTest extends TestCase | ||
{ | ||
public function testAdditionalRulesConfiguration(): void | ||
{ | ||
$rules = new CommonAdditionalRules(); | ||
$config = new Config(rules: $rules); | ||
|
||
$this->assertSame([ | ||
DeclareStrictTypesFixer::class => null, | ||
CastSpacesFixer::class => [ | ||
"space" => "none", | ||
], | ||
DoubleQuoteFixer::class => null, | ||
], $config->options()["rules"]); | ||
} | ||
|
||
public function testClearingAdditionalRulesConfiguration(): void | ||
{ | ||
$rules = new CommonAdditionalRules(); | ||
$config = new Config(rules: $rules->clear()); | ||
|
||
$this->assertSame([], $config->options()["rules"]); | ||
} | ||
|
||
public function testFilteringAdditionalRulesConfiguration(): void | ||
{ | ||
$rules = new CommonAdditionalRules(); | ||
$config = new Config(rules: $rules->filter(CastSpacesFixer::class)); | ||
|
||
$this->assertSame([ | ||
DeclareStrictTypesFixer::class => null, | ||
DoubleQuoteFixer::class => null, | ||
], $config->options()["rules"]); | ||
} | ||
|
||
public function testExtendingAdditionalRulesConfiguration(): void | ||
{ | ||
$rules = new CommonAdditionalRules(); | ||
$config = new Config( | ||
rules: $rules->add(new Rule(HeredocToNowdocFixer::class)) | ||
); | ||
|
||
$this->assertSame([ | ||
DeclareStrictTypesFixer::class => null, | ||
CastSpacesFixer::class => [ | ||
"space" => "none", | ||
], | ||
DoubleQuoteFixer::class => null, | ||
HeredocToNowdocFixer::class => null, | ||
], $config->options()["rules"]); | ||
} | ||
|
||
public function testExtendingWithOptionsAdditionalRulesConfiguration(): void | ||
{ | ||
$rules = new CommonAdditionalRules(); | ||
$config = new Config( | ||
rules: $rules->add(new Rule(NoMixedEchoPrintFixer::class, [ | ||
"use" => "echo", | ||
])) | ||
); | ||
|
||
$this->assertSame([ | ||
DeclareStrictTypesFixer::class => null, | ||
CastSpacesFixer::class => [ | ||
"space" => "none", | ||
], | ||
DoubleQuoteFixer::class => null, | ||
NoMixedEchoPrintFixer::class => [ | ||
"use" => "echo", | ||
], | ||
], $config->options()["rules"]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Blumilk\Codestyle\Config; | ||
use Blumilk\Codestyle\Configuration\Defaults\LaravelPaths; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class LaravelPathsConfigurationTest extends TestCase | ||
{ | ||
public function testLaravelPathsConfiguration(): void | ||
{ | ||
$paths = new LaravelPaths(); | ||
$config = new Config(paths: $paths); | ||
|
||
$this->assertSame(["app", "config", "database", "resources/lang", "routes", "tests"], | ||
$config->options()["paths"]); | ||
} | ||
|
||
public function testFilteredLaravelPathsConfiguration(): void | ||
{ | ||
$paths = new LaravelPaths(); | ||
$config = new Config(paths: $paths->filter("resources/lang")); | ||
|
||
$this->assertSame(["app", "config", "database", "routes", "tests"], | ||
$config->options()["paths"]); | ||
} | ||
|
||
public function testClearedLaravelPathsConfiguration(): void | ||
{ | ||
$paths = new LaravelPaths(); | ||
$config = new Config(paths: $paths->clear()->add("src")); | ||
|
||
$this->assertSame(["src"], $config->options()["paths"]); | ||
} | ||
} |
Oops, something went wrong.