Hi,
I'm going trough Spatie's Laravel Testing course, and one of the chapters is covering Http::fake(). I'm trying to use the knowledge gained to implement testing in a small project of mine, but for some reason the Http::fake() is ignored. I'll try to explain what I've done;
- In the test I'm doing this:
it("shows content on the projects budget page", function () {
Http::fake([ "https://api.harvestapp.com/v2/projects" => Http::response(""),
]);
$this->get("/projects_budget")->assertSee("Kompetansebank");
});
-
The "/projects_budget" in my route is calling
[ProjectController::class, 'budget_index'] -
The
budget_indexfunction in ProjectController can be simplified to this:
$this->harvest = new HarvestController();
$projectList = $this->harvest->projects();
- And in HarvestController this is the
projectsfunction:
public function projects(): array
{
$response = Http::withToken($this->token)
->withHeader("Harvest-Account-Id", $this->account_id)
->get("https://api.harvestapp.com/v2/projects?is_active=true&per_page=400");
return $response->json();
}
As you can see I'm using the Http function to fetch something from the Harvest API, but if I do a dump of $response in this function before returning it I get the actual content. I was hoping/expecting the Http::fake to override and let me shape the content for further testing.
Can anyone help me figure out what I'm missing? Thank you π