Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cbb5968

Browse filesBrowse files
committed
feature symfony#19 Added a "smoke test" for the application URLs and moved one test location (javiereguiluz)
This PR was squashed before being merged into the master branch (closes symfony#19). Discussion ---------- Added a "smoke test" for the application URLs and moved one test location This fixes symfony#18 Commits ------- 5c75ed6 Added a "smoke test" for the application URLs and moved one test location
2 parents 4f65c26 + 5c75ed6 commit cbb5968
Copy full SHA for cbb5968

File tree

Expand file treeCollapse file tree

3 files changed

+103
-16
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+103
-16
lines changed
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace AppBundle\Tests\Controller;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15+
use AppBundle\Entity\Post;
16+
17+
/**
18+
* Functional test for the controllers defined inside BlogController.
19+
* See http://symfony.com/doc/current/book/testing.html#functional-tests
20+
*
21+
* Execute the application tests using this command (requires PHPUnit to be installed):
22+
*
23+
* $ cd your-symfony-project/
24+
* $ phpunit -c app
25+
*
26+
*/
27+
class BlogControllerTest extends WebTestCase
28+
{
29+
public function testIndex()
30+
{
31+
$client = static::createClient();
32+
$crawler = $client->request('GET', '/blog/');
33+
34+
$this->assertCount(
35+
Post::NUM_ITEMS,
36+
$crawler->filter('article.post'),
37+
'The homepage displays the right number of posts.'
38+
);
39+
}
40+
}

‎src/AppBundle/Tests/Controller/DefaultControllerTest.php

Copy file name to clipboardExpand all lines: src/AppBundle/Tests/Controller/DefaultControllerTest.php
+60-12Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,76 @@
1212
namespace AppBundle\Tests\Controller;
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15-
use AppBundle\Entity\Post;
1615

1716
/**
18-
* Functional test for the DefaultController methods.
19-
* See http://symfony.com/doc/current/book/testing.html#functional-tests
17+
* Functional test that implements a "smoke test" of all the public and secure
18+
* URLs of the application.
19+
* See http://symfony.com/doc/current/best_practices/tests.html#functional-tests.
2020
*
2121
* Execute the application tests using this command (requires PHPUnit to be installed):
22-
* $ cd your-symfony-project/
23-
* $ phpunit -c app
2422
*
25-
* @author Ryan Weaver <weaverryan@gmail.com>
26-
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
23+
* $ cd your-symfony-project/
24+
* $ phpunit -c app
25+
*
2726
*/
2827
class DefaultControllerTest extends WebTestCase
2928
{
30-
public function testIndex()
29+
/**
30+
* PHPUnit's data providers allow to execute the same tests repeated times
31+
* using a different set of data each time.
32+
* See http://symfony.com/doc/current/cookbook/form/unit_testing.html#testing-against-different-sets-of-data.
33+
*
34+
* @dataProvider getPublicUrls
35+
*/
36+
public function testPublicUrls($url)
37+
{
38+
$client = self::createClient();
39+
$client->request('GET', $url);
40+
41+
$this->assertTrue(
42+
$client->getResponse()->isSuccessful(),
43+
sprintf('The %s public URL loads correctly.', $url)
44+
);
45+
}
46+
47+
/**
48+
* The application contains a lot of secure URLs which shouldn't be
49+
* publicly accessible. This tests ensures that whenever a user tries to
50+
* access one of those pages, a redirection to the login form is performed.
51+
*
52+
* @dataProvider getSecureUrls
53+
*/
54+
public function testSecureUrls($url)
3155
{
32-
$client = static::createClient();
33-
$crawler = $client->request('GET', '/blog/');
56+
$client = self::createClient();
57+
$client->request('GET', $url);
3458

35-
$this->assertEquals(Post::NUM_ITEMS, $crawler->filter('article.post')->count(),
36-
'The homepage displayes the right number of posts'
59+
$this->assertTrue($client->getResponse()->isRedirect());
60+
61+
$this->assertEquals(
62+
'http://localhost/login',
63+
$client->getResponse()->getTargetUrl(),
64+
sprintf('The %s secure URL redirects to the login form.', $url)
65+
);
66+
}
67+
68+
public function getPublicUrls()
69+
{
70+
return array(
71+
array('/'),
72+
array('/blog/'),
73+
array('/blog/posts/morbi-tempus-commodo-mattis'),
74+
array('/login'),
75+
);
76+
}
77+
78+
public function getSecureUrls()
79+
{
80+
return array(
81+
array('/admin/post/'),
82+
array('/admin/post/new'),
83+
array('/admin/post/1'),
84+
array('/admin/post/1/edit'),
3785
);
3886
}
3987
}

‎src/AppBundle/Tests/Utils/SluggerTest.php

Copy file name to clipboardExpand all lines: src/AppBundle/Tests/Utils/SluggerTest.php
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
* See http://symfony.com/doc/current/book/testing.html#unit-tests
1919
*
2020
* Execute the application tests using this command (requires PHPUnit to be installed):
21-
* $ cd your-symfony-project/
22-
* $ phpunit -c app
2321
*
24-
* @author Ryan Weaver <weaverryan@gmail.com>
25-
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
22+
* $ cd your-symfony-project/
23+
* $ phpunit -c app
24+
*
2625
*/
2726
class SluggerTest extends \PHPUnit_Framework_TestCase
2827
{

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.