Skip to content

Provide full test example #4712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 24, 2015
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions best_practices/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,36 @@ 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the + // src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php one ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope the empty line after the line you mentioned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$this->assertTrue($client->getResponse()->isSuccessful());
}
namespace AppBundle\Tests;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add a file comment: // src/AppBundle/Tests/ApplicationAvailabilityFunctionalTest.php ?


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