Join Justin Yost for an in-depth discussion in this video Basic Guzzle mock responses, part of Consuming RESTful APIs in PHP with Guzzle.
- [Instructor] When we want to test the Guzzle client,…we typically will want to mock the responses we get back…from an external API, so as to not actually have to…hit a real API and make real network requests.…So, how can we go about doing that?…First of all, if you haven't done testing in PHP,…you may want to look at my recent course,…Test-Driven Development in PHP with PHPUnit.…It covers many of the basic techniques for writing…unit tests in PHP.…So, how do we fake the responses in Guzzle?…We'll start by going into our editor,…and we'll create a new file, and we'll name it mock.php.…
To begin with, since creating mocks requires a fair bit…of use lines to import that are tedious to write out.…We'll instead open up the snippets.txt file,…included in the exercise folder for this chapter…and this lesson.…We'll copy the contents of it, go back to our editor,…and paste it in as our top eight lines.…The way we mock the Guzzle responses…is actually pretty simple.…We mock it by building a middleware stack that will…
- 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 35m 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.