From bed8a5eee9589ce5c96c458f5c30b1b71550ebb9 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 4 Feb 2020 20:29:11 +0100 Subject: [PATCH] [Testing] Use a better example for Symfony asserts --- testing/functional_tests_assertions.rst | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/testing/functional_tests_assertions.rst b/testing/functional_tests_assertions.rst index 6cff835e1f0..edf1a6bb679 100644 --- a/testing/functional_tests_assertions.rst +++ b/testing/functional_tests_assertions.rst @@ -13,16 +13,15 @@ When doing functional tests, sometimes you need to make complex assertions in order to check whether the ``Request``, the ``Response`` or the ``Crawler`` contain the expected information to make your test succeed. -Here is an example with plain PHPUnit:: +The following example uses plain PHPUnit to assert that the response redirects +to a certain URL:: - $this->assertGreaterThan( - 0, - $crawler->filter('html:contains("Hello World")')->count() - ); + $this->assertSame(301, $client->getResponse()->getStatusCode()); + $this->assertSame('https://example.com', $client->getResponse()->headers->get('Location')); -Now here is the example with the assertions specific to Symfony:: +This is the same example using the assertions provided by Symfony:: - $this->assertSelectorTextContains('html', 'Hello World'); + $this->assertResponseRedirects('https://example.com', 301); .. note:: @@ -70,9 +69,9 @@ Crawler - ``assertSelectorExists()`` - ``assertSelectorNotExists()`` -- ``assertSelectorTextContains()`` -- ``assertSelectorTextSame()`` -- ``assertSelectorTextNotContains()`` +- ``assertSelectorTextContains()`` (note: it only checks the first selector occurrence) +- ``assertSelectorTextSame()`` (note: it only checks the first selector occurrence) +- ``assertSelectorTextNotContains()`` (note: it only checks the first selector occurrence) - ``assertPageTitleSame()`` - ``assertPageTitleContains()`` - ``assertInputValueSame()``