I'm starting with PHP Unit and I'm trying to build a Mock for an Eloquent Model which is required as a dependency in the __construct method for the class to test.
This is the constructor for my class I want to test:
namespace App\Repository\Link;
use App\Repository\RepositoryAbstract;
use Illuminate\Database\Eloquent\Model;
class EloquentLink extends RepositoryAbstract implements LinkInterface
{
protected $link;
public function __construct(Model $link)
{
$this->link = $link;
}
}
My test class looks like this:
namespace App\Repository\Link;
use Link as ModelLink; //Link is the Eloquent model to pass as constructor for EloquentLink
use Illuminate\Database\Eloquent\Model as Eloquent; //Link extends Eloquent
class EloquentLinkTest extends \PHPUnit_Framework_TestCase
{
protected $modelMock;
protected $link;
public function setUp() {
$this->modelMock = $this->getMockBuilder('ModelLink')->getMock();
$this->link = new EloquentLink($this->modelMock);
}
public function testCase()
{
//comes here
}
}
I get this error:
1) App\Repository\Link\EloquentLinkTest::testCase Argument 1 passed to App\Repository\Link\EloquentLink::__construct() must be an instance of Illuminate\Database\Eloquent\Model, instance of Mock_ModelLink_ea1343ff given
How can I make the mock extend the Model class?