saloonphp / saloon

🤠 Build beautiful API integrations and SDKs with Saloon
https://docs.saloon.dev
MIT License
2.03k stars 105 forks source link

Asserting a request is sent by closure parameter #417

Closed innocenzi closed 2 months ago

innocenzi commented 3 months ago

Take the following snippet:

MockClient::getGlobal()->assertSent(function (CreateDealRequest $request) {
    expect($request->body()->all())->toMatchArray([
        'title' => '[MGT] Jon Doe / foo - bar / ' . now()->addDay()->format('M d \'y'),
        'status' => DealStatus::OPEN,
    ]);
});

This would fail if there was a request other than CreateDealRequest. It would be great if assertSent could take the request type into account.

Open to PRing that 👍

Sammyjo20 commented 2 months ago

Thank you for PRing this! I'm going to close this as it's now a PR.