@@ -292,54 +292,55 @@ document::
292292
293293 // ...
294294
295- // asserts that there is at least one h2 tag
296- // with the class "subtitle"
297- $this->assertGreaterThan(
298- 0,
299- $crawler->filter('h2.subtitle')->count()
295+ // asserts that there is at least one h2 tag with the class "subtitle"
296+ // the third argument is an optional message shown on failed tests
297+ $this->assertGreaterThan(0, $crawler->filter('h2.subtitle')->count(),
298+ 'There is at least one subtitle'
300299 );
301300
302301 // asserts that there are exactly 4 h2 tags on the page
303302 $this->assertCount(4, $crawler->filter('h2'));
304303
305304 // asserts that the "Content-Type" header is "application/json"
306- $this->assertTrue(
307- $client->getResponse()->headers->contains(
308- 'Content-Type',
309- 'application/json'
310- ),
311- 'the "Content-Type" header is "application/json"' // optional message shown on failure
312- );
313- //or
314- $this->assertResponseHeaderSame('Content-Type', 'application/json', 'the "Content-Type" header is "application/json"');
305+ $this->assertResponseHeaderSame('Content-Type', 'application/json');
306+ // equivalent to:
307+ $this->assertTrue($client->getResponse()->headers->contains(
308+ 'Content-Type', 'application/json'
309+ ));
310+
315311 // asserts that the response content contains a string
316312 $this->assertContains('foo', $client->getResponse()->getContent());
317313 // ...or matches a regex
318314 $this->assertRegExp('/foo(bar)?/', $client->getResponse()->getContent());
319315
320316 // asserts that the response status code is 2xx
321- $this->assertTrue($client->getResponse()->isSuccessful(), 'response status is 2xx');
322- // ...or simply
323- $this->assertResponseIsSuccessful('response status is 2xx');
324- // asserts that the response status code is 404
317+ $this->assertResponseIsSuccessful();
318+ // equivalent to:
319+ $this->assertTrue($client->getResponse()->isSuccessful());
320+
321+ // asserts that the response status code is 404 Not Found
325322 $this->assertTrue($client->getResponse()->isNotFound());
326- // asserts a specific 200 status code
327- $this->assertEquals(
328- 200, // or Symfony\Component\HttpFoundation\Response::HTTP_OK
329- $client->getResponse()->getStatusCode()
330- );
331- //...or simply
332- $this->assertResponseStatusCodeSame(200);
323+
324+ // asserts a specific status code
325+ $this->assertResponseStatusCodeSame(201);
326+ // HTTP status numbers are available as constants too:
327+ // e.g. 201 === Symfony\Component\HttpFoundation\Response::HTTP_CREATED
328+ // equivalent to:
329+ $this->assertEquals(201, $client->getResponse()->getStatusCode());
330+
333331 // asserts that the response is a redirect to /demo/contact
334- $this->assertTrue(
335- $client->getResponse()->isRedirect('/demo/contact')
336- // if the redirection URL was generated as an absolute URL
337- // $client->getResponse()->isRedirect('http://localhost/demo/contact')
338- );
339- // ...or simply check that the response is a redirect to any URL
340- $this->assertTrue($client->getResponse()->isRedirect());
341- // ...or simply
332+ $this->assertResponseRedirects('/demo/contact');
333+ // equivalent to:
334+ $this->assertTrue($client->getResponse()->isRedirect('/demo/contact'));
335+ // ...or check that the response is a redirect to any URL
342336 $this->assertResponseRedirects();
337+
338+ .. versionadded :: 4.3
339+
340+ The ``assertResponseHeaderSame() ``, ``assertResponseIsSuccessful() ``,
341+ ``assertResponseStatusCodeSame() ``, ``assertResponseRedirects() `` and other
342+ related methods were introduced in Symfony 4.3.
343+
343344.. _testing-data-providers :
344345
345346Testing against Different Sets of Data
0 commit comments