PHP code example of cristiangiordano / nova-test-assertions

1. Go to this page and download the library: Download cristiangiordano/nova-test-assertions library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cristiangiordano / nova-test-assertions example snippets




namespace Tests;

use Illuminate\Foundation\Testing\TestResponse as BaseTestResponse;
use NovaTestHelpers\NovaTestAssertions;

class TestResponse extends BaseTestResponse
{
    use NovaTestAssertions;
}

    protected function createTestResponse($response)
    {
        return TestResponse::fromBaseResponse($response);
    }

use NovaTestHelpers\NovaEndpointAware;

class ManageAdminsTest extends TestCase
{
    use NovaEndpointAware;

    public function resource(): string
    {
        return 'admins';
    }
}

 /** @test */
function viewing_a_list_of_admin_resources()
{
    $admin = factory(User::class)->state(UserRole::ADMIN)->create();
    $user  = factory(User::class)->state(UserRole::USER)->create();

    $response = $this->json('GET', $this->endpoint());

    $response->assertOk();
    $response->assertNovaCollectionLabel('Admins');
    $response->assertNovaCollectionHas($admin);
    $response->assertNovaCollectionMissing($user);
    $response->assertNovaTextField('fullname', $admin->fullname, true);
    $response->assertNovaTextField('email', $admin->email, false);
    $response->assertNovaFieldCount(2);
}