Skip to content

Commit d930a80

Browse files
committed
Simplified example
* Removed manager interface * Replaced manager with repository
1 parent 9045699 commit d930a80

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

spec/Peterjmit/BlogBundle/Controller/BlogControllerSpec.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
use PhpSpec\ObjectBehavior;
66
use Prophecy\Argument;
77

8-
use Peterjmit\BlogBundle\Model\BlogManagerInterface;
8+
use Peterjmit\BlogBundle\Doctrine\BlogRepository;
99

1010
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
1111
use Symfony\Component\HttpFoundation\Response;
1212

1313
class BlogControllerSpec extends ObjectBehavior
1414
{
1515
function let(
16-
BlogManagerInterface $manager,
16+
BlogRepository $repository,
1717
EngineInterface $templating
1818
) {
19-
$this->beConstructedWith($manager, $templating);
19+
$this->beConstructedWith($repository, $templating);
2020
}
2121

2222
function it_is_initializable()
@@ -25,11 +25,11 @@ function it_is_initializable()
2525
}
2626

2727
function it_should_respond_to_index_action(
28-
BlogManagerInterface $manager,
28+
BlogRepository $repository,
2929
EngineInterface $templating,
3030
Response $mockResponse
3131
) {
32-
$manager->findAll()->willReturn(array('An array', 'of blog', 'posts!'));
32+
$repository->findAll()->willReturn(array('An array', 'of blog', 'posts!'));
3333

3434
$templating
3535
->renderResponse(
@@ -45,11 +45,11 @@ function it_should_respond_to_index_action(
4545
}
4646

4747
function it_shows_a_single_blog_post(
48-
BlogManagerInterface $manager,
48+
BlogRepository $repository,
4949
EngineInterface $templating,
5050
Response $response
5151
) {
52-
$manager->find(1)->willReturn('A blog post');
52+
$repository->find(1)->willReturn('A blog post');
5353

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

65-
function it_throws_an_exception_if_a_blog_post_doesnt_exist(BlogManagerInterface $manager)
65+
function it_throws_an_exception_if_a_blog_post_doesnt_exist(BlogRepository $repository)
6666
{
67-
$manager->find(999)->willReturn(null);
67+
$repository->find(999)->willReturn(null);
6868

6969
$this
7070
->shouldThrow('Symfony\Component\HttpKernel\Exception\NotFoundHttpException')

src/Peterjmit/BlogBundle/Controller/BlogController.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22

33
namespace Peterjmit\BlogBundle\Controller;
44

5-
use Peterjmit\BlogBundle\Model\BlogManagerInterface;
5+
use Peterjmit\BlogBundle\Doctrine\BlogRepository;
66
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
77
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
88

99
class BlogController
1010
{
11-
private $manager;
11+
private $repository;
1212
private $templating;
1313

14-
public function __construct(BlogManagerInterface $manager, EngineInterface $templating)
14+
public function __construct(BlogRepository $repository, EngineInterface $templating)
1515
{
16-
$this->manager = $manager;
16+
$this->repository = $repository;
1717
$this->templating = $templating;
1818
}
1919

2020
public function indexAction()
2121
{
22-
$posts = $this->manager->findAll();
22+
$posts = $this->repository->findAll();
2323

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

2929
public function showAction($id)
3030
{
31-
$post = $this->manager->find($id);
31+
$post = $this->repository->find($id);
3232

3333
if (!$post) {
3434
throw new NotFoundHttpException(sprintf('Blog post %s was not found', $id));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Peterjmit\BlogBundle\Doctrine;
4+
5+
use Doctrine\ORM\EntityRepository;
6+
use Doctrine\ORM\QueryBuilder;
7+
8+
/**
9+
* BlogRepository
10+
*
11+
* This class was generated by the Doctrine ORM. Add your own custom
12+
* repository methods below.
13+
*/
14+
class BlogRepository extends EntityRepository
15+
{
16+
}

src/Peterjmit/BlogBundle/Model/BlogManagerInterface.php

-9
This file was deleted.

0 commit comments

Comments
 (0)