Skip to content
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

[8.x] Make ResponseSequence macroable #36719

Merged
merged 2 commits into from
Mar 24, 2021
Merged

[8.x] Make ResponseSequence macroable #36719

merged 2 commits into from
Mar 24, 2021

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Mar 23, 2021

This PR makes the ResponseSequence class macroable. This class is used by Http::fakeSequence().

My first use-case is that some APIs always need to retrieve an access token before any calls can be made. Currently I always push a fixture of the access token response every time I call Http::fakeSequence(). Custom macros can clean this up:

Http::fakeSequence()
    ->pushFile($this->fixtures.'dhl/access-token-01.json')
    ->pushFile($this->fixtures.'dhl/tracking-01.json');

// After this PR

Http::fakeSequence()
    ->pushDhlAccessTokenResponse()
    ->pushFile($this->fixtures.'dhl/tracking-01.json');

Macros can also be used to craft custom responses. This is a use-case from another project of mine:

$checkoutUrl = 'http://example.com/'.Str::random();

Http::fakeSequence()
    ->pushMollieCheckoutResponse($checkoutUrl);

$this->postCheckout()
    ->assertRedirect($checkoutUrl);

@taylorotwell taylorotwell merged commit de5f6a7 into laravel:8.x Mar 24, 2021
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.

2 participants