diff --git a/.gitattributes b/.gitattributes index b263871..d3f20b0 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,9 +2,10 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". +/.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/.travis.yml export-ignore /phpunit.xml.dist export-ignore -/.scrutinizer.yml export-ignore /tests export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml new file mode 100644 index 0000000..62f6106 --- /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.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/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..8d579a9 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,48 @@ +name: "Tests" + +on: + push: + branches: [develop] + pull_request: + branches: [main] + schedule: + - cron: '0 0 * * *' + +jobs: + run-tests: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php: [7.4, 8.0, 8.1] + laravel: [8.*] + dependency-version: [prefer-lowest, prefer-stable] + include: + - laravel: 8.* + testbench: ^6.23 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - 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 + coverage: none + + - name: Setup Problem Matches + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/phpunit diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..0e73b1e --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,28 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +jobs: + update: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: master + + - name: Update Changelog + uses: stefanzweifel/changelog-updater-action@v1 + with: + latest-version: ${{ github.event.release.name }} + release-notes: ${{ github.event.release.body }} + + - name: Commit updated CHANGELOG + uses: stefanzweifel/git-auto-commit-action@v4 + with: + branch: master + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.php_cs.dist.php b/.php_cs.dist.php new file mode 100644 index 0000000..316fec0 --- /dev/null +++ b/.php_cs.dist.php @@ -0,0 +1,34 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->name('*.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, + '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 d3ad737..29a905d 100644 --- a/composer.json +++ b/composer.json @@ -17,11 +17,12 @@ ], "type": "library", "require": { - "illuminate/support": "^6.0|^7.0|^8.0" + "php": "^7.4|^8.0", + "illuminate/support": "^6.20.13|7.30.4|^8.22.2" }, "require-dev": { - "phpunit/phpunit": "~9.0", - "orchestra/testbench": "~5|~6", + "phpunit/phpunit": "^9.3", + "orchestra/testbench": "^5.20|^6.23", "friendsofphp/php-cs-fixer": "^3.0" }, "autoload": { @@ -42,8 +43,8 @@ } }, "scripts": { - "test": "phpunit", - "format": "vendor/bin/php-cs-fixer fix --allow-risky=yes" + "format": "vendor/bin/php-cs-fixer fix --config=.php_cs.dist.php --allow-risky=yes", + "test": "vendor/bin/phpunit" }, "minimum-stability": "dev", "prefer-stable": true diff --git a/src/Console/Commands/HelperMakeCommand.php b/src/Console/Commands/HelperMakeCommand.php index 9a09334..98a5e18 100644 --- a/src/Console/Commands/HelperMakeCommand.php +++ b/src/Console/Commands/HelperMakeCommand.php @@ -34,17 +34,18 @@ class HelperMakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__ . '/stubs/helper.stub'; + return __DIR__.'/stubs/helper.stub'; } /** * Get the default namespace for the class. * - * @param string $rootNamespace + * @param string $rootNamespace + * * @return string */ protected function getDefaultNamespace($rootNamespace) { - return $rootNamespace . '\\' . config('helpers.directory', 'Helpers'); + return $rootNamespace.'\\'.config('helpers.directory', 'Helpers'); } } diff --git a/src/HelperServiceProvider.php b/src/HelperServiceProvider.php index d5f469c..34677dd 100644 --- a/src/HelperServiceProvider.php +++ b/src/HelperServiceProvider.php @@ -7,7 +7,7 @@ class HelperServiceProvider extends ServiceProvider { - public const CONFIG_PATH = __DIR__ . '/../config/helpers.php'; + public const CONFIG_PATH = __DIR__.'/../config/helpers.php'; /** * Bootstrap the application events. @@ -35,7 +35,7 @@ public function boot() public function register() { $this->mergeConfigFrom(self::CONFIG_PATH, 'helper'); - $files = glob(app_path(config('helpers.directory', 'Helpers') . '/*.php')); + $files = glob(app_path(config('helpers.directory', 'Helpers').'/*.php')); foreach ($files as $file) { require_once $file; diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index a4f9e42..53ef3f3 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -7,6 +7,6 @@ class HelpersTest extends TestCase /** @test */ public function test_console_command() { - $this->assertEquals(1, 1); + $this->artisan('make:helper', ['name' => 'TestHelper'])->assertExitCode(0); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index b7ae21c..938bbe4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,8 +2,20 @@ namespace Devtical\Helpers\Tests; +use Devtical\Helpers\HelperServiceProvider; use Orchestra\Testbench\TestCase as Orchestra; abstract class TestCase extends Orchestra { + /** + * @param \Illuminate\Foundation\Application $app + * + * @return array + */ + protected function getPackageProviders($app): array + { + return [ + HelperServiceProvider::class, + ]; + } }