Skip to content
Permalink
Browse files

Removed container dependency from controller

  • Loading branch information
peterjmit committed Sep 4, 2013
1 parent e44c1fa commit 3d5de3432698af520eb30c915e278d39bf53093a
@@ -5,8 +5,6 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

use Symfony\Component\DependencyInjection\ContainerInterface;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\ObjectRepository;
@@ -17,20 +15,15 @@
class BlogControllerSpec extends ObjectBehavior
{
function let(
ContainerInterface $container,
ManagerRegistry $registry,
ObjectManager $manager,
ObjectRepository $repository,
EngineInterface $templating
) {
$container->has('doctrine')->willReturn(true);
$container->get('doctrine')->willReturn($registry);
$container->get('templating')->willReturn($templating);

$registry->getManager()->willReturn($manager);
$manager->getRepository('PeterjmitBlogBundle:Blog')->willReturn($repository);

$this->setContainer($container);
$this->beConstructedWith($registry, $templating);
}

function it_is_initializable()
@@ -48,8 +41,7 @@ function it_should_respond_to_index_action(
$templating
->renderResponse(
'PeterjmitBlogBundle:Blog:index.html.twig',
array('posts' => array()),
null
array('posts' => array())
)
->willReturn($mockResponse)
;
@@ -2,30 +2,40 @@

namespace Peterjmit\BlogBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;

class BlogController extends Controller
class BlogController
{
private $doctrine;
private $templating;

public function __construct(ManagerRegistry $doctrine, EngineInterface $templating)
{
$this->doctrine = $doctrine;
$this->templating = $templating;
}

public function indexAction()
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager = $this->doctrine->getManager();
$posts = $entityManager->getRepository('PeterjmitBlogBundle:Blog')->findAll();

return $this->render('PeterjmitBlogBundle:Blog:index.html.twig', array(
return $this->templating->renderResponse('PeterjmitBlogBundle:Blog:index.html.twig', array(
'posts' => $posts
));
}

public function showAction($id)
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager = $this->doctrine->getManager();
$post = $entityManager->getRepository('PeterjmitBlogBundle:Blog')->find($id);

if (!$post) {
throw $this->createNotFoundException(sprintf('Blog post %s was not found', $id));
}

return $this->render('PeterjmitBlogBundle:Blog:show.html.twig', array(
return $this->templating->renderResponse('PeterjmitBlogBundle:Blog:show.html.twig', array(
'posts' => $posts
));
}

0 comments on commit 3d5de34

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