Skip to content

Commit

Permalink
feature #4712 Provide full test example (ifdattic)
Browse files Browse the repository at this point in the history
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 f5ff45e
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions best_practices/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5ff45e

Please sign in to comment.