Last active
April 3, 2017 06:21
-
-
Save symball/2d3155bffee7079f6428ab538061f895 to your computer and use it in GitHub Desktop.
PHPUnit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\AppBundle\Functional\Process; | |
/* The kernel test case we'll be using */ | |
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | |
use AppBundle\Entity\Post; | |
use AppBundle\Repository\PostRepository; | |
class BlogFunctionalProcessTest extends KernelTestCase | |
{ | |
protected $container; | |
public function setUp() | |
{ | |
$firstPost = $this->createMock(Post::class); | |
$firstPost->expects($this->once()) | |
->method('getTitle') | |
->will($this->returnValue('First Post')); | |
$secondPost = $this->createMock(Post::class); | |
$secondPost->expects($this->once()) | |
->method('getTitle') | |
->will($this->returnValue('Second Post')); | |
$postRepository = $this | |
->getMockBuilder(PostRepository::class) | |
->setMethods(['find', 'findAllOrderedByDate']) | |
->disableOriginalConstructor() | |
->getMock(); | |
$postRepository->expects($this->once()) | |
->method('find') | |
->will($this->returnValue($firstPost)); | |
$postRepository | |
->expects($this->once()) | |
->method('findAllOrderedByDate') | |
->will($this->returnValue([$firstPost,$secondPost])); | |
/* Overwrite the service definition for the repository */ | |
$kernel = static::createKernel(); | |
$kernel->boot(); | |
$this->container = $kernel->getContainer(); | |
$this->container->set('app.repository.post', $postRepository); | |
} | |
public function testPostRead() | |
{ | |
$blogManager = $this->container->get('app.service.blog_manager'); | |
$post = $blogManager->fetchPost('First Post'); | |
$this->assertEquals('First Post', $post->getTitle()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment