Passed
Branch master (bb3df7)
by Theo
01:32
created

CalendarControllerSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\CalendarBundle\Controller;
4
5
use CalendarBundle\CalendarEvents;
6
use CalendarBundle\Controller\CalendarController;
7
use CalendarBundle\Entity\Event;
8
use CalendarBundle\Event\CalendarEvent;
9
use CalendarBundle\Serializer\SerializerInterface;
10
use PhpSpec\ObjectBehavior;
11
use Prophecy\Argument;
12
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
17
class CalendarControllerSpec extends ObjectBehavior
18
{
19
    public function let(
20
        EventDispatcherInterface $eventDispatcher,
21
        SerializerInterface $serializer
22
    ) {
23
        $this->beConstructedWith($eventDispatcher, $serializer);
24
    }
25
26
    public function it_is_initializable()
27
    {
28
        $this->shouldHaveType(CalendarController::class);
29
    }
30
31
    public function it_is_a_Symfony_controller()
32
    {
33
        $this->shouldHaveType(AbstractController::class);
34
    }
35
36
    public function it_provides_an_events_feed_for_a_calendar(
37
        CalendarEvent $calendarEvent,
38
        Event $event,
39
        EventDispatcherInterface $eventDispatcher,
40
        Request $request,
41
        SerializerInterface $serializer
42
    ) {
43
        $request->get('start')->willReturn('2016-03-01');
44
        $request->get('end')->willReturn('2016-03-19 15:11:00');
45
        $request->get('filters', [])->willReturn([]);
46
        $events = [$event];
47
48
        $eventDispatcher
49
            ->dispatch(CalendarEvents::SET_DATA, Argument::type(CalendarEvent::class))
0 ignored issues
show
Bug introduced by
Prophecy\Argument::type(...t\CalendarEvent::class) of type Prophecy\Argument\Token\TypeToken is incompatible with the type Symfony\Component\EventDispatcher\Event|null expected by parameter $event of Symfony\Component\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
            ->dispatch(CalendarEvents::SET_DATA, /** @scrutinizer ignore-type */ Argument::type(CalendarEvent::class))
Loading history...
50
            ->shouldBeCalled()
0 ignored issues
show
Bug introduced by
The method shouldBeCalled() does not exist on Symfony\Component\EventDispatcher\Event. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
            ->/** @scrutinizer ignore-call */ shouldBeCalled()

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
            ->willReturn($calendarEvent);
52
53
        $data = <<<'JSON'
54
  [
55
    {
56
      "title": "Birthday!",
57
      "start": "2016-03-01",
58
      "allDay": true,
59
    }, {
60
      "title": "Flight to somewhere sunny",
61
      "start": "2016-03-12T08:55:00Z",
62
      "allDay": false,
63
      "end": "2016-03-12T11:50:00Z"
64
    }
65
  ]
66
JSON;
67
68
        $calendarEvent->getEvents()->shouldBeCalled()->willReturn($events);
69
        $serializer->serialize($events)->shouldBeCalled()->willReturn($data);
70
71
        $response = new Response();
72
        $response->headers->set('Content-Type', 'application/json');
73
        $response->setContent($data);
74
        $response->setStatusCode(Response::HTTP_OK);
75
76
        $this->loadAction($request)->shouldBeLike($response);
0 ignored issues
show
Bug introduced by
The method loadAction() does not exist on Tests\CalendarBundle\Con...\CalendarControllerSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        $this->/** @scrutinizer ignore-call */ 
77
               loadAction($request)->shouldBeLike($response);
Loading history...
77
    }
78
79
    public function it_not_find_any_events(
80
        CalendarEvent $calendarEvent,
81
        EventDispatcherInterface $eventDispatcher,
82
        Request $request,
83
        SerializerInterface $serializer
84
    ) {
85
        $request->get('start')->willReturn('2016-03-01');
86
        $request->get('end')->willReturn('2016-03-19 15:11:00');
87
        $request->get('filters', [])->willReturn([]);
88
        $events = [];
89
90
        $eventDispatcher
91
            ->dispatch(CalendarEvents::SET_DATA, Argument::type(CalendarEvent::class))
0 ignored issues
show
Bug introduced by
Prophecy\Argument::type(...t\CalendarEvent::class) of type Prophecy\Argument\Token\TypeToken is incompatible with the type Symfony\Component\EventDispatcher\Event|null expected by parameter $event of Symfony\Component\EventD...erInterface::dispatch(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

91
            ->dispatch(CalendarEvents::SET_DATA, /** @scrutinizer ignore-type */ Argument::type(CalendarEvent::class))
Loading history...
92
            ->shouldBeCalled()
93
            ->willReturn($calendarEvent);
94
95
        $data = '';
96
97
        $calendarEvent->getEvents()->shouldBeCalled()->willReturn($events);
98
        $serializer->serialize($events)->shouldBeCalled()->willReturn($data);
99
100
        $response = new Response();
101
        $response->headers->set('Content-Type', 'application/json');
102
        $response->setContent($data);
103
        $response->setStatusCode(Response::HTTP_NO_CONTENT);
104
105
        $this->loadAction($request)->shouldBeLike($response);
106
    }
107
}
108