I've created a simple User Repository class in Laravel that will handle all CRUD functionalities.
Everything works fine, but when I try to unit test it with phpunit, it all breaks apart.
I'm running the latest development version of Laravel, I understand this isn't a stable release but I'm confused whether this is a laravel bug or am I doing something wrong.
When running phpunit, I get this huge error output.
The classes I have are
Model Role
namespace Shazzam\Models;
use Illuminate\Database\Eloquent\Model;
class Role extends Model {
protected $fillable = ['name'];
}
Role Repository
namespace Shazzam\Repositories;
use \Shazzam\Models\Role;
class RoleRepository
{
/**
* @param array $args
* @return bool
*/
public function create($args)
{
$role = new Role($args);
return $role->save();
}
}
RoleRepository Test
use Shazzam\Repositories\RoleRepository;
class RoleRepositoryTest extends TestCase
{
public $repo;
public function setUp()
{
$this->repo = new RoleRepository;
}
public function test_it_creates_a_new_role()
{
$role['name'] = "NewRole";
$this->assertTrue($this->repo->create($role));
}
}
Please let me know if you see that I'm doing anything wrong. I'd really like to keep working on the dev version of Laravel. Thanks.
Edit 1- Removed array typehint in the RoleRepository create method. Updated Title
You should call the base class setUp method:
public function setUp() {
parent::setUp();