Skip to content

[7.x] Add HTTP client assertions assertNotSent() and assertNothingSent() #32197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2020
Merged

[7.x] Add HTTP client assertions assertNotSent() and assertNothingSent() #32197

merged 1 commit into from
Apr 2, 2020

Conversation

christophrumpel
Copy link
Contributor

This PR adds a new assertion to the new HTTP client called assertNotSent.

Similar to the given helper method assertSent, this new one tests the opposite: if a specific request was not sent.

Here is an example:

Http::assertNotSent(function ($request) {
    return $request->hasHeader('X-First', 'foo') &&
           $request->url() == 'http://test.com/users' &&
           $request['name'] == 'Taylor' &&
           $request['role'] == 'Developer';
});

Since there are no specific tests for the assertion helpers, I added one to the HTTP client test file.

@christophrumpel christophrumpel changed the title [7.x] Add HTTP client assertion assertNotSent() [7.x] Add HTTP client assertions assertNotSent() and assertNothingSent() Apr 2, 2020
@christophrumpel
Copy link
Contributor Author

After @nunomaduro's feedback, I added another assertion to make sure no request was sent at all.

this->factory->assertNothingSent();

@nuernbergerA
Copy link
Contributor

Nice PR!

@taylorotwell taylorotwell merged commit 194953f into laravel:7.x Apr 2, 2020
@taylorotwell
Copy link
Member

Thanks. Probably worth a laravel/docs PR.

@christophrumpel
Copy link
Contributor Author

Thanks and no problem. Will do a docs PR as well 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants