Skip to content
Permalink
Browse files

Simplified example

* Removed manager interface
* Replaced manager with repository
  • Loading branch information
peterjmit committed Sep 10, 2013
1 parent 9045699 commit d930a806641a10706c2ed2d61219de660a8e93bb
@@ -5,18 +5,18 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

use Peterjmit\BlogBundle\Model\BlogManagerInterface;
use Peterjmit\BlogBundle\Doctrine\BlogRepository;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;

class BlogControllerSpec extends ObjectBehavior
{
function let(
BlogManagerInterface $manager,
BlogRepository $repository,
EngineInterface $templating
) {
$this->beConstructedWith($manager, $templating);
$this->beConstructedWith($repository, $templating);
}

function it_is_initializable()
@@ -25,11 +25,11 @@ function it_is_initializable()
}

function it_should_respond_to_index_action(
BlogManagerInterface $manager,
BlogRepository $repository,
EngineInterface $templating,
Response $mockResponse
) {
$manager->findAll()->willReturn(array('An array', 'of blog', 'posts!'));
$repository->findAll()->willReturn(array('An array', 'of blog', 'posts!'));

$templating
->renderResponse(
@@ -45,11 +45,11 @@ function it_should_respond_to_index_action(
}

function it_shows_a_single_blog_post(
BlogManagerInterface $manager,
BlogRepository $repository,
EngineInterface $templating,
Response $response
) {
$manager->find(1)->willReturn('A blog post');
$repository->find(1)->willReturn('A blog post');

$templating
->renderResponse(
@@ -62,9 +62,9 @@ function it_shows_a_single_blog_post(
$this->showAction(1)->shouldReturn($response);
}

function it_throws_an_exception_if_a_blog_post_doesnt_exist(BlogManagerInterface $manager)
function it_throws_an_exception_if_a_blog_post_doesnt_exist(BlogRepository $repository)
{
$manager->find(999)->willReturn(null);
$repository->find(999)->willReturn(null);

$this
->shouldThrow('Symfony\Component\HttpKernel\Exception\NotFoundHttpException')
@@ -2,24 +2,24 @@

namespace Peterjmit\BlogBundle\Controller;

use Peterjmit\BlogBundle\Model\BlogManagerInterface;
use Peterjmit\BlogBundle\Doctrine\BlogRepository;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class BlogController
{
private $manager;
private $repository;
private $templating;

public function __construct(BlogManagerInterface $manager, EngineInterface $templating)
public function __construct(BlogRepository $repository, EngineInterface $templating)
{
$this->manager = $manager;
$this->repository = $repository;
$this->templating = $templating;
}

public function indexAction()
{
$posts = $this->manager->findAll();
$posts = $this->repository->findAll();

return $this->templating->renderResponse('PeterjmitBlogBundle:Blog:index.html.twig', array(
'posts' => $posts
@@ -28,7 +28,7 @@ public function indexAction()

public function showAction($id)
{
$post = $this->manager->find($id);
$post = $this->repository->find($id);

if (!$post) {
throw new NotFoundHttpException(sprintf('Blog post %s was not found', $id));
@@ -0,0 +1,16 @@
<?php

namespace Peterjmit\BlogBundle\Doctrine;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;

/**
* BlogRepository
*
* This class was generated by the Doctrine ORM. Add your own custom
* repository methods below.
*/
class BlogRepository extends EntityRepository
{
}

This file was deleted.

0 comments on commit d930a80

Please sign in to comment.
You can’t perform that action at this time.