2
votes

Hello guys I created a package on laravel in my workbench, it work on my laravel project then i decided to write unit testing for it. I download php unit on the vendor of my package and mockery.

I set up my phpunit test file and when i'm going to mock the dependency of this model doing:

  public function setUp()
  {
     $model = Mockery::mock('Path/OfMy/Model');
     new MyRepository($model);
  }

when i run phpunit command it throw me an erorr:

PHP Fatal error: Class 'Illuminate\Database\Eloquent\Model' not found

This is how i set up my model

use Illuminate\Database\Eloquent\Model;

/**
* 
*/
class TableEloquent extends Model
{
    protected $table = "tables";
    protected $fillable = ['text','name'];

    public function relation()
    {
        return $this->hasOne('My\Name\Space\OtherModel','type_id');
    }
}

The weird thing is that i have another Model extending at same way the Model class, and it doesn't give problem.

If is not the model to give problem how can i figure out to this strange behavior?

1
Were you able to resolve this? I'm having a similar issue.J. LaRosee
Yes, I'll write the answer belowFabrizio Fenoglio
No problem, my pleasureFabrizio Fenoglio

1 Answers

1
votes

for fix this issue you just need to mock \Illuminate\Database\Eloquent\Model at the top of your setUp() method like so:

public function setUp()
{
   Mockery::mock('Illuminate\Database\Eloquent\Model');
   // your set up
}