From a38f058518ea82118b6d5c992abc24ef618b36a0 Mon Sep 17 00:00:00 2001 From: Josh Gaber Date: Wed, 6 Apr 2022 18:24:16 -0400 Subject: [PATCH] Add support for Laravel Nova 4 --- CHANGELOG.md | 4 ++++ README.md | 2 +- composer.json | 8 +++---- docs/actions.md | 8 +++---- src/Actions/MockActionElement.php | 24 +++++++++++++++---- src/Traits/FieldAssertions.php | 12 +++++----- .../Fixtures/Actions/ActionInvalidFields.php | 3 ++- .../Actions/ActionInvalidFieldset.php | 3 ++- tests/Fixtures/Actions/ActionNoFields.php | 3 ++- tests/Fixtures/Actions/ActionValidFields.php | 3 ++- 10 files changed, 47 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acef841..386a620 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to NovaUnit will be documented in this file. +## 3.0 + +- Compatibility with Laravel Nova 4 + ## 2.3 - Compatibility with Laravel 9 diff --git a/README.md b/README.md index 6e5f5db..5fa771c 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ composer require --dev joshgaber/novaunit * PHP 7.3 or higher * [Laravel](https://laravel.com/) 6.x - 9.x -* [Laravel Nova](https://nova.laravel.com/) 2.x - 3.x +* [Laravel Nova](https://nova.laravel.com/) 2.x - 4.x * [PHPUnit](https://github.com/sebastianbergmann/phpunit) 8.5.x - 9.x ## Usage diff --git a/composer.json b/composer.json index f849c7a..0cf79bc 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "joshgaber/novaunit", "description": "Unit testing suite for Laravel Nova, built to extend PHPUnit", - "version": "2.3", + "version": "3.0", "keywords": [ "laravel", "nova", @@ -20,11 +20,11 @@ } ], "require": { - "php": "^7.3 || ^8.0", + "php": "^8.0", "ext-mbstring": "*", "cakephp/chronos": ">=1.2.3", - "illuminate/support": "^8.0|^9.0", - "laravel/nova": "^3.0", + "illuminate/support": "^8.83.4|^9.3.1", + "laravel/nova": "^4.0", "phpunit/phpunit": "^9.0" }, "require-dev": { diff --git a/docs/actions.md b/docs/actions.md index 328bbb1..effceb9 100644 --- a/docs/actions.md +++ b/docs/actions.md @@ -187,18 +187,18 @@ $action->assertHiddenFromDetail(); Asserts that the action will be hidden from this component's detail view. -### `assertShownOnTableRow()` +### `assertShownInline()` ```php -$action->assertShownOnTableRow(); +$action->assertShownInline(); ``` Asserts that the action will be shown on this component's table row view. -### `assertHiddenFromTableRow()` +### `assertNotShownInline()` ```php -$action->assertHiddenFromTableRow(); +$action->assertNotShownInline(); ``` Asserts that the action will be hidden from this component's table row view. diff --git a/src/Actions/MockActionElement.php b/src/Actions/MockActionElement.php index 2041732..36de773 100644 --- a/src/Actions/MockActionElement.php +++ b/src/Actions/MockActionElement.php @@ -72,23 +72,39 @@ public function assertHiddenFromDetail(string $message = ''): self * @param string $message * @return $this */ - public function assertShownOnTableRow(string $message = ''): self + public function assertShownInline(string $message = ''): self { - PHPUnit::assertTrue($this->action->showOnTableRow, $message); + PHPUnit::assertTrue($this->action->showInline, $message); return $this; } + /** + * @deprecated + */ + public function assertShownOnTableRow(string $message = ''): self + { + return $this->assertShownInline($message); + } + /** * Assert that the action is hidden from table rows. * * @param string $message * @return $this */ - public function assertHiddenFromTableRow(string $message = ''): self + public function assertNotShownInline(string $message = ''): self { - PHPUnit::assertFalse($this->action->showOnTableRow, $message); + PHPUnit::assertFalse($this->action->showInline, $message); return $this; } + + /** + * @deprecated + */ + public function assertHiddenFromTableRow(string $message = ''): self + { + return $this->assertNotShownInline($message); + } } diff --git a/src/Traits/FieldAssertions.php b/src/Traits/FieldAssertions.php index e01ab3a..b4b2d9d 100644 --- a/src/Traits/FieldAssertions.php +++ b/src/Traits/FieldAssertions.php @@ -2,7 +2,6 @@ namespace JoshGaber\NovaUnit\Traits; -use Illuminate\Http\Request; use JoshGaber\NovaUnit\Constraints\HasField; use JoshGaber\NovaUnit\Constraints\HasValidFields; use JoshGaber\NovaUnit\Fields\FieldHelper; @@ -10,6 +9,7 @@ use JoshGaber\NovaUnit\Fields\MockFieldElement; use JoshGaber\NovaUnit\Lenses\MockLens; use JoshGaber\NovaUnit\Resources\MockResource; +use Laravel\Nova\Http\Requests\NovaRequest; use PHPUnit\Framework\Assert as PHPUnit; use PHPUnit\Framework\Constraint\IsType; @@ -25,7 +25,7 @@ trait FieldAssertions public function assertHasField(string $field, string $message = ''): self { PHPUnit::assertThat( - $this->component->fields(Request::createFromGlobals()), + $this->component->fields(NovaRequest::createFromGlobals()), new HasField($field, $this->allowPanels()), $message ); @@ -44,7 +44,7 @@ public function assertHasField(string $field, string $message = ''): self public function assertFieldMissing(string $field, string $message = ''): self { PHPUnit::assertThat( - $this->component->fields(Request::createFromGlobals()), + $this->component->fields(NovaRequest::createFromGlobals()), PHPUnit::logicalNot(new HasField($field, $this->allowPanels())), $message ); @@ -60,7 +60,7 @@ public function assertFieldMissing(string $field, string $message = ''): self */ public function assertHasNoFields(string $message = ''): self { - PHPUnit::assertCount(0, $this->component->fields(Request::createFromGlobals()), $message); + PHPUnit::assertCount(0, $this->component->fields(NovaRequest::createFromGlobals()), $message); return $this; } @@ -74,7 +74,7 @@ public function assertHasNoFields(string $message = ''): self public function assertHasValidFields(string $message = ''): self { PHPUnit::assertThat( - $this->component->fields(Request::createFromGlobals()), + $this->component->fields(NovaRequest::createFromGlobals()), PHPUnit::logicalAnd( new IsType(IsType::TYPE_ARRAY), new HasValidFields($this->allowPanels()) @@ -96,7 +96,7 @@ public function assertHasValidFields(string $message = ''): self public function field(string $fieldName): MockFieldElement { $field = FieldHelper::findField( - $this->component->fields(Request::createFromGlobals()), + $this->component->fields(NovaRequest::createFromGlobals()), $fieldName, $this->allowPanels() ); diff --git a/tests/Fixtures/Actions/ActionInvalidFields.php b/tests/Fixtures/Actions/ActionInvalidFields.php index d4a7c33..c8dc3c9 100644 --- a/tests/Fixtures/Actions/ActionInvalidFields.php +++ b/tests/Fixtures/Actions/ActionInvalidFields.php @@ -4,10 +4,11 @@ use Laravel\Nova\Actions\Action; use Laravel\Nova\Fields\Text; +use Laravel\Nova\Http\Requests\NovaRequest; class ActionInvalidFields extends Action { - public function fields() + public function fields(NovaRequest $request) { return [ Text::make('Alpha', 'field_alpha'), diff --git a/tests/Fixtures/Actions/ActionInvalidFieldset.php b/tests/Fixtures/Actions/ActionInvalidFieldset.php index fb4152a..69afc2d 100644 --- a/tests/Fixtures/Actions/ActionInvalidFieldset.php +++ b/tests/Fixtures/Actions/ActionInvalidFieldset.php @@ -3,10 +3,11 @@ namespace JoshGaber\NovaUnit\Tests\Fixtures\Actions; use Laravel\Nova\Actions\Action; +use Laravel\Nova\Http\Requests\NovaRequest; class ActionInvalidFieldset extends Action { - public function fields() + public function fields(NovaRequest $request) { return 'invalid'; } diff --git a/tests/Fixtures/Actions/ActionNoFields.php b/tests/Fixtures/Actions/ActionNoFields.php index c896a89..139f67c 100644 --- a/tests/Fixtures/Actions/ActionNoFields.php +++ b/tests/Fixtures/Actions/ActionNoFields.php @@ -3,10 +3,11 @@ namespace JoshGaber\NovaUnit\Tests\Fixtures\Actions; use Laravel\Nova\Actions\Action; +use Laravel\Nova\Http\Requests\NovaRequest; class ActionNoFields extends Action { - public function fields() + public function fields(NovaRequest $request) { return []; } diff --git a/tests/Fixtures/Actions/ActionValidFields.php b/tests/Fixtures/Actions/ActionValidFields.php index 8bf48b1..4dd172f 100644 --- a/tests/Fixtures/Actions/ActionValidFields.php +++ b/tests/Fixtures/Actions/ActionValidFields.php @@ -5,6 +5,7 @@ use Laravel\Nova\Actions\Action; use Laravel\Nova\Fields\Number; use Laravel\Nova\Fields\Text; +use Laravel\Nova\Http\Requests\NovaRequest; class ActionValidFields extends Action { @@ -13,7 +14,7 @@ public function handle() return Action::message('Test Message'); } - public function fields() + public function fields(NovaRequest $request) { return [ Text::make('Alpha', 'field_alpha'),