knubbe's avatar
Level 36

How to wrote a test for method in controller with DI?

I have invocable controller for rendering some pdf. In route I only need to pass some string as parameter but my method look like this:

public function __invoke(
        Request $request,
        IncidentPdfGenerationService $incidentPdfGenerationService,
        string $report
    ) {
        $pdf = $incidentPdfGenerationService->getRawPdf($request, $report);
        $name = $report . '.pdf';

        return $pdf->stream($name);
    }

IncidentPdfGenerationService is a interface and I bind that in service provider. How to wrote a test to check this route with only assertStatus(200)?

0 likes
2 replies
knubbe's avatar
Level 36

I try to trigger method via route and test this controller

Please or to participate in this conversation.