Skip to content

Commit

Permalink
Provide full test example
Browse files Browse the repository at this point in the history
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 |
  • Loading branch information
ifdattic committed Dec 30, 2014
1 parent 153565e commit d4ab971
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions best_practices/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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);
<?php
$this->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
Expand Down

0 comments on commit d4ab971

Please sign in to comment.