Skip to content

Laravel 12 and Nova 5 support #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

steps:
- name: 📚 Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: 🔥 Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
php-version: 8.4
coverage: none
tools: cs2pr, pint

Expand Down
22 changes: 9 additions & 13 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,21 @@ on:

jobs:
test:
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
os: [ ubuntu-latest ]
php: [ 8.2, 8.3 ]
laravel: [ "^10.0", "^11.0" ]
php: [ 8.2, 8.3, 8.4 ]
laravel: [ "^11.0", "^12.0" ]
stability: [ prefer-lowest, prefer-stable ]
include:
- laravel: "^10.0"
testbench: "^8.0"
enum: "^6.0"
- laravel: "^11.0"
testbench: "^9.0"
enum: "^6.0"
nova: "^4.0"
- laravel: "^12.0"
nova: "^5.0"

name: P${{ matrix.php }} - L${{ matrix.laravel }} - E${{ matrix.enum }} - ${{ matrix.stability }} - ${{ matrix.os }}
name: P${{ matrix.php }} - L${{ matrix.laravel }} - N${{ matrix.nova }} - ${{ matrix.stability }}

services:
mysql:
Expand All @@ -41,13 +38,12 @@ 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: bcmath, curl, dom, fileinfo, intl, libxml, mbstring, pcntl, pdo, sqlite, zip
coverage: none

- name: 🔎 Setup problem matchers
Expand All @@ -58,7 +54,7 @@ jobs:
- name: 📦 Install Composer dependencies
run: |
composer config "http-basic.nova.laravel.com" "${{ secrets.NOVA_USERNAME }}" "${{ secrets.NOVA_PASSWORD }}"
composer require "illuminate/support:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "bensampo/laravel-enum:${{ matrix.enum }}" --no-interaction --no-update
composer require "illuminate/support:${{ matrix.laravel }}" "laravel/nova:${{ matrix.nova }}" "bensampo/laravel-enum:^6.0" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-ansi --no-scripts --no-progress

- name: 🧪 Run test suite
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
],
"homepage": "https://github.com/simplesquid/nova-enum-field",
"require": {
"php": "^8.1",
"php": "^8.2",
"bensampo/laravel-enum": "^5.0 || ^6.0",
"illuminate/support": "^10.0 || ^11.0",
"laravel/nova": "^4.0"
"illuminate/support": "^11.0 || ^12.0",
"laravel/nova": "^4.0 || ^5.0"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.44",
"laravel/pint": "^1.2",
"mockery/mockery": "^1.3.3",
"nunomaduro/collision": "^7.0 || ^8.0",
"orchestra/testbench": "^8.0 || ^9.0",
"phpunit/phpunit": "^10.1",
"quotevelocity/novaunit": "^4.0",
"symfony/var-dumper": "^6.0 || ^7.0"
"ergebnis/composer-normalize": "^2.0",
"laravel/pint": "^1.13",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"orchestra/testbench": "^9.0 || ^10.0",
"phpunit/phpunit": "^11.5.3",
"quotevelocity/novaunit": "^4.0 || ^5.0",
"symfony/var-dumper": "^7.0"
},
"repositories": [
{
Expand Down
11 changes: 6 additions & 5 deletions tests/Fields/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BenSampo\Enum\Rules\EnumValue;
use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\Enum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase;
Expand All @@ -21,7 +22,7 @@ protected function setUp(): void
$this->field = Enum::make('Enum')->attach(IntegerEnum::class);
}

/** @test */
#[Test]
public function it_starts_with_no_options_and_rules()
{
$field = Enum::make('Enum');
Expand All @@ -31,30 +32,30 @@ public function it_starts_with_no_options_and_rules()
$this->assertEmpty($field->rules);
}

/** @test */
#[Test]
public function it_allows_an_enum_to_be_attached()
{
$this->assertIsObject($this->field);
$this->assertTrue(property_exists($this->field, 'optionsCallback'));
}

/** @test */
#[Test]
public function it_adds_correct_rules()
{
$this->assertContains('required', $this->field->rules);

$this->assertContainsEquals(new EnumValue(IntegerEnum::class, false), $this->field->rules);
}

/** @test */
#[Test]
public function it_displays_enum_options()
{
$this->assertCount(count(IntegerEnum::getValues()), $this->field->optionsCallback);

$this->assertSame(IntegerEnum::asSelectArray(), $this->field->optionsCallback);
}

/** @test */
#[Test]
public function it_can_be_nullable()
{
$this->field->nullable();
Expand Down
13 changes: 7 additions & 6 deletions tests/Fields/FlaggedFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields;

use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\FlaggedEnum as FlaggedEnumField;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\FlaggedEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\FlaggedModel;
Expand Down Expand Up @@ -31,27 +32,27 @@ protected function setUp(): void
$this->model = FlaggedModel::create(['enum' => FlaggedEnum::None]);
}

/** @test */
#[Test]
public function it_starts_with_no_options()
{
$field = FlaggedEnumField::make('Enum');

$this->assertEmpty($field->options);
}

/** @test */
#[Test]
public function it_allows_an_enum_to_be_attached()
{
$this->assertNotEmpty($this->field->options);
}

/** @test */
#[Test]
public function it_has_no_value_text()
{
$this->assertSame('None', $this->field->noValueText);
}

/** @test */
#[Test]
public function it_displays_enum_options()
{
$this->assertCount(count(FlaggedEnum::getValues()) - 1, $this->field->options);
Expand All @@ -68,7 +69,7 @@ public function it_displays_enum_options()
}
}

/** @test */
#[Test]
public function it_resolves_enum_values()
{
$this->field->resolve($this->model);
Expand All @@ -90,7 +91,7 @@ public function it_resolves_enum_values()
}
}

/** @test */
#[Test]
public function it_fills_database_with_flagged_enum_value()
{
$request = new NovaRequest;
Expand Down
7 changes: 4 additions & 3 deletions tests/Fields/IntegerFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields;

use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\Enum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerModel;
Expand All @@ -25,23 +26,23 @@ protected function setUp(): void
$this->model = IntegerModel::create(['enum' => IntegerEnum::Moderator]);
}

/** @test */
#[Test]
public function it_resolves_enum_value()
{
$this->field->resolve($this->model);

$this->assertSame(IntegerEnum::Moderator, $this->field->value);
}

/** @test */
#[Test]
public function it_displays_enum_description()
{
$this->field->resolveForDisplay($this->model);

$this->assertSame(IntegerEnum::Moderator()->description, $this->field->displayedAs ?? $this->field->value);
}

/** @test */
#[Test]
public function it_fills_database_with_enum_value()
{
$request = new NovaRequest;
Expand Down
7 changes: 4 additions & 3 deletions tests/Fields/NoCastsFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields;

use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\Enum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\NoCastsModel;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\StringEnum;
Expand All @@ -25,23 +26,23 @@ protected function setUp(): void
$this->model = NoCastsModel::create(['enum' => StringEnum::Moderator]);
}

/** @test */
#[Test]
public function it_resolves_enum_value()
{
$this->field->resolve($this->model);

$this->assertSame(StringEnum::Moderator, $this->field->value);
}

/** @test */
#[Test]
public function it_displays_enum_description()
{
$this->field->resolveForDisplay($this->model);

$this->assertSame(StringEnum::Moderator, $this->field->value);
}

/** @test */
#[Test]
public function it_fills_database_with_enum_value()
{
$request = new NovaRequest;
Expand Down
7 changes: 4 additions & 3 deletions tests/Fields/StringFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SimpleSquid\Nova\Fields\Enum\Tests\Fields;

use Laravel\Nova\Http\Requests\NovaRequest;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\Enum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\StringEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\StringModel;
Expand All @@ -25,23 +26,23 @@ protected function setUp(): void
$this->model = StringModel::create(['enum' => StringEnum::Moderator]);
}

/** @test */
#[Test]
public function it_resolves_enum_value()
{
$this->field->resolve($this->model);

$this->assertSame(StringEnum::Moderator, $this->field->value);
}

/** @test */
#[Test]
public function it_displays_enum_description()
{
$this->field->resolveForDisplay($this->model);

$this->assertSame(StringEnum::Moderator()->description, $this->field->displayedAs ?? $this->field->value);
}

/** @test */
#[Test]
public function it_fills_database_with_enum_value()
{
$request = new NovaRequest;
Expand Down
11 changes: 6 additions & 5 deletions tests/Filters/BooleanFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace SimpleSquid\Nova\Fields\Enum\Tests\Filters;

use JoshGaber\NovaUnit\Filters\MockFilter;
use PHPUnit\Framework\Attributes\Test;
use SimpleSquid\Nova\Fields\Enum\EnumBooleanFilter;
use SimpleSquid\Nova\Fields\Enum\Tests\Examples\IntegerEnum;
use SimpleSquid\Nova\Fields\Enum\Tests\TestCase;
Expand All @@ -20,27 +21,27 @@ protected function setUp(): void
$this->mockFilter = new MockFilter($this->filter);
}

/** @test */
#[Test]
public function it_is_a_boolean_filter()
{
$this->mockFilter->assertBooleanFilter();
}

/** @test */
#[Test]
public function it_has_a_default_name()
{
$this->assertEquals('Enum', $this->filter->name());
}

/** @test */
#[Test]
public function it_can_have_a_different_name()
{
$this->assertInstanceOf(EnumBooleanFilter::class, $this->filter->name('Different name'));

$this->assertEquals('Different name', $this->filter->name());
}

/** @test */
#[Test]
public function it_accepts_optional_default_values()
{
$this->filter->default(IntegerEnum::Moderator);
Expand Down Expand Up @@ -71,7 +72,7 @@ public function it_accepts_optional_default_values()
], $this->filter->jsonSerialize()['currentValue']);
}

/** @test */
#[Test]
public function it_has_no_default_value_by_default()
{
$this->assertEquals([
Expand Down
Loading
Loading