From d4ab97123773446ec225e122d03950aa5502e348 Mon Sep 17 00:00:00 2001 From: "Andrew (Andrius) Marcinkevicius" Date: Tue, 30 Dec 2014 13:13:53 +0200 Subject: [PATCH 1/4] Provide full test example In my opinion providing the full code for the example only adds a few additional lines, but increases the value of the example greatly. Of course the name for the test should probably be changed as couldn't think of a good one. ping @stof | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.3 | Fixed tickets | --- best_practices/tests.rst | 41 ++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/best_practices/tests.rst b/best_practices/tests.rst index 0bbcbd665de..83aaabb631a 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -30,25 +30,34 @@ A functional test can be as easy as this: .. code-block:: php - /** @dataProvider provideUrls */ - public function testPageIsSuccessful($url) - { - $client = self::createClient(); - $client->request('GET', $url); + assertTrue($client->getResponse()->isSuccessful()); - } + namespace AppBundle\Tests; + + use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; - public function provideUrls() + class ApplicationAvailabilityFunctionalTest extends WebTestCase { - return array( - array('/'), - array('/posts'), - array('/post/fixture-post-1'), - array('/blog/category/fixture-category'), - array('/archives'), - // ... - ); + /** @dataProvider provideUrls */ + public function testPageIsSuccessful($url) + { + $client = self::createClient(); + $client->request('GET', $url); + + $this->assertTrue($client->getResponse()->isSuccessful()); + } + + public function provideUrls() + { + return array( + array('/'), + array('/posts'), + array('/post/fixture-post-1'), + array('/blog/category/fixture-category'), + array('/archives'), + // ... + ); + } } This code checks that all the given URLs load successfully, which means that From d4907caabd69d325a749e7b72c517687a2cda483 Mon Sep 17 00:00:00 2001 From: "Andrew (Andrius) Marcinkevicius" Date: Tue, 30 Dec 2014 14:51:50 +0200 Subject: [PATCH 2/4] Update tests.rst --- best_practices/tests.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/best_practices/tests.rst b/best_practices/tests.rst index 83aaabb631a..f3389cf8eff 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -30,7 +30,7 @@ A functional test can be as easy as this: .. code-block:: php - Date: Wed, 31 Dec 2014 12:24:40 +0200 Subject: [PATCH 3/4] Update tests.rst --- best_practices/tests.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/best_practices/tests.rst b/best_practices/tests.rst index f3389cf8eff..5c9a2f77fb5 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -38,7 +38,9 @@ A functional test can be as easy as this: class ApplicationAvailabilityFunctionalTest extends WebTestCase { - /** @dataProvider provideUrls */ + /** + * @dataProvider urlProvider + */ public function testPageIsSuccessful($url) { $client = self::createClient(); @@ -47,7 +49,7 @@ A functional test can be as easy as this: $this->assertTrue($client->getResponse()->isSuccessful()); } - public function provideUrls() + public function urlProvider() { return array( array('/'), From 9832e2314e1bb442410043b68918bebde83d98b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrew=20Marcinkevi=C4=8Dius?= Date: Mon, 23 Feb 2015 10:42:12 +0200 Subject: [PATCH 4/4] Update tests.rst --- best_practices/tests.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/best_practices/tests.rst b/best_practices/tests.rst index 5c9a2f77fb5..56f0581816e 100644 --- a/best_practices/tests.rst +++ b/best_practices/tests.rst @@ -31,7 +31,6 @@ A functional test can be as easy as this: .. code-block:: php // src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php - namespace AppBundle\Tests; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;