Support the ongoing development of Laravel.io →
Database Eloquent Testing
Last updated 1 year ago.
0

Your repository isn't resolving the dependency out of the IoC container.

public function __construct(){
        $this->source = new \Oclify\Models\Dna\Source;
}

$this->source is now equal to a brand new instance of Oclify\Models\Dna\Source, at this point the repository has no idea about your mock because you haven't resolved the dependency, laravel does not hook into requests for a new instance of a class.

The instance method on app allows you bind an instance into the container, you'll need to then use the IoC container to retrieve that object, you could either use dependency resolution through the constructor, like so:

public function __construct(Oclify\Models\Dna\Source $source)
{
        $this->source = $source;
}

or through make:

public function __construct()
{
        $this->source = App::make('Oclify\Models\Dna\Source');
}

http://laravel.com/docs/ioc#automatic-resolution

Last updated 1 year ago.
0

hmm, okay thanks citric, imma try that

Last updated 1 year ago.
0

that sucks, okay so basically I have to do this?

App::bind("Oclify\Repos\Dna\SourceRepo",function(){
	return new Oclify\Repos\Dna\SourceRepoEloquent(new Oclify\Models\Dna\Source);
});

along with the update to the __constructor method. This is the proper way to do it right? there was no other way?

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.