diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9cf06b0..e1e39a4 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -42,7 +42,7 @@ jobs: 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 + coverage: xdebug - name: Setup problem matchers run: | @@ -55,4 +55,11 @@ jobs: composer update --${{ matrix.stability }} --prefer-dist --no-interaction - name: Execute tests - run: vendor/bin/pest + run: vendor/bin/pest --coverage-cobertura coverage.xml + + - name: Upload coverage + uses: gaelgirodon/ci-badges-action@v1 + if: github.ref == 'refs/heads/main' + with: + gist-id: 9dd8e508cb2433728d42a258193770eb + token: ${{ secrets.GIST_TOKEN }} diff --git a/README.md b/README.md index a2e03fc..3c8b6cf 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/oddvalue/laravel-drafts/run-tests.yml?label=tests&style=flat-square)](https://github.com/oddvalue/laravel-drafts/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/oddvalue/laravel-drafts/php-cs-fixer.yml?label=code%20style&style=flat-square)](https://github.com/oddvalue/laravel-drafts/actions?query=workflow%3A"Check+%26+fix+styling"+branch%3Amain) [![Total Downloads](https://img.shields.io/packagist/dt/oddvalue/laravel-drafts.svg?style=flat-square)](https://packagist.org/packages/oddvalue/laravel-drafts) +![Coverage](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/oddvalue/9dd8e508cb2433728d42a258193770eb/raw/laravel-drafts-cobertura-coverage.json) * [Installation](#installation) * [Usage](#usage) diff --git a/composer.json b/composer.json index 0d2d04b..bef7c45 100644 --- a/composer.json +++ b/composer.json @@ -33,6 +33,7 @@ "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.0|^10.0", "roave/security-advisories": "dev-latest", + "spatie/invade": "^2.0", "spatie/pest-plugin-test-time": "^1.0|^2.0", "spatie/ray": "^1.37" }, diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index a68c571..00ba796 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -40,3 +40,32 @@ ->and($post->getPublisherColumns())->toBe(['id' => $post::PUBLISHER_ID, 'type' => $post::PUBLISHER_TYPE]) ->and($post->getQualifiedPublisherColumns())->toBe($post->qualifyColumns(['id' => $post::PUBLISHER_ID, 'type' => $post::PUBLISHER_TYPE])); }); + +it('honors column name overrides', function () { + + $post = OverridePost::make([ + + ]); + invade($post)->newRevision(); + + expect($post->getPublishedAtColumn())->toBe('published_at_override') + ->and($post->getIsPublishedColumn())->toBe('is_published_override') + ->and($post->getIsCurrentColumn())->toBe('is_current_override') + ->and($post->getUuidColumn())->toBe('uuid_override') + ->and($post->getPublisherColumns())->toBe(['id' => 'publisher_override_id', 'type' => 'publisher_override_type']); +}); + +class OverridePost extends \Illuminate\Database\Eloquent\Model +{ + use \Oddvalue\LaravelDrafts\Concerns\HasDrafts; + use \Illuminate\Database\Eloquent\SoftDeletes; + + public const PUBLISHED_AT = 'published_at_override'; + public const IS_PUBLISHED = 'is_published_override'; + public const IS_CURRENT = 'is_current_override'; + public const UUID = 'uuid_override'; + public const PUBLISHER_ID = 'publisher_override_id'; + public const PUBLISHER_TYPE = 'publisher_override_type'; + + protected $guarded = []; +}