Skip to content

Removed ControllerTestTrait #503

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 1 commit into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
32 changes: 24 additions & 8 deletions tests/AppBundle/Controller/Admin/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use AppBundle\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Tests\ControllerTestTrait;
use Tests\FixturesTrait;

/**
Expand All @@ -34,15 +33,17 @@
*/
class BlogControllerTest extends WebTestCase
{
use ControllerTestTrait;
use FixturesTrait;

/**
* @dataProvider getUrlsForRegularUsers
*/
public function testAccessDeniedForRegularUsers($httpMethod, $url)
{
$client = $this->getUserClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'john_user',
'PHP_AUTH_PW' => 'kitten',
]);

$client->request($httpMethod, $url);
$this->assertSame(Response::HTTP_FORBIDDEN, $client->getResponse()->getStatusCode());
Expand All @@ -58,7 +59,10 @@ public function getUrlsForRegularUsers()

public function testAdminBackendHomePage()
{
$client = $this->getAdminClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);

$crawler = $client->request('GET', '/en/admin/post/');
$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());
Expand All @@ -82,7 +86,10 @@ public function testAdminNewPost()
$postSummary = $this->getRandomPostSummary();
$postContent = $this->getPostContent();

$client = $this->getAdminClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
$crawler = $client->request('GET', '/en/admin/post/new');
$form = $crawler->selectButton('Create post')->form([
'post[title]' => $postTitle,
Expand All @@ -103,7 +110,10 @@ public function testAdminNewPost()

public function testAdminShowPost()
{
$client = $this->getAdminClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
$client->request('GET', '/en/admin/post/1');

$this->assertSame(Response::HTTP_OK, $client->getResponse()->getStatusCode());
Expand All @@ -119,7 +129,10 @@ public function testAdminEditPost()
{
$newBlogPostTitle = 'Blog Post Title '.mt_rand();

$client = $this->getAdminClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
$crawler = $client->request('GET', '/en/admin/post/1/edit');
$form = $crawler->selectButton('Save changes')->form([
'post[title]' => $newBlogPostTitle,
Expand All @@ -141,7 +154,10 @@ public function testAdminEditPost()
*/
public function testAdminDeletePost()
{
$client = $this->getAdminClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'jane_admin',
'PHP_AUTH_PW' => 'kitten',
]);
$crawler = $client->request('GET', '/en/admin/post/1');
$client->submit($crawler->filter('#delete-form')->form());

Expand Down
14 changes: 8 additions & 6 deletions tests/AppBundle/Controller/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use AppBundle\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Tests\ControllerTestTrait;
use Tests\FixturesTrait;

/**
Expand All @@ -29,12 +28,11 @@
*/
class BlogControllerTest extends WebTestCase
{
use ControllerTestTrait;
use FixturesTrait;

public function testIndex()
{
$client = $this->getAnonymousClient();
$client = static::createClient();
$crawler = $client->request('GET', '/en/blog/');

$this->assertCount(
Expand All @@ -46,7 +44,7 @@ public function testIndex()

public function testRss()
{
$client = $this->getAnonymousClient();
$client = static::createClient();
$crawler = $client->request('GET', '/en/blog/rss.xml');

$this->assertSame(
Expand All @@ -69,7 +67,10 @@ public function testRss()
*/
public function testNewComment()
{
$client = $this->getUserClient();
$client = static::createClient([], [
'PHP_AUTH_USER' => 'john_user',
'PHP_AUTH_PW' => 'kitten',
]);

/** @var Post $post */
$post = $client->getContainer()->get('doctrine')->getRepository(Post::class)->find(1);
Expand All @@ -85,7 +86,8 @@ public function testNewComment()
$this->assertSame(Response::HTTP_FOUND, $client->getResponse()->getStatusCode());

$post = $client->getContainer()->get('doctrine')->getRepository(Post::class)->find(1);
// The first one is the last inserted (See descending order of comments association).
// The first one is the most recent comment because of the automatic sorting
// defined in the comments association of the Post entity
$comment = $post->getComments()->first();

$this->assertSame($commentsCount + 1, $post->getComments()->count());
Expand Down
11 changes: 4 additions & 7 deletions tests/AppBundle/Controller/DefaultControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use AppBundle\Entity\Post;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Response;
use Tests\ControllerTestTrait;

/**
* Functional test that implements a "smoke test" of all the public and secure
Expand All @@ -28,8 +27,6 @@
*/
class DefaultControllerTest extends WebTestCase
{
use ControllerTestTrait;

/**
* PHPUnit's data providers allow to execute the same tests repeated times
* using a different set of data each time.
Expand All @@ -39,7 +36,7 @@ class DefaultControllerTest extends WebTestCase
*/
public function testPublicUrls($url)
{
$client = $this->getAnonymousClient();
$client = static::createClient();
$client->request('GET', $url);

$this->assertSame(
Expand All @@ -58,8 +55,8 @@ public function testPublicUrls($url)
*/
public function testPublicBlogPost()
{
// the service container is always available via the client
$client = $this->getAnonymousClient();
$client = static::createClient();
// the service container is always available via the test client
$blogPost = $client->getContainer()->get('doctrine')->getRepository(Post::class)->find(1);
$client->request('GET', sprintf('/en/blog/posts/%s', $blogPost->getSlug()));

Expand All @@ -75,7 +72,7 @@ public function testPublicBlogPost()
*/
public function testSecureUrls($url)
{
$client = $this->getAnonymousClient();
$client = static::createClient();
$client->request('GET', $url);

$response = $client->getResponse();
Expand Down
48 changes: 0 additions & 48 deletions tests/ControllerTestTrait.php

This file was deleted.