Skip to content

Conversation

@Patabugen
Copy link

@Patabugen Patabugen commented Jan 26, 2026

Description

The assertion methods listed below allow passing either an Eloquent Record or the the row index as the $record parameter.

The functionality works - but the phpunit messages use $record->getKey() which mean the assertions fail when used with an index instead of an Eloquent Record causing an error.

  • assertTableColumnStateSet
  • assertTableColumnStateNotSet
  • assertTableColumnFormattedStateSet
  • assertTableColumnFormattedStateNotSet
  • assertTableColumnHasExtraAttributes
  • assertTableColumnDoesNotHaveExtraAttributes
  • assertTableColumnHasDescription
  • assertTableColumnDoesNotHaveDescription
  • assertTableSelectColumnHasOptions
  • assertTableSelectColumnDoesNotHaveOptions

Visual changes

None

Functional changes

  • Added assertTableRecordKeyExists to give a friendly error if an invalid index is passed
  • Updated other assertions to use the passed $record as the $key if it is not an Eloquent Model
  • Added a CustomDataTable fixture (based on the existing `PostsTable)

Workaround

In case anyone else needs a workaround before this is merged:

Add this to your TestCase:

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
    /**
     * Workaround for this bug: https://github.com/filamentphp/filament/pull/19092
     */
    protected function workaroundFilamentBug(\Closure $closure)
    {
        try {
            $closure();
        } catch(\Error $e) {
            if ($e->getMessage() !== "Call to a member function getKey() on array") {
                throw $e;
            }
        }
    }
}

And use it like this:

$page = Livewire::test(MyPage::class);
$this->workaroundFilamentBug(fn() => $page->assertTableColumnStateSet('column_name', 3, 1));

@danharrin danharrin added enhancement New feature or request pending review labels Jan 27, 2026
@danharrin danharrin added this to the v4 milestone Jan 27, 2026
@Patabugen
Copy link
Author

@danharrin Do I need to make another PR to apply this to Filament v5?

@danharrin
Copy link
Member

No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pending review

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants