-
Notifications
You must be signed in to change notification settings - Fork 1
/
BlogControllerSpec.php
74 lines (59 loc) · 2 KB
/
BlogControllerSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace spec\Peterjmit\BlogBundle\Controller;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Peterjmit\BlogBundle\Doctrine\BlogRepository;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Component\HttpFoundation\Response;
class BlogControllerSpec extends ObjectBehavior
{
function let(
BlogRepository $repository,
EngineInterface $templating
) {
$this->beConstructedWith($repository, $templating);
}
function it_is_initializable()
{
$this->shouldHaveType('Peterjmit\BlogBundle\Controller\BlogController');
}
function it_should_respond_to_index_action(
BlogRepository $repository,
EngineInterface $templating,
Response $mockResponse
) {
$repository->findAll()->willReturn(array('An array', 'of blog', 'posts!'));
$templating
->renderResponse(
'PeterjmitBlogBundle:Blog:index.html.twig',
array('posts' => array('An array', 'of blog', 'posts!'))
)
->willReturn($mockResponse)
;
$response = $this->indexAction();
$response->shouldHaveType('Symfony\Component\HttpFoundation\Response');
}
function it_shows_a_single_blog_post(
BlogRepository $repository,
EngineInterface $templating,
Response $response
) {
$repository->find(1)->willReturn('A blog post');
$templating
->renderResponse(
'PeterjmitBlogBundle:Blog:show.html.twig',
Argument::withEntry('post', 'A blog post')
)
->willReturn($response)
;
$this->showAction(1)->shouldReturn($response);
}
function it_throws_an_exception_if_a_blog_post_doesnt_exist(BlogRepository $repository)
{
$repository->find(999)->willReturn(null);
$this
->shouldThrow('Symfony\Component\HttpKernel\Exception\NotFoundHttpException')
->duringShowAction(999)
;
}
}