diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..a83d708 --- /dev/null +++ b/.github/workflows/php-cs-fixer.yml @@ -0,0 +1,23 @@ +name: Check & fix styling + +on: [push] + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.head_ref }} + + - name: Run PHP CS Fixer + uses: docker://oskarstark/php-cs-fixer-ga + with: + args: --config=.php-cs-fixer.dist.php --allow-risky=yes + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: Fix styling diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b1761a1..6f8fe3f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,38 +1,36 @@ -name: run-tests +name: Tests -on: - push: - pull_request: +on: [push, pull_request] jobs: test: - runs-on: [ubuntu-latest] + runs-on: ubuntu-latest strategy: - fail-fast: false + fail-fast: true matrix: - php: [8.0, 7.4, 7.3, 7.2, 7.1] - dependency-version: [prefer-lowest, prefer-stable] + php: [8.0, 8.1] + stability: [prefer-lowest, prefer-stable] - name: P${{ matrix.php }} ${{ matrix.dependency-version }} + name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} steps: - name: Checkout code uses: actions/checkout@v2 - - name: Cache dependencies - uses: actions/cache@v1 - with: - path: ~/.composer/cache/files - key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo coverage: none + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + - name: Install dependencies - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests run: vendor/bin/phpunit diff --git a/.gitignore b/.gitignore index bb36c67..5c4133d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ docs vendor coverage phpunit.xml +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..8d8a790 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,40 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.php') + ->notName('*.blade.php') + ->ignoreDotFiles(true) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setRules([ + '@PSR12' => true, + 'array_syntax' => ['syntax' => 'short'], + 'ordered_imports' => ['sort_algorithm' => 'alpha'], + 'no_unused_imports' => true, + 'not_operator_with_successor_space' => true, + 'trailing_comma_in_multiline' => true, + 'phpdoc_scalar' => true, + 'unary_operator_spaces' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => [ + 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], + ], + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_var_without_name' => true, + 'class_attributes_separation' => [ + 'elements' => [ + 'method' => 'one', + ], + ], + 'method_argument_space' => [ + 'on_multiline' => 'ensure_fully_multiline', + 'keep_multiple_spaces_after_comma' => true, + ], + 'single_trait_insert_per_statement' => true, + ]) + ->setFinder($finder); diff --git a/composer.json b/composer.json index 544b90a..22a354e 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,12 @@ } ], "require": { - "php": "^7.1|^8.0" + "php": "^8.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.2", "larapack/dd": "^1.0", - "phpunit/phpunit": "^7.0|^8.0|^9.0" + "phpunit/phpunit": "^9.0" }, "autoload": { "psr-4": { @@ -33,6 +34,9 @@ "sixlive\\DotenvEditor\\Tests\\": "tests" } }, + "scripts": { + "cs": "vendor/bin/php-cs-fixer fix --config=./.php-cs-fixer.dist.php" + }, "config": { "sort-packages": true } diff --git a/tests/DotenvEditorTest.php b/tests/DotenvEditorTest.php index 268bc8c..ca9634e 100644 --- a/tests/DotenvEditorTest.php +++ b/tests/DotenvEditorTest.php @@ -25,7 +25,7 @@ public function tearDown(): void /** @test */ public function a_config_value_can_be_set() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -38,7 +38,7 @@ public function a_config_value_can_be_set() /** @test */ public function a_config_value_can_be_unset() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -52,7 +52,7 @@ public function a_config_value_can_be_unset() /** @test */ public function all_config_values_can_be_retrieved() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->set('EXAMPLE_CONFIG', 'foo'); $editor->set('EXAMPLE_CONFIG_2', 'bar'); @@ -68,7 +68,7 @@ public function all_config_values_can_be_retrieved() /** @test */ public function config_values_can_be_saved() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -81,7 +81,7 @@ public function config_values_can_be_saved() public function config_values_can_be_saved_to_a_new_path() { $newPath = __DIR__.'/tmp/env-new'; - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -93,7 +93,7 @@ public function config_values_can_be_saved_to_a_new_path() /** @test */ public function multiple_config_values_can_be_saved() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -111,7 +111,7 @@ public function multiple_config_values_can_be_saved() /** @test */ public function line_breaks_can_be_added() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('EXAMPLE_CONFIG', 'foo'); @@ -128,7 +128,7 @@ public function line_breaks_can_be_added() /** @test */ public function headings_can_be_added() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->heading('Examples'); @@ -144,7 +144,7 @@ public function headings_can_be_added() /** @test */ public function headings_get_added_with_a_new_line_after_a_non_blank_entry() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('APP_KEY', 'bar'); @@ -163,7 +163,7 @@ public function headings_get_added_with_a_new_line_after_a_non_blank_entry() /** @test */ public function values_from_files_are_imported_on_load() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load(__DIR__.'/Fixtures/env-example'); @@ -180,7 +180,7 @@ public function values_from_files_are_imported_on_load() /** @test */ public function keys_can_be_checked_for() { - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load(__DIR__.'/Fixtures/env-example'); $this->assertTrue($editor->has('EXAMPLE_2')); @@ -190,7 +190,7 @@ public function keys_can_be_checked_for() public function configuration_values_can_be_merge_with_an_existing_config() { copy(__DIR__.'/Fixtures/env-example', $this->path); - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->heading('Foo'); @@ -210,7 +210,7 @@ public function leaves_blank_settings_as_they_were() $fixturePath = __DIR__.'/Fixtures/env-laravel'; copy($fixturePath, $this->path); - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $editor->set('FOO', 'bar'); @@ -227,7 +227,7 @@ public function an_exception_is_thrown_if_the_file_does_not_exist() { $this->expectException(InvalidArgumentException::class); - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load(__DIR__.'/.env'); } @@ -237,7 +237,7 @@ public function returns_true_if_file_is_written() $fixturePath = __DIR__.'/Fixtures/env-laravel'; copy($fixturePath, $this->path); - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($this->path); $this->assertTrue($editor->save()); @@ -248,7 +248,7 @@ public function does_not_modify_app_key() { $fixturePath = __DIR__.'/Fixtures/env-laravel'; - $editor = new DotenvEditor; + $editor = new DotenvEditor(); $editor->load($fixturePath); $this->assertEquals( 'base64:LPqcjIZ3/T2pO4yrL7vgb6W/+hgyau002onyOKHvzfo=',