I am trying to write a class which will read the routes given by the constructor it's constructed with. However, even after 1h of googling I didn't find anything how to access the getRouter
method of the Laravel Controller - because it's a static function. I've tried many things but most of the time I 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 I achieve this or is this just not possible with 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();
}
}
Aucun commentaire:
Enregistrer un commentaire