Skip to content

Commit 315cd5b

Browse files
committed
minor symfony#6736 Use message argument for PHPunit assert() functions (SimonHeimberg, WouterJ)
This PR was merged into the 2.7 branch. Discussion ---------- Use message argument for PHPunit assert() functions Finishes symfony#6118 Original PR description: > Assert functions from PHPUnit do have an optional message argument. This is especially usefull for assertTrue because the message printed on failure does not (and can not) contain any details. Demonstrate this possibility Commits ------- d604bfd Make messages positive 97e072e use the message argument of assertX functions
2 parents b986733 + d604bfd commit 315cd5b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

book/testing.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ document::
263263
$client->getResponse()->headers->contains(
264264
'Content-Type',
265265
'application/json'
266-
)
266+
),
267+
'the "Content-Type" header is "application/json"' // optional message shown on failure
267268
);
268269

269270
// Assert that the response content contains a string
@@ -272,7 +273,7 @@ document::
272273
$this->assertRegExp('/foo(bar)?/', $client->getResponse()->getContent());
273274

274275
// Assert that the response status code is 2xx
275-
$this->assertTrue($client->getResponse()->isSuccessful());
276+
$this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
276277
// Assert that the response status code is 404
277278
$this->assertTrue($client->getResponse()->isNotFound());
278279
// Assert a specific 200 status code
@@ -283,7 +284,8 @@ document::
283284

284285
// Assert that the response is a redirect to /demo/contact
285286
$this->assertTrue(
286-
$client->getResponse()->isRedirect('/demo/contact')
287+
$client->getResponse()->isRedirect('/demo/contact'),
288+
'response is a redirect to /demo/contact'
287289
);
288290
// ...or simply check that the response is a redirect to any URL
289291
$this->assertTrue($client->getResponse()->isRedirect());

0 commit comments

Comments
 (0)