Skip to content

Instantly share code, notes, and snippets.

@jhm-ciberman
Last active February 15, 2024 02:37
Show Gist options
  • Select an option

  • Save jhm-ciberman/b6063c31a680b75fca55f7dcb37f66ae to your computer and use it in GitHub Desktop.

Select an option

Save jhm-ciberman/b6063c31a680b75fca55f7dcb37f66ae to your computer and use it in GitHub Desktop.

Revisions

  1. jhm-ciberman revised this gist Feb 15, 2024. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions NovaResourcesTest.php
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    namespace Tests\Feature;

    use Tests\TestCase;
    use Illuminate\Http\Request;
    use Laravel\Nova\Http\Requests\NovaRequest;
    use Laravel\Nova\Nova;

    class NovaResourcesTest extends TestCase
    @@ -14,6 +14,8 @@ public function testAllNovaResources()
    // It is meant for testing only basic syntax errors
    // Nova resource behaviours should be manually tested

    Nova::resourcesIn(app_path('Nova'));

    $resources = collect(Nova::$resources);

    $this->assertTrue($resources->count() > 0);
    @@ -41,7 +43,7 @@ private function executeTestFor($resourceClass)

    public function assertResourceMethod($resource, $methodName)
    {
    $request = new Request();
    $request = new NovaRequest();

    $array = $resource->{$methodName}($request);

  2. jhm-ciberman revised this gist Feb 15, 2024. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions NovaResourcesTest.php
    Original file line number Diff line number Diff line change
    @@ -3,11 +3,8 @@
    namespace Tests\Feature;

    use Tests\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Http\Request;
    use Laravel\Nova\Nova;
    use Laravel\Nova\Resource;

    class NovaResourcesTest extends TestCase
    {
    @@ -48,6 +45,6 @@ public function assertResourceMethod($resource, $methodName)

    $array = $resource->{$methodName}($request);

    $this->assertInternalType('array', $array);
    $this->assertIsArray($array);
    }
    }
    }
  3. jhm-ciberman created this gist Apr 28, 2019.
    53 changes: 53 additions & 0 deletions NovaResourcesTest.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,53 @@
    <?php

    namespace Tests\Feature;

    use Tests\TestCase;
    use Illuminate\Foundation\Testing\WithFaker;
    use Illuminate\Foundation\Testing\RefreshDatabase;
    use Illuminate\Http\Request;
    use Laravel\Nova\Nova;
    use Laravel\Nova\Resource;

    class NovaResourcesTest extends TestCase
    {
    public function testAllNovaResources()
    {
    // This test only instanciates one resource of each type
    // It is meant for testing only basic syntax errors
    // Nova resource behaviours should be manually tested

    $resources = collect(Nova::$resources);

    $this->assertTrue($resources->count() > 0);

    $resources->each(function($resourceClass) {
    $this->executeTestFor($resourceClass);
    });
    }

    private function executeTestFor($resourceClass)
    {
    // Asserts the model asociated to the nova resource can be instantiated
    $model = app($resourceClass::$model);
    $this->assertNotNull($model);

    // Instantiates the nova resource
    $resource = new $resourceClass($model);

    $this->assertResourceMethod($resource, 'fields');
    $this->assertResourceMethod($resource, 'cards');
    $this->assertResourceMethod($resource, 'filters');
    $this->assertResourceMethod($resource, 'lenses');
    $this->assertResourceMethod($resource, 'actions');
    }

    public function assertResourceMethod($resource, $methodName)
    {
    $request = new Request();

    $array = $resource->{$methodName}($request);

    $this->assertInternalType('array', $array);
    }
    }