Permalink
Browse files

feature #4712 Provide full test example (ifdattic)

This PR was merged into the 2.3 branch.

Discussion
----------

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 |

Commits
-------

9832e23 Update tests.rst
4df1fe1 Update tests.rst
d4907ca Update tests.rst
d4ab971 Provide full test example
  • Loading branch information...
weaverryan committed Feb 24, 2015
2 parents 5e83045 + 9832e23 commit f5ff45eba45bb4d87f5b49959eb6b9f7051157c0
Showing with 26 additions and 16 deletions.
  1. +26 −16 best_practices/tests.rst
@@ -30,25 +30,35 @@ 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);
// src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php
namespace AppBundle\Tests;
$this->assertTrue($client->getResponse()->isSuccessful());
}
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 urlProvider
*/
public function testPageIsSuccessful($url)
{
$client = self::createClient();
$client->request('GET', $url);
$this->assertTrue($client->getResponse()->isSuccessful());
}
public function urlProvider()
{
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

0 comments on commit f5ff45e

Please sign in to comment.