mercredi 5 juin 2019

How can I change the app url for unit testing?

I have a function which requires the url to be able to work. I am trying to unit test it as its behaviour changes depending on the url query parameters.

MyServiceTest.php

function testMyTestFunction() {
    $service = new MyService();

    // Some how change the url for the app. This doesn't work
    config(['app.url' => 'http://test.test?myNewParam=5']);

    $service->test();
}

MyService.php

function test() {
    // Does not contain `myNewParam`
    $url = url()->full();

    // do some logic
}

I've also tried mocking the request as that's what the url() helper function references but I've had no luck in doing this successfully.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire