diff --git a/.github/workflows/auto-format-code.yml b/.github/workflows/auto-format-code.yml index 3c77cf5..8157669 100644 --- a/.github/workflows/auto-format-code.yml +++ b/.github/workflows/auto-format-code.yml @@ -1,9 +1,18 @@ -name: Auto-format code +name: Verify code formatting on: - push: + pull_request: branches: + - develop - master + push: + branches: + - develop + +permissions: + # Give the default GITHUB_TOKEN write permission to commit and push the + # added or changed files to the repository. + contents: write jobs: test: @@ -12,14 +21,9 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v1 - - - name: Setup PHP - uses: shivammathur/setup-php@master + uses: actions/checkout@v3 with: - php-version: '8.1' - extensions: exif,json,mbstring - coverage: none + fetch-depth: 0 - name: Setup NodeJS uses: actions/setup-node@v3 @@ -27,25 +31,49 @@ jobs: node-version: lts/* cache: 'npm' + - name: Install NodeJS dependencies + run: npm install --verbose --foreground-scripts + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + extensions: exif,json,mbstring + coverage: none + - name: Configure local Laravel Nova dummy package - run: composer config repositories.0 path ./tests/Fixtures/nova + run: | + composer config repositories.0 path ./tests/Fixtures/nova + git update-index --assume-unchanged composer.json composer.lock - name: Install Composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: composer-options: "--ignore-platform-req=php" dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible - - name: Install NodeJS dependencies - run: npm install - - name: Lint code run: | composer run format npm run format - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + - name: Report changes + id: report-changes + run: | + git diff --color=always + echo " > git diff --shortstat" >> $GITHUB_STEP_SUMMARY + echo " $( git diff --shortstat )" >> $GITHUB_STEP_SUMMARY + echo "HAS_CHANGES=$( git diff --quiet && echo 'no' || echo 'yes' )" >> $GITHUB_OUTPUT + + - name: Fail on changes (pull request only) + if: ${{ github.event_name == 'pull_request' && steps.report-changes.outputs.HAS_CHANGES == 'yes' }} + run: | + echo '::error title=Linting caused changes::Some files were modified by the linter, please run `composer format` to fix these' + exit 1 + + - name: Commit changes (push only) + if: ${{ github.event_name == 'push' }} + uses: stefanzweifel/git-auto-commit-action@v4.16.0 with: commit_message: Fixed code style using PHP-CS-Fixer diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 769d599..9270cff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,7 +8,7 @@ on: jobs: test: - name: Test on PHP ${{ matrix.php }} + name: Test Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental == true }} @@ -17,57 +17,76 @@ jobs: matrix: php: - '8.1' + - '8.2' - 'nightly' + laravel: + - '8.0' + - '9.0' + - '10.0' + include: + - php: '8.2' + laravel: '9.0' + stable: true - php: 'nightly' experimental: true + - laravel: '8.0' + testbench: '6.0' + - laravel: '9.0' + testbench: '7.0' + - laravel: '10.0' + testbench: '8.0' steps: - name: Checkout - uses: actions/checkout@v1 + uses: actions/checkout@v3 - name: Setup PHP - uses: shivammathur/setup-php@master + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} extensions: exif,json,mbstring coverage: pcov - - name: Setup problem matchers - run: | - echo "::add-matcher::${{ runner.tool_cache }}/php.json" - - name: Remove platform from Composer file run: composer config --unset platform - - name: Add GitHub Actions printer for PHPUnit - run: composer require --dev --no-update mheap/phpunit-github-actions-printer + - name: Configure to use Laravel ${{ matrix.laravel }} with Testbench ${{ matrix.testbench }} + run: | + composer require --no-update laravel/laravel:^${{ matrix.laravel }} + composer require --no-update --dev orchestra/testbench:^${{ matrix.testbench }} - name: Configure local Laravel Nova dummy package run: composer config repositories.0 path ./tests/Fixtures/nova - name: Install Composer dependencies - uses: ramsey/composer-install@v1 + uses: ramsey/composer-install@v2 with: composer-options: "--ignore-platform-req=php" - dependency-versions: highest # No lockfile is present, so locked (the default) isn't possible + dependency-versions: highest # We're installing additional packages, and cannot use the lockfile - - name: Lint code - run: composer run lint + - name: Run unit tests with coverage and printer + id: phpunit + run: | + echo "phpunit_version=$( vendor/bin/phpunit --version | cut -d ' ' -f 2 )" >> $GITHUB_OUTPUT + vendor/bin/phpunit \ + --log-junit ./report-junit.xml \ + --coverage-clover ./coverage-clover.xml - - name: Run unit tests - run: - vendor/bin/phpunit - --printer mheap\\GithubActionsReporter\\Printer - --coverage-clover=./coverage.xml + - name: Report test results + if: ${{ success() || failure() }} + uses: mikepenz/action-junit-report@v3 + with: + report_paths: ./report-junit.xml + check_name: Test Results Laravel ${{ matrix.laravel }} on PHP ${{ matrix.php }} with PHPUnit ${{ steps.phpunit.outputs.phpunit_version }} - name: Determine coverage - uses: slavcodev/coverage-monitor-action@1.1.0 - if: github.event_name == 'pull_request' && matrix.experimental != true + uses: slavcodev/coverage-monitor-action@1.8.0 + if: ${{ github.event_name == 'pull_request' && matrix.stable == true }} continue-on-error: true with: github_token: ${{ secrets.GITHUB_TOKEN }} - clover_file: ./coverage.xml + coverage_path: ./coverage-clover.xml threshold_alert: 60 threshold_warning: 85 diff --git a/phpunit.xml b/phpunit.xml index f43d9eb..91f13c1 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,6 +1,6 @@ - - + + ./src diff --git a/src/Http/Controllers/EditorJsImageUploadController.php b/src/Http/Controllers/EditorJsImageUploadController.php index f34ff71..e114165 100644 --- a/src/Http/Controllers/EditorJsImageUploadController.php +++ b/src/Http/Controllers/EditorJsImageUploadController.php @@ -119,7 +119,6 @@ public function url(Request $request): JsonResponse } /** - * @param $path * @param array $alterations */ private function applyAlterations($path, $alterations = []) @@ -187,7 +186,6 @@ private function applyAlterations($path, $alterations = []) } /** - * @param $path * @return array */ private function applyThumbnails($path) @@ -224,7 +222,6 @@ private function applyThumbnails($path) /** - * @param $path */ private function deleteThumbnails($path) { diff --git a/src/NovaEditorJsConverter.php b/src/NovaEditorJsConverter.php index 9e93114..aa04b90 100644 --- a/src/NovaEditorJsConverter.php +++ b/src/NovaEditorJsConverter.php @@ -147,7 +147,6 @@ protected function registerDefaultCallbacks(): void } /** - * @param $blockData * @return string */ protected function calculateImageClasses($blockData) diff --git a/tests/Feature/Http/Controllers/EditorJsImageUploadControllerTest.php b/tests/Feature/Http/Controllers/EditorJsImageUploadControllerTest.php index 9cd35d1..e092ca9 100644 --- a/tests/Feature/Http/Controllers/EditorJsImageUploadControllerTest.php +++ b/tests/Feature/Http/Controllers/EditorJsImageUploadControllerTest.php @@ -167,7 +167,7 @@ public function testSubmittingImageUrlWithErrors(): void * Provides a list of valid image files to test. * @return string[][] */ - public function provideValidFiles(): array + public static function provideValidFiles(): array { return [ 'gif' => [test_resource('responses/image.gif')], @@ -182,9 +182,9 @@ public function provideValidFiles(): array * Provides a subset of the available image formats, since svg isn't supported by the GD library. * @return string[][] */ - public function provideValidFilesForImageUpload(): array + public static function provideValidFilesForImageUpload(): array { - return Arr::except($this->provideValidFiles(), [ + return Arr::except(self::provideValidFiles(), [ 'svg', ]); } diff --git a/tests/TestCase.php b/tests/TestCase.php index d8ccb1a..b5ab120 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -16,6 +16,23 @@ class TestCase extends OrchestraTestCase { use DatabaseMigrations; + /** + * Ensure the HTTP Client requests have a method to prevent stray requests (without logic) + * @before + */ + protected function repairLaravel8Compatibiliy() + { + if (! \Composer\InstalledVersions::satisfies(new \Composer\Semver\VersionParser(), 'illuminate/support', '^8.0')) { + return; + } + + $this->afterApplicationCreated(function () { + \Illuminate\Http\Client\PendingRequest::macro('preventStrayRequests', function () { + return $this; + }); + }); + } + /** * Path to config file from here */