@@ -14,211 +14,249 @@ create your own directly using any ``ResponseInterface``:
1414 :depth: 2
1515
1616Testing the Response
17- ====================
17+ ********************
1818
1919Whether you have received a ``TestResponse `` as a result of your tests or created one yourself,
2020there are a number of new assertions that you can use in your tests.
2121
2222Accessing Request/Response
23- --------------------------
23+ ==========================
2424
25- **request() **
25+ request()
26+ ---------
2627
2728You can access directly the Request object, if it was set during testing:
2829
2930.. literalinclude :: response/002.php
3031
31- **response() **
32+ response()
33+ ----------
3234
3335This allows you direct access to the response object:
3436
3537.. literalinclude :: response/003.php
3638
3739Checking Response Status
38- ------------------------
40+ ========================
3941
40- **isOK() **
42+ isOK()
43+ ------
4144
4245Returns a boolean true/false based on whether the response is perceived to be "ok". This is primarily determined by
4346a response status code in the 200 or 300's. An empty body is not considered valid, unless in redirects.
4447
4548.. literalinclude :: response/004.php
4649
47- **assertOK() **
50+ assertOK()
51+ ----------
4852
49- This assertion simply uses the ** isOK() ** method to test a response. ** assertNotOK ** is the inverse of this assertion.
53+ This assertion simply uses the `` isOK() `` method to test a response. `` assertNotOK() `` is the inverse of this assertion.
5054
5155.. literalinclude :: response/005.php
5256
53- **isRedirect() **
57+ isRedirect()
58+ ------------
5459
5560Returns a boolean true/false based on whether the response is a redirected response.
5661
5762.. literalinclude :: response/006.php
5863
59- **assertRedirect() **
64+ assertRedirect()
65+ ----------------
6066
61- Asserts that the Response is an instance of RedirectResponse. ** assertNotRedirect ** is the inverse of this assertion.
67+ Asserts that the Response is an instance of RedirectResponse. `` assertNotRedirect() `` is the inverse of this assertion.
6268
6369.. literalinclude :: response/007.php
6470
65- **assertRedirectTo() **
71+ assertRedirectTo()
72+ ------------------
6673
6774Asserts that the Response is an instance of RedirectResponse and the destination
6875matches the uri given.
6976
7077.. literalinclude :: response/008.php
7178
72- **getRedirectUrl() **
79+ getRedirectUrl()
80+ ----------------
7381
7482Returns the URL set for a RedirectResponse, or null for failure.
7583
7684.. literalinclude :: response/009.php
7785
78- **assertStatus(int $code) **
86+ assertStatus(int $code)
87+ -----------------------
7988
8089Asserts that the HTTP status code returned matches $code.
8190
8291.. literalinclude :: response/010.php
8392
8493Session Assertions
85- ------------------
94+ ==================
8695
87- **assertSessionHas(string $key, $value = null) **
96+ assertSessionHas(string $key, $value = null)
97+ --------------------------------------------
8898
8999Asserts that a value exists in the resulting session. If $value is passed, will also assert that the variable's value
90100matches what was specified.
91101
92102.. literalinclude :: response/011.php
93103
94- **assertSessionMissing(string $key) **
104+ assertSessionMissing(string $key)
105+ ---------------------------------
95106
96107Asserts that the resulting session does not include the specified $key.
97108
98109.. literalinclude :: response/012.php
99110
100111Header Assertions
101- -----------------
112+ =================
102113
103- **assertHeader(string $key, $value = null) **
114+ assertHeader(string $key, $value = null)
115+ ----------------------------------------
104116
105- Asserts that a header named ** $key ** exists in the response. If ** $value ** is not empty, will also assert that
117+ Asserts that a header named `` $key `` exists in the response. If `` $value `` is not empty, will also assert that
106118the values match.
107119
108120.. literalinclude :: response/013.php
109121
110- **assertHeaderMissing(string $key) **
122+ assertHeaderMissing(string $key)
123+ --------------------------------
111124
112- Asserts that a header name ** $key ** does not exist in the response.
125+ Asserts that a header name `` $key `` does not exist in the response.
113126
114127.. literalinclude :: response/014.php
115128
116129Cookie Assertions
117- -----------------
130+ =================
118131
119- **assertCookie(string $key, $value = null, string $prefix = '') **
132+ assertCookie(string $key, $value = null, string $prefix = '')
133+ -------------------------------------------------------------
120134
121- Asserts that a cookie named ** $key ** exists in the response. If ** $value ** is not empty, will also assert that
135+ Asserts that a cookie named `` $key `` exists in the response. If `` $value `` is not empty, will also assert that
122136the values match. You can set the cookie prefix, if needed, by passing it in as the third parameter.
123137
124138.. literalinclude :: response/015.php
125139
126- **assertCookieMissing(string $key) **
140+ assertCookieMissing(string $key)
141+ --------------------------------
127142
128- Asserts that a cookie named ** $key ** does not exist in the response.
143+ Asserts that a cookie named `` $key `` does not exist in the response.
129144
130145.. literalinclude :: response/016.php
131146
132- **assertCookieExpired(string $key, string $prefix = '') **
147+ assertCookieExpired(string $key, string $prefix = '')
148+ -----------------------------------------------------
133149
134- Asserts that a cookie named ** $key ** exists, but has expired. You can set the cookie prefix, if needed, by passing it
150+ Asserts that a cookie named `` $key `` exists, but has expired. You can set the cookie prefix, if needed, by passing it
135151in as the second parameter.
136152
137153.. literalinclude :: response/017.php
138154
139155DOM Helpers
140- -----------
156+ ===========
141157
142158The response you get back contains a number of helper methods to inspect the HTML output within the response. These
143159are useful for using within assertions in your tests.
144160
145- The **see() ** method checks the text on the page to see if it exists either by itself, or more specifically within
161+ see()
162+ -----
163+
164+ The ``see() `` method checks the text on the page to see if it exists either by itself, or more specifically within
146165a tag, as specified by type, class, or id:
147166
148167.. literalinclude :: response/018.php
149168
150- The ** dontSee() ** method is the exact opposite:
169+ The `` dontSee() `` method is the exact opposite:
151170
152171.. literalinclude :: response/019.php
153172
154- The **seeElement() ** and **dontSeeElement() ** are very similar to the previous methods, but do not look at the
173+ seeElement()
174+ ------------
175+
176+ The ``seeElement() `` and ``dontSeeElement() `` are very similar to the previous methods, but do not look at the
155177values of the elements. Instead, they simply check that the elements exist on the page:
156178
157179.. literalinclude :: response/020.php
158180
159- You can use **seeLink() ** to ensure that a link appears on the page with the specified text:
181+ seeLink()
182+ ---------
183+
184+ You can use ``seeLink() `` to ensure that a link appears on the page with the specified text:
160185
161186.. literalinclude :: response/021.php
162187
163- The **seeInField() ** method checks for any input tags exist with the name and value:
188+ seeInField()
189+ ------------
190+
191+ The ``seeInField() `` method checks for any input tags exist with the name and value:
164192
165193.. literalinclude :: response/022.php
166194
167- Finally, you can check if a checkbox exists and is checked with the **seeCheckboxIsChecked() ** method:
195+ seeCheckboxIsChecked()
196+ ----------------------
197+
198+ Finally, you can check if a checkbox exists and is checked with the ``seeCheckboxIsChecked() `` method:
168199
169200.. literalinclude :: response/023.php
170201
171202DOM Assertions
172- --------------
203+ ==============
173204
174205You can perform tests to see if specific elements/text/etc exist with the body of the response with the following
175206assertions.
176207
177- **assertSee(string $search = null, string $element = null) **
208+ assertSee(string $search = null, string $element = null)
209+ --------------------------------------------------------
178210
179211Asserts that text/HTML is on the page, either by itself or - more specifically - within
180212a tag, as specified by type, class, or id:
181213
182214.. literalinclude :: response/024.php
183215
184- **assertDontSee(string $search = null, string $element = null) **
216+ assertDontSee(string $search = null, string $element = null)
217+ ------------------------------------------------------------
185218
186- Asserts the exact opposite of the ** assertSee() ** method:
219+ Asserts the exact opposite of the `` assertSee() `` method:
187220
188221.. literalinclude :: response/025.php
189222
190- **assertSeeElement(string $search) **
223+ assertSeeElement(string $search)
224+ --------------------------------
191225
192- Similar to ** assertSee() ** , however this only checks for an existing element. It does not check for specific text:
226+ Similar to `` assertSee() `` , however this only checks for an existing element. It does not check for specific text:
193227
194228.. literalinclude :: response/026.php
195229
196- **assertDontSeeElement(string $search) **
230+ assertDontSeeElement(string $search)
231+ ------------------------------------
197232
198- Similar to ** assertSee() ** , however this only checks for an existing element that is missing. It does not check for
233+ Similar to `` assertSee() `` , however this only checks for an existing element that is missing. It does not check for
199234specific text:
200235
201236.. literalinclude :: response/027.php
202237
203- **assertSeeLink(string $text, string $details=null) **
238+ assertSeeLink(string $text, string $details = null)
239+ ---------------------------------------------------
204240
205- Asserts that an anchor tag is found with matching ** $text ** as the body of the tag:
241+ Asserts that an anchor tag is found with matching `` $text `` as the body of the tag:
206242
207243.. literalinclude :: response/028.php
208244
209- **assertSeeInField(string $field, string $value=null) **
245+ assertSeeInField(string $field, string $value = null)
246+ -----------------------------------------------------
210247
211248Asserts that an input tag exists with the name and value:
212249
213250.. literalinclude :: response/029.php
214251
215252Working With JSON
216- -----------------
253+ =================
217254
218255Responses will frequently contain JSON responses, especially when working with API methods. The following methods
219256can help to test the responses.
220257
221- **getJSON() **
258+ getJSON()
259+ ---------
222260
223261This method will return the body of the response as a JSON string:
224262
@@ -230,19 +268,22 @@ You can use this method to determine if ``$response`` actually holds JSON conten
230268
231269.. note :: Be aware that the JSON string will be pretty-printed in the result.
232270
233- **assertJSONFragment(array $fragment) **
271+ assertJSONFragment(array $fragment)
272+ -----------------------------------
234273
235274Asserts that $fragment is found within the JSON response. It does not need to match the entire JSON value.
236275
237276.. literalinclude :: response/032.php
238277
239- **assertJSONExact($test) **
278+ assertJSONExact($test)
279+ ----------------------
240280
241- Similar to ** assertJSONFragment() ** , but checks the entire JSON response to ensure exact matches.
281+ Similar to `` assertJSONFragment() `` , but checks the entire JSON response to ensure exact matches.
242282
243283Working With XML
244- ----------------
284+ ================
245285
246- **getXML() **
286+ getXML()
287+ --------
247288
248289If your application returns XML, you can retrieve it through this method.
0 commit comments