Skip to content

Commit

Permalink
minor #6736 Use message argument for PHPunit assert() functions (Simo…
Browse files Browse the repository at this point in the history
…nHeimberg, WouterJ)

This PR was merged into the 2.7 branch.

Discussion
----------

Use message argument for PHPunit assert() functions

Finishes #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
  • Loading branch information
wouterj committed Jul 9, 2016
2 parents b986733 + d604bfd commit 315cd5b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 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'
)
),
'the "Content-Type" header is "application/json"' // optional message shown on failure
);

// Assert that the response content contains a string
Expand All @@ -272,7 +273,7 @@ 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 is 2xx');
// Assert that the response status code is 404
$this->assertTrue($client->getResponse()->isNotFound());
// Assert a specific 200 status code
Expand All @@ -283,7 +284,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 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 315cd5b

Please sign in to comment.