I am trying to test the following bit of code:
DimonaClient is just a simple wrapper around a Laravel HttpClient; simplified function here:
The getDeclaration()
response is a \Illuminate\Http\Client\Response
What I am trying to do in my test is:
My test code looks like this:
My issue(s) seem to be:
I feel like I'm one small step away from making this work, but going round in circles trying to hook it up correctly.
TIA!
If you are using Http
Facade, you don't need to mock DimonaCient
. You are nearly there with your test, but let me show you what you would have done:
/** @test */
public function it_can_handle_an_approved_submission(): void
{
Http::fake([
'*' => Http::response([
'declarationStatus' => [
'result' => DimonaDeclarationStatus::ACCEPTED,
'dimonaPeriodId' => $this->faker->numerify('############'),
],
],
]);
$dimonaDeclarationId = $this->faker->numerify('############');
// Do your normal call, and then assertions
}
Doing this, you will tell Http
to fake any URL, because we are using *
. I would recommend you use $this->endpoint/$declarationId
so if it does not match, you will also know you did not hit the right endpoint.
I am not sure what Laravel you are using but this is available since Laravel 6+, check Http
fake URLs.