Dependancy injection with PHPunit Laravel 5.1 -
the project has service/repository/contract framework i'm trying test phpunit
. dependency injection done via controller methods injecting repository contract (interface). using service providers injected contracts replace correct repository.
the problem need access these repositories within unit testing. such in roletest
class
funciton testsomething(\examplenamespace\users\contract\rolecontract $repo){ $service = new roleservice($repo); //do fun stuff $ret = $service->dosomething( ); }
however not work. error thrown saying instance in not correct empty string received instead.
i run.
funciton testsomething( ){ $repo = new \examplenamespace\users\repositories\roleeloquentrepository( ); $service = new roleservice($repo); //do fun stuff $ret = $service->dosomething( ); }
then defeat purpose of dependency inversion. how can make work?
Comments
Post a Comment