Join Justin Yost for an in-depth discussion in this video Advanced Guzzle mock responses, part of Consuming RESTful APIs in PHP with Guzzle.
- [Instructor] So What happens when we need…our Guzzle mock responses…to contain more possibilities…than just some simple headers…or a certain status code?…Can we get our mocks…to also contain a custom response?…Let's set this up.…To begin we'll work with the mock file that…we worked with in the last lesson…to speed up our development.…So open up mock.php.…Now currently we just create…some random responses and that's pretty much it.…We want to add in the ability…to set our responses to include an actual body.…
To do this we'll add a few blank lines…between lines 8 and 10.…And we'll create a variable body that…we'll then set to an empty array.…Now at this point, we'll want to create a mock response…as if we are talking to an API.…So we'll set, for instance, an id…and a name field for this body array.…We'll set an id equal to the number 10…and then we'll set a name property set equal…to the string sample.…
Right.…Now we want to pass in our body to the request.…So let's go ahead and delete…our other mock responses except…
- Installing Guzzle
- Sending basic requests
- Sending asynchronous requests
- Sending concurrent requests
- Sending query data
- Sending request data
- Advanced Guzzle request options
- Reviewing basic Guzzle responses
- Processing response headers
- Reviewing PSR-7 requests, responses, bodies, and headers
Skill Level Intermediate
PHP: Clean URLs on Apache Serverwith David Powers1h 36m Intermediate
PHP: Managing Persistent Sessionswith David Powers2h 41m Intermediate
1. Guzzle Basics
2. Requests with Guzzle
3. Responses with Guzzle
4. Guzzle and PSR-7
5. Testing and Guzzle
Next steps1m 12s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.