vendredi 13 octobre 2017

Lumen: cannot inject UrlGenerator during testing

I'm trying to unit test a piece of code that uses the UrlGenerator. In my application code I have this:

$urlGenerator = app('url');

And in my PHPUnit test I do this:

app()->instance('url', $this->urlGeneratorMock);

If I use the following code in the real implementation:

$urlGenerator = app('url2');

And this one in my test:

app()->instance('url2', $this->urlGeneratorMock);

Then it works and my test passes. But then the actual code does not work anymore, of course. I've also tried using 'Laravel\Lumen\Routing\UrlGenerator' instead of 'url', and all other UrlGenerator related class names as well.

I'm using Lumen 5.5. Any help is greatly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire