i trying write class read routes given constructor it's constructed with. however, after 1h of googling didn't find how access getrouter
method of laravel controller - because it's static function. i've tried many things of time got following error:
uncaught error: using $this when not in object context in
vendor/phpspec/prophecy/src/prophecy/doubler/generator/classcreator.php(49) :
eval()'d code:13
stack trace: #0 [internal function]: double\illuminate\routing\controller\p4::getrouter()
how can achieve or not possible phpspec?
my spec:
use illuminate\routing\controller; use phpspec\objectbehavior; use prophecy\argument; class optiondescriberspec extends objectbehavior { function let(controller $controller) { $this->beconstructedwith($controller); } function it_should_read_the_aviable_routes_of_the_controller() { $this->getcontroller()->getrouter()->shouldreturn('router'); $this->render()->shouldreturn('router'); } }
my class:
use illuminate\routing\controller; class optiondescriber { /** * @var controller */ protected $controller; /** * optiondescriber constructor. * * @param controller $controller */ public function __construct(controller $controller) { $this->controller = $controller; } public function render() { return $this->controller->getrouter(); } }
function it_should_read_the_aviable_routes_of_the_controller(controller $controller, router $router) { $this->getcontroller()->willreturn($controller); $controller->getrouter()->willreturn($router); $this->render()->shouldreturn($router); }
alltough it's not recommended spec controllers. make controller thin possible , move 'meat' service used controller.
Comments
Post a Comment