Skip to content

Commit

Permalink
use the message argument of assertX functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SimonHeimberg authored and wouterj committed Jul 8, 2016
1 parent 70c980d commit 97e072e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions book/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ document::
$client->getResponse()->headers->contains(
'Content-Type',
'application/json'
)
),
'"Content-Type" header is NOT "application/json"' // optional message shown on failure
);

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

// Assert that the response status code is 2xx
$this->assertTrue($client->getResponse()->isSuccessful());
$this->assertTrue($client->getResponse()->isSuccessful(),
'response status code is NOT 2xx'
);
// Assert that the response status code is 404
$this->assertTrue($client->getResponse()->isNotFound());
// Assert a specific 200 status code
Expand All @@ -283,7 +286,8 @@ document::

// Assert that the response is a redirect to /demo/contact
$this->assertTrue(
$client->getResponse()->isRedirect('/demo/contact')
$client->getResponse()->isRedirect('/demo/contact'),
'response is NOT a redirect to /demo/contact'
);
// ...or simply check that the response is a redirect to any URL
$this->assertTrue($client->getResponse()->isRedirect());
Expand Down

0 comments on commit 97e072e

Please sign in to comment.