Skip to content

Commit f5ff45e

Browse files
committed
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
2 parents 5e83045 + 9832e23 commit f5ff45e

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

best_practices/tests.rst

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,35 @@ A functional test can be as easy as this:
3030

3131
.. code-block:: php
3232
33-
/** @dataProvider provideUrls */
34-
public function testPageIsSuccessful($url)
35-
{
36-
$client = self::createClient();
37-
$client->request('GET', $url);
33+
// src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php
34+
namespace AppBundle\Tests;
3835
39-
$this->assertTrue($client->getResponse()->isSuccessful());
40-
}
36+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
4137
42-
public function provideUrls()
38+
class ApplicationAvailabilityFunctionalTest extends WebTestCase
4339
{
44-
return array(
45-
array('/'),
46-
array('/posts'),
47-
array('/post/fixture-post-1'),
48-
array('/blog/category/fixture-category'),
49-
array('/archives'),
50-
// ...
51-
);
40+
/**
41+
* @dataProvider urlProvider
42+
*/
43+
public function testPageIsSuccessful($url)
44+
{
45+
$client = self::createClient();
46+
$client->request('GET', $url);
47+
48+
$this->assertTrue($client->getResponse()->isSuccessful());
49+
}
50+
51+
public function urlProvider()
52+
{
53+
return array(
54+
array('/'),
55+
array('/posts'),
56+
array('/post/fixture-post-1'),
57+
array('/blog/category/fixture-category'),
58+
array('/archives'),
59+
// ...
60+
);
61+
}
5262
}
5363
5464
This code checks that all the given URLs load successfully, which means that

0 commit comments

Comments
 (0)