SarahS's avatar
Level 12

Create problem in test

I'm setting up tests to start adding recording activity in my app (like I the Birdboard course). I have this function:

function creating_a_client_generates_activity()
{   
    $client = factory('App\Client')->create();
    
    $this->assertCount(1, $client->activity); 
}

But when I run it I get:

  1. Tests\Feature\ActivityFeedTest::creating_a_client_generates_activity TypeError: Argument 1 passed to Illuminate\Database\Eloquent\Builder::create() must be of the type array, object given,

I'm assuming it is the way I have tried to create the client but I don't know how to fix it.

0 likes
2 replies
tykus's avatar

What does the ClientFactory look like?

SarahS's avatar
Level 12
/* @var $factory \Illuminate\Database\Eloquent\Factory */

use App\Client;
use Faker\Generator as Faker;

$factory->define(Client::class, function (Faker $faker) {
    return [
        'user_id' => factory(\App\User::class),
        'forename' => $faker->firstName,
        'surname' => $faker->lastName,
        'email' => $faker->unique()->safeEmail,
    ];
});

Please or to participate in this conversation.