GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Failed Conditions
Pull Request — master (#1)
by Pascal
02:45
created

ResponseListenerTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSkipsEventIfResponseIsControllerResult() 0 14 1
A testWillFallBackToDefaultContentTypeOnAcceptedTypeAny() 0 20 1
A testWillFallbackToDefaultContentType() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Saikootau\ApiBundle\Tests\Event\Listener;
6
7
use PHPUnit\Framework\TestCase;
8
use Prophecy\Argument;
9
use Saikootau\ApiBundle\Event\Listener\ResponseListener;
10
use Saikootau\ApiBundle\MediaType\Exception\NonNegotiableMediaTypeException;
11
use Saikootau\ApiBundle\MediaType\MediaTypeHandler;
12
use Saikootau\ApiBundle\MediaType\MediaTypeNegotiator;
13
use Saikootau\ApiBundle\MediaType\MediaTypes;
14
use Saikootau\ApiBundle\Serializer\Serializer;
15
use stdClass;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
19
20
class ResponseListenerTest extends TestCase
21
{
22
    public function testSkipsEventIfResponseIsControllerResult(): void
23
    {
24
        $mediaTypeNegotiator = $this->prophesize(MediaTypeNegotiator::class)->reveal();
25
26
        $listener = new ResponseListener(
27
            $mediaTypeNegotiator,
28
            MediaTypes::TYPE_APPLICATION_XML
29
        );
30
31
        $event = $this->prophesize(GetResponseForControllerResultEvent::class);
32
        $event->getControllerResult()->willReturn($this->prophesize(Response::class));
33
        $event->setResponse(Argument::any())->shouldNotBeCalled();
34
35
        $listener->onKernelView($event->reveal());
36
    }
37
38
    public function testWillFallbackToDefaultContentType(): void
39
    {
40
        $serializer = $this->getMockBuilder([Serializer::class, MediaTypeHandler::class])->getMock();
41
        $mediaTypeNegotiator = $this->prophesize(MediaTypeNegotiator::class);
42
        $mediaTypeNegotiator->negotiate(MediaTypes::TYPE_APPLICATION_JSON)->willThrow(new NonNegotiableMediaTypeException('application/json'));
43
        $mediaTypeNegotiator->negotiate(MediaTypes::TYPE_APPLICATION_XML)->shouldBeCalledTimes(1)->willReturn($serializer);
44
45
        $listener = new ResponseListener(
46
            $mediaTypeNegotiator->reveal(),
47
            MediaTypes::TYPE_APPLICATION_XML
48
        );
49
50
        $event = $this->prophesize(GetResponseForControllerResultEvent::class);
51
        $event->getRequest()->willReturn(Request::create('/', Request::METHOD_GET, [], [], [], [
52
            'HTTP_ACCEPT' => 'application/json;q=0.8',
53
        ]));
54
        $event->getControllerResult()->willReturn(new stdClass());
55
        $event->setResponse(Argument::type(Response::class))->shouldBeCalled();
56
57
        $listener->onKernelView($event->reveal());
58
    }
59
60
    public function testWillFallBackToDefaultContentTypeOnAcceptedTypeAny(): void
61
    {
62
        $serializer = $this->getMockBuilder([Serializer::class, MediaTypeHandler::class])->getMock();
63
        $mediaTypeNegotiator = $this->prophesize(MediaTypeNegotiator::class);
64
        $mediaTypeNegotiator->negotiate(MediaTypes::TYPE_APPLICATION_XML)->shouldBeCalledTimes(1)->willReturn($serializer);
65
66
        $listener = new ResponseListener(
67
            $mediaTypeNegotiator->reveal(),
68
            MediaTypes::TYPE_APPLICATION_XML
69
        );
70
71
        $event = $this->prophesize(GetResponseForControllerResultEvent::class);
72
        $event->getRequest()->willReturn(Request::create('/', Request::METHOD_GET, [], [], [], [
73
            'HTTP_ACCEPT' => '*/*;q=0.8',
74
        ]));
75
        $event->getResponse()->willReturn(null);
76
        $event->getControllerResult()->willReturn(new stdClass());
77
        $event->setResponse(Argument::type(Response::class))->shouldBeCalled();
78
79
        $listener->onKernelView($event->reveal());
80
    }
81
}
82