View on GitHub

NovaUnit

Unit testing suite for Laravel Nova, built to extend PHPUnit

Filters

Testing Filters

To create the testing object for a Nova Filter, add the NovaFilterTest trait to your class, and invoke the test method.

class TestClass extends TestCase
{
    use NovaFilterTest;

    public function testNovaFilter()
    {
        $filter = $this->novaFilter(MyFilter::class);
    }
}

The following assertions can be run on the Nova Filter:

assertSelectFilter()

$filter->assertSelectFilter();

Assert that the filter is a Select Filter

assertBooleanFilter()

$filter->assertBooleanFilter();

Assert that the filter is a Boolean Filter

assertDateFilter()

$filter->assertDateFilter();

Assert that the filter is a Date Filter

assertHasOption($option)

$filter->assertHasOption('is_admin');

Assert that the filter has an option with a key or value that matches $option

assertOptionMissing($option)

$filter->assertOptionMissing('is_admin');

Assert that the filter does not have an option with a key or value that matches $option

Testing Applying Filter

$response = $filter->apply(User::class, 'is_admin');

Invokes the apply method on the filter with the given parameters.

assertContains($element)

$response->assertContains(User::find(1));

Assert that $element is returned when this filter is applied

assertMissing($element)

$response->assertMissing(User::find(1));

Assert that $element is not returned when this filter is applied

assertCount($count)

$response->assertCount(3);

Assert that a specific number of records are returned when this filter is applied

Testing Filters on Components

Filter assertions can be run on the following Nova classes:

assertHasFilter($filter)

$component->assertHasFilter(MyFilter::class);

Asserts that the provided class path $filter matches one of the filters returned by the filters() method

assertFilterMissing($filter)

$component->assertFilterMissing(MyFilter::class);

Asserts that the provided class path $filter does not match any filters returned by the filters() method

assertHasNoFilters()

$component->assertHasNoFilters();

Asserts that the filters() method returns an empty array.

assertHasValidFilters()

$component->assertHasValidFilters();

Asserts that all values returned by the filters() method are valid Nova Filters.