From cb8ab7240b5a0eecf5c6b03f065228d6e11d2a3a Mon Sep 17 00:00:00 2001 From: Scot Rumery Date: Sun, 21 Jul 2024 09:41:20 -0600 Subject: [PATCH 1/4] Update for Laravel v11 Support --- composer.json | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 424ad0d..05070ba 100644 --- a/composer.json +++ b/composer.json @@ -17,19 +17,19 @@ } ], "require": { - "php": "^8.1", - "spatie/laravel-package-tools": "^1.14.0", - "illuminate/contracts": "^10.0" + "php": "^8.2", + "spatie/laravel-package-tools": "^1.16", + "illuminate/contracts": "^10.0||^11.0" }, "require-dev": { - "laravel/pint": "^1.0", - "nunomaduro/collision": "^7.9", - "nunomaduro/larastan": "^2.0.1", - "orchestra/testbench": "^8.0", + "laravel/pint": "^1.14", + "nunomaduro/collision": "^8.0||^7.10", + "larastan/larastan": "^2.9", + "orchestra/testbench": "^9.0.0||^8.22.0", "phpstan/extension-installer": "^1.1", "phpstan/phpstan-deprecation-rules": "^1.0", - "phpstan/phpstan-phpunit": "^1.0", - "phpunit/phpunit": "^10.2" + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^11.0.1" }, "autoload": { "psr-4": { From f00f6f1b8373fc7c1d91f346637dfbb1103fb63e Mon Sep 17 00:00:00 2001 From: Scot Rumery Date: Sun, 21 Jul 2024 09:41:46 -0600 Subject: [PATCH 2/4] Update for laatest PHPUnit version --- tests/LaravelNotesServiceProviderTest.php | 3 +-- tests/NoteTest.php | 20 +++++--------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/tests/LaravelNotesServiceProviderTest.php b/tests/LaravelNotesServiceProviderTest.php index f083655..2801fa4 100644 --- a/tests/LaravelNotesServiceProviderTest.php +++ b/tests/LaravelNotesServiceProviderTest.php @@ -43,8 +43,7 @@ public function tearDown(): void | ----------------------------------------------------------------- */ - /** @test */ - public function it_can_be_instantiated(): void + public function test_it_can_be_instantiated(): void { $expectations = [ \Illuminate\Support\ServiceProvider::class, diff --git a/tests/NoteTest.php b/tests/NoteTest.php index 7f66d8e..50f72a0 100644 --- a/tests/NoteTest.php +++ b/tests/NoteTest.php @@ -17,8 +17,7 @@ class NoteTest extends TestCase | ----------------------------------------------------------------- */ - /** @test */ - public function it_can_create_a_note(): void + public function test_it_can_create_a_note(): void { $post = $this->createPost(); @@ -33,8 +32,7 @@ public function it_can_create_a_note(): void static::assertNull($post->note->author); } - /** @test */ - public function it_should_create_single_note_for_has_one_note_trait(): void + public function test_it_should_create_single_note_for_has_one_note_trait(): void { $post = $this->createPost(); @@ -59,8 +57,7 @@ public function it_should_create_single_note_for_has_one_note_trait(): void static::assertCount(1, Note::all()); } - /** @test */ - public function it_can_create_with_author(): void + public function test_it_can_create_with_author(): void { $user = $this->createUser(); $post = $this->createPost(); @@ -77,8 +74,7 @@ public function it_can_create_with_author(): void static::assertEquals($user->id, $post->note->author->id); } - /** @test */ - public function it_can_update_note(): void + public function test_it_can_update_note(): void { $post = $this->createPost(); @@ -103,8 +99,7 @@ public function it_can_update_note(): void static::assertCount(1, Note::all()); } - /** @test */ - public function it_can_reverse_relation(): void + public function test_it_can_reverse_relation(): void { $post = $this->createPost(); @@ -122,7 +117,6 @@ public function it_can_reverse_relation(): void | ----------------------------------------------------------------- */ - /** @test */ public function it_can_add_note(): void { $user = $this->createUser(); @@ -135,7 +129,6 @@ public function it_can_add_note(): void static::assertNull($note->author); } - /** @test */ public function it_can_add_note_without_get_current_author_id_method(): void { $user = $this->createUserWithAuthorId(); @@ -148,7 +141,6 @@ public function it_can_add_note_without_get_current_author_id_method(): void static::assertSame($user->id, $note->author->id); } - /** @test */ public function it_can_find_note_by_its_id(): void { $user = $this->createUser(); @@ -159,7 +151,6 @@ public function it_can_find_note_by_its_id(): void static::assertSame($note->id, $created->id); } - /** @test */ public function it_can_retrieve_authored_notes(): void { $user = $this->createUser(); @@ -174,7 +165,6 @@ public function it_can_retrieve_authored_notes(): void static::assertCount(2, $user->authoredNotes()->get()); } - /** @test */ public function it_must_retrieve_authored_notes_foreach_owner(): void { $userOne = $this->createUserWithAuthorId(); From d971556d5d9e39babb44b6d7397d2185b74e1c76 Mon Sep 17 00:00:00 2001 From: Scot Rumery Date: Sun, 21 Jul 2024 09:53:24 -0600 Subject: [PATCH 3/4] Update GitHub Workflows --- .../workflows/fix-php-code-style-issues.yml | 7 ++++--- .github/workflows/phpstan.yml | 8 ++++--- .github/workflows/run-tests.yml | 21 ++++++++++++------- .github/workflows/update-changelog.yml | 5 +++-- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml index 7520a18..56d54d3 100644 --- a/.github/workflows/fix-php-code-style-issues.yml +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -11,17 +11,18 @@ permissions: jobs: php-code-styling: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.head_ref }} - name: Fix PHP code style issues - uses: aglipanci/laravel-pint-action@2.3.0 + uses: aglipanci/laravel-pint-action@2.4 - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: commit_message: Fix styling diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 9d41c0c..d5db2f1 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -5,22 +5,24 @@ on: paths: - '**.php' - 'phpstan.neon.dist' + - '.github/workflows/phpstan.yml' jobs: phpstan: name: phpstan runs-on: ubuntu-latest + timeout-minutes: 5 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.1' + php-version: '8.2' coverage: none - name: Install composer dependencies - uses: ramsey/composer-install@v2 + uses: ramsey/composer-install@v3 - name: Run PHPStan run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index fc06010..0e5811c 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -2,21 +2,28 @@ name: run-tests on: push: - branches: [main] - pull_request: - branches: [main] + paths: + - '**.php' + - '.github/workflows/run-tests.yml' + - 'phpunit.xml.dist' + - 'composer.json' + - 'composer.lock' jobs: test: runs-on: ${{ matrix.os }} + timeout-minutes: 5 strategy: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.2, 8.1] - laravel: [10.*] + php: [8.3, 8.2] + laravel: [11.*, 10.*] stability: [prefer-lowest, prefer-stable] include: + - laravel: 11.* + testbench: 9.* + carbon: ^2.63 - laravel: 10.* testbench: 8.* carbon: ^2.63 @@ -25,14 +32,14 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - 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: pcov + coverage: none - name: Setup problem matchers run: | diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml index 8c12ba9..39de30d 100644 --- a/.github/workflows/update-changelog.yml +++ b/.github/workflows/update-changelog.yml @@ -10,10 +10,11 @@ permissions: jobs: update: runs-on: ubuntu-latest + timeout-minutes: 5 steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: main @@ -24,7 +25,7 @@ jobs: release-notes: ${{ github.event.release.body }} - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 + uses: stefanzweifel/git-auto-commit-action@v5 with: branch: main commit_message: Update CHANGELOG From 1f4e3636550142551325bbe8107443e0ff186536 Mon Sep 17 00:00:00 2001 From: scotrumery Date: Sun, 21 Jul 2024 15:53:44 +0000 Subject: [PATCH 4/4] Fix styling --- src/Models/Note.php | 18 +++++++++--------- src/Traits/HasManyNotes.php | 2 +- src/Traits/HasOneNote.php | 4 ++-- tests/Stubs/Models/User.php | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Models/Note.php b/src/Models/Note.php index 3a5b3db..4a17e84 100644 --- a/src/Models/Note.php +++ b/src/Models/Note.php @@ -9,15 +9,15 @@ /** * Class Note * - * @property int $id - * @property string $content - * @property int $noteable_id - * @property string $noteable_type - * @property int $author_id - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property \Illuminate\Database\Eloquent\Model $author - * @property \Illuminate\Database\Eloquent\Model $noteable + * @property int $id + * @property string $content + * @property int $noteable_id + * @property string $noteable_type + * @property int $author_id + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property \Illuminate\Database\Eloquent\Model $author + * @property \Illuminate\Database\Eloquent\Model $noteable */ class Note extends Model { diff --git a/src/Traits/HasManyNotes.php b/src/Traits/HasManyNotes.php index 7e62a1c..ee89992 100644 --- a/src/Traits/HasManyNotes.php +++ b/src/Traits/HasManyNotes.php @@ -69,7 +69,7 @@ public function findNote($id) * @param string $content * @return array */ - protected function prepareNoteAttributes($content, Model $author = null) + protected function prepareNoteAttributes($content, ?Model $author = null) { return [ 'author_id' => is_null($author) ? $this->getCurrentAuthorId() : $author->getKey(), diff --git a/src/Traits/HasOneNote.php b/src/Traits/HasOneNote.php index 475e923..32eb4f1 100644 --- a/src/Traits/HasOneNote.php +++ b/src/Traits/HasOneNote.php @@ -64,7 +64,7 @@ public function createNote($content, $author = null, $reload = true) * @param bool $reload * @return bool */ - public function updateNote($content, Model $author = null, $reload = true) + public function updateNote($content, ?Model $author = null, $reload = true) { $updated = $this->note->update( $this->prepareNoteAttributes($content, $author) @@ -88,7 +88,7 @@ public function updateNote($content, Model $author = null, $reload = true) * @param string $content * @return array */ - protected function prepareNoteAttributes($content, Model $author = null) + protected function prepareNoteAttributes($content, ?Model $author = null) { return [ 'author_id' => is_null($author) ? $this->getCurrentAuthorId() : $author->getKey(), diff --git a/tests/Stubs/Models/User.php b/tests/Stubs/Models/User.php index 5784be8..8bcdfdd 100644 --- a/tests/Stubs/Models/User.php +++ b/tests/Stubs/Models/User.php @@ -16,6 +16,7 @@ */ class User extends Model { + use AuthoredNotes; /* ----------------------------------------------------------------- | Traits | ----------------------------------------------------------------- @@ -23,7 +24,6 @@ class User extends Model use HasFactory; use HasManyNotes; - use AuthoredNotes; /* ----------------------------------------------------------------- | Properties