60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace App\Tests\Web;
 | 
						|
 | 
						|
use App\Tests\Common\DatabaseTestTrait;
 | 
						|
use App\Tests\Common\FakerTrait;
 | 
						|
use App\Tests\Common\Generators\CommentGeneratorTrait;
 | 
						|
use App\Tests\Common\Generators\PostGeneratorTrait;
 | 
						|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
 | 
						|
use Symfony\Component\BrowserKit\AbstractBrowser;
 | 
						|
 | 
						|
class DetailPostControllerTest extends WebTestCase
 | 
						|
{
 | 
						|
    use DatabaseTestTrait;
 | 
						|
    use FakerTrait;
 | 
						|
    use PostGeneratorTrait;
 | 
						|
    use CommentGeneratorTrait;
 | 
						|
 | 
						|
    protected AbstractBrowser $client;
 | 
						|
 | 
						|
    protected function setUp(): void
 | 
						|
    {
 | 
						|
        $this->client = static::createClient();
 | 
						|
        $this->bootDatabase();
 | 
						|
        $this->bootFaker();
 | 
						|
        $this->getFaker()->unique();
 | 
						|
    }
 | 
						|
 | 
						|
    public function testPostDetail(): void
 | 
						|
    {
 | 
						|
        $post = $this->createPost(1);
 | 
						|
        $comments = [];
 | 
						|
        $comments[] = $this->createComment(1, $post);
 | 
						|
        $comments[] = $this->createComment(2, $post);
 | 
						|
 | 
						|
        $this->client->request('GET', '/posts/detail/1');
 | 
						|
 | 
						|
        $this->assertResponseIsSuccessful();
 | 
						|
        $this->assertSelectorTextSame('.t-title', $post->title);
 | 
						|
        $this->assertSelectorTextSame('.t-content', $post->body);
 | 
						|
 | 
						|
        $this->assertSelectorTextSame('.t-user-name', $post->user->name);
 | 
						|
        $this->assertSelectorTextSame('.t-user-email', $post->user->email);
 | 
						|
        $this->assertSelectorTextSame('.t-user-website', $post->user->website);
 | 
						|
        $this->assertSelectorTextSame('.t-user-company', $post->user->company->name);
 | 
						|
        $this->assertSelectorCount(2, '.t-comment');
 | 
						|
        $this->assertSelectorTextSame('.t-comment:nth-child(1) .t-comment-name', $comments[0]->name);
 | 
						|
        $this->assertSelectorTextSame('.t-comment:nth-child(1) .t-comment-email', $comments[0]->email);
 | 
						|
        $this->assertSelectorTextSame('.t-comment:nth-child(1) .t-comment-body', $comments[0]->body);
 | 
						|
    }
 | 
						|
 | 
						|
    public function testPostDetailNotFound(): void
 | 
						|
    {
 | 
						|
        $this->client->request('GET', '/posts/detail/100');
 | 
						|
        $this->assertResponseStatusCodeSame(404);
 | 
						|
    }
 | 
						|
}
 |