laracasts / TestDummy

Easy factories for PHP integration testing.
https://laracasts.com/lessons/whats-new-in-testdummy
MIT License
455 stars 80 forks source link

Call to undefined method User::fill() #106

Closed ottersfish closed 9 years ago

ottersfish commented 9 years ago

I am trying to do unit test (if I have the correct understanding) with testDummy, it supposed to return an object from Eloquent model, in this case called user, but instead it showed this error message

Fatal error: Call to undefined method User::fill() in C:\xampp\htdocs\filehosting\vendor\laracasts\t
estdummy\src\EloquentModel.php on line 60

this is my factories.php file:

<?php

    $factory('User', [
        'id' => $faker->randomNumber,
        'email' => $faker->email,
        'username' => $faker->userName,
        'password' => $faker->password,
        'name' => $faker->name,
        'is_admin' => FALSE
    ]);

    $factory('User', 'admin_user', [
        'id' => $faker->randomNumber,
        'email' => $faker->email,
        'username' => $faker->userName,
        'password' => $faker->password,
        'name' => $faker->name,
        'is_admin' => TRUE
    ]);

?>

and I'm calling the testDummy like this:

$user = Factory::create('User');

Thanks in advance, and sorry if this issue is off topic, I'm still new to this community. :)

ddelnano commented 9 years ago

Why do you have the User factory defined twice? You are supposed to make one factory for each model. Also are your models namespaced? If so you need to include that in the first argument like so

$factory('App\User', [
//properties
];
ottersfish commented 9 years ago

Thanks for the reply! Sorry I forget to say that I am using Laravel 4. It is twice because the other one I need for making specific type of user. Anyway after I retry using it again suddenly it works :) maybe I did it wrong inside my test class.