Skip to content

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

Merged
taylorotwell merged 1 commit intolaravel:7.xfrom
christophrumpel:feature/addNotSentAssertionToHttpClient
Apr 2, 2020
Merged

[7.x] Add HTTP client assertions assertNotSent() and assertNothingSent()#32197
taylorotwell merged 1 commit intolaravel:7.xfrom
christophrumpel:feature/addNotSentAssertionToHttpClient

Conversation

@christophrumpel
Copy link
Copy Markdown
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.

Comment thread src/Illuminate/Http/Client/Factory.php
@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
Copy Markdown
Contributor Author

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

this->factory->assertNothingSent();

Comment thread src/Illuminate/Http/Client/Factory.php
Comment thread src/Illuminate/Http/Client/Factory.php Outdated
@nuernbergerA
Copy link
Copy Markdown
Contributor

Nice PR!

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

Thanks. Probably worth a laravel/docs PR.

@christophrumpel
Copy link
Copy Markdown
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