Skip to content

Commit

Permalink
Add support for Laravel Nova 4
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgaber committed Apr 6, 2022
1 parent 33124b4 commit a38f058
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down
8 changes: 4 additions & 4 deletions docs/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
24 changes: 20 additions & 4 deletions src/Actions/MockActionElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 6 additions & 6 deletions src/Traits/FieldAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

namespace JoshGaber\NovaUnit\Traits;

use Illuminate\Http\Request;
use JoshGaber\NovaUnit\Constraints\HasField;
use JoshGaber\NovaUnit\Constraints\HasValidFields;
use JoshGaber\NovaUnit\Fields\FieldHelper;
use JoshGaber\NovaUnit\Fields\FieldNotFoundException;
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;

Expand All @@ -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
);
Expand All @@ -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
);
Expand All @@ -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;
}
Expand All @@ -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())
Expand All @@ -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()
);
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/Actions/ActionInvalidFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/Actions/ActionInvalidFieldset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/Actions/ActionNoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixtures/Actions/ActionValidFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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'),
Expand Down

0 comments on commit a38f058

Please sign in to comment.