1414use AppBundle \Entity \Post ;
1515use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
1616use Symfony \Component \HttpFoundation \Response ;
17- use Tests \ControllerTestTrait ;
1817use Tests \FixturesTrait ;
1918
2019/**
3433 */
3534class BlogControllerTest extends WebTestCase
3635{
37- use ControllerTestTrait;
3836 use FixturesTrait;
3937
4038 /**
4139 * @dataProvider getUrlsForRegularUsers
4240 */
4341 public function testAccessDeniedForRegularUsers ($ httpMethod , $ url )
4442 {
45- $ client = $ this ->getUserClient ();
43+ $ client = static ::createClient ([], [
44+ 'PHP_AUTH_USER ' => 'john_user ' ,
45+ 'PHP_AUTH_PW ' => 'kitten ' ,
46+ ]);
4647
4748 $ client ->request ($ httpMethod , $ url );
4849 $ this ->assertSame (Response::HTTP_FORBIDDEN , $ client ->getResponse ()->getStatusCode ());
@@ -58,7 +59,10 @@ public function getUrlsForRegularUsers()
5859
5960 public function testAdminBackendHomePage ()
6061 {
61- $ client = $ this ->getAdminClient ();
62+ $ client = static ::createClient ([], [
63+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
64+ 'PHP_AUTH_PW ' => 'kitten ' ,
65+ ]);
6266
6367 $ crawler = $ client ->request ('GET ' , '/en/admin/post/ ' );
6468 $ this ->assertSame (Response::HTTP_OK , $ client ->getResponse ()->getStatusCode ());
@@ -82,7 +86,10 @@ public function testAdminNewPost()
8286 $ postSummary = $ this ->getRandomPostSummary ();
8387 $ postContent = $ this ->getPostContent ();
8488
85- $ client = $ this ->getAdminClient ();
89+ $ client = static ::createClient ([], [
90+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
91+ 'PHP_AUTH_PW ' => 'kitten ' ,
92+ ]);
8693 $ crawler = $ client ->request ('GET ' , '/en/admin/post/new ' );
8794 $ form = $ crawler ->selectButton ('Create post ' )->form ([
8895 'post[title] ' => $ postTitle ,
@@ -103,7 +110,10 @@ public function testAdminNewPost()
103110
104111 public function testAdminShowPost ()
105112 {
106- $ client = $ this ->getAdminClient ();
113+ $ client = static ::createClient ([], [
114+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
115+ 'PHP_AUTH_PW ' => 'kitten ' ,
116+ ]);
107117 $ client ->request ('GET ' , '/en/admin/post/1 ' );
108118
109119 $ this ->assertSame (Response::HTTP_OK , $ client ->getResponse ()->getStatusCode ());
@@ -119,7 +129,10 @@ public function testAdminEditPost()
119129 {
120130 $ newBlogPostTitle = 'Blog Post Title ' .mt_rand ();
121131
122- $ client = $ this ->getAdminClient ();
132+ $ client = static ::createClient ([], [
133+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
134+ 'PHP_AUTH_PW ' => 'kitten ' ,
135+ ]);
123136 $ crawler = $ client ->request ('GET ' , '/en/admin/post/1/edit ' );
124137 $ form = $ crawler ->selectButton ('Save changes ' )->form ([
125138 'post[title] ' => $ newBlogPostTitle ,
@@ -141,7 +154,10 @@ public function testAdminEditPost()
141154 */
142155 public function testAdminDeletePost ()
143156 {
144- $ client = $ this ->getAdminClient ();
157+ $ client = static ::createClient ([], [
158+ 'PHP_AUTH_USER ' => 'jane_admin ' ,
159+ 'PHP_AUTH_PW ' => 'kitten ' ,
160+ ]);
145161 $ crawler = $ client ->request ('GET ' , '/en/admin/post/1 ' );
146162 $ client ->submit ($ crawler ->filter ('#delete-form ' )->form ());
147163
0 commit comments