Skip to content

Commit 97e072e

Browse files
SimonHeimbergwouterj
authored andcommitted
use the message argument of assertX functions
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
1 parent 70c980d commit 97e072e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

book/testing.rst

Lines changed: 7 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+
'"Content-Type" header is NOT "application/json"' // optional message shown on failure
267268
);
268269

269270
// Assert that the response content contains a string
@@ -272,7 +273,9 @@ 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(),
277+
'response status code is NOT 2xx'
278+
);
276279
// Assert that the response status code is 404
277280
$this->assertTrue($client->getResponse()->isNotFound());
278281
// Assert a specific 200 status code
@@ -283,7 +286,8 @@ document::
283286

284287
// Assert that the response is a redirect to /demo/contact
285288
$this->assertTrue(
286-
$client->getResponse()->isRedirect('/demo/contact')
289+
$client->getResponse()->isRedirect('/demo/contact'),
290+
'response is NOT a redirect to /demo/contact'
287291
);
288292
// ...or simply check that the response is a redirect to any URL
289293
$this->assertTrue($client->getResponse()->isRedirect());

0 commit comments

Comments
 (0)