Level 70
@abkrim How about this?
expect(fn () => AnalyzerCallJobV1::dispatch(
$ulid,
$commandCenter,
$job_time,
$delayed_at
))->throws(CallSlimException::class);
1 like
I can't do a test to verify that a series of errors in the work of a job throws a series of exceptions.
The Job calls an Action which makes a call to an API.
The test makes a fake of said call emulating a 500 error.
it('CallAnalyzerAction throws a communication error with slim', function () {
$commandCenter = CommandCenter::factory()->create();
$job_time = Carbon::now();
$delayed_at = Carbon::now();
$ulid = generateUlid();
Http::fake(['*' => Http::response('Error', 500)]);
AnalyzerCallJobV1::dispatch(
$ulid,
$commandCenter,
$job_time,
$delayed_at
);
$this->expectException(CallSlimException::class);
});
if ($response->serverError()) {
ray('Error 500');
throw new CallSlimException("SLIM server error {$response->status()} $msg");
}
When I run the test the answer is correct in the sense that the code hits the exception, since ray shows me the message "Error 500"
However, the expectation fails.
Failed asserting that exception of type "App\Exceptions\CallSlimException" is thrown.
at vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:176
I'm lost with this problem
Please or to participate in this conversation.