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.

AbstractEventSubscriberTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 108
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
createEventSubscriber() 0 1 ?
prophesizeSerializer() 0 1 ?
mockSerializationVisitor() 0 1 ?
A mockEvent() 0 9 1
B testOnPostSerialize() 0 46 1
B testOnPostSerializeWithNoLinksEmbeddeds() 0 42 1
1
<?php
2
3
namespace Hateoas\Tests\Serializer\EventSubscriber;
4
5
use Hateoas\Tests\TestCase;
6
7
abstract class AbstractEventSubscriberTest extends TestCase
8
{
9
    public function testOnPostSerialize()
10
    {
11
        $embeddeds = array(
12
            $this->prophesize('Hateoas\Model\Embedded')->reveal(),
13
        );
14
        $links = array(
15
            $this->prophesize('Hateoas\Model\Link')->reveal(),
16
        );
17
        $object = new \StdClass();
18
        $context = $this->prophesize('JMS\Serializer\SerializationContext')->reveal();
19
20
        $serializationVisitor = $this->mockSerializationVisitor();
21
22
        $serializerProphecy = $this->prophesizeSerializer();
23
        $serializerProphecy
24
            ->serializeEmbeddeds($embeddeds, $serializationVisitor, $context)
25
            ->shouldBeCalledTimes(1)
26
        ;
27
        $serializerProphecy
28
            ->serializeLinks($links, $serializationVisitor, $context)
29
            ->shouldBeCalledTimes(1)
30
        ;
31
32
        $linksFactoryProphecy = $this->prophesize('Hateoas\Factory\LinksFactory');
33
        $linksFactoryProphecy
34
            ->create($object, $context)
35
            ->willReturn($links)
36
            ->shouldBeCalledTimes(1)
37
        ;
38
39
        $embeddedsFactoryProphecy = $this->prophesize('Hateoas\Factory\EmbeddedsFactory');
40
        $embeddedsFactoryProphecy
41
            ->create($object, $context)
42
            ->willReturn($embeddeds)
43
            ->shouldBeCalledTimes(1)
44
        ;
45
46
        $eventProphecy = $this->mockEvent($object, $serializationVisitor, $context);
47
48
        $embeddedEventSubscriber = $this->createEventSubscriber(
49
            $serializerProphecy->reveal(),
50
            $linksFactoryProphecy->reveal(),
51
            $embeddedsFactoryProphecy->reveal()
52
        );
53
        $embeddedEventSubscriber->onPostSerialize($eventProphecy->reveal());
54
    }
55
56
    public function testOnPostSerializeWithNoLinksEmbeddeds()
57
    {
58
        $embeddeds = array();
59
        $links = array();
60
        $object = new \StdClass();
61
        $context = $this->prophesize('JMS\Serializer\SerializationContext')->reveal();
62
63
        $serializationVisitor = $this->mockSerializationVisitor();
64
65
        $serializerProphecy = $this->prophesizeSerializer();
66
        $serializerProphecy
67
            ->serializeEmbeddeds($embeddeds, $serializationVisitor, $context)
68
            ->shouldNotBeCalled()
69
        ;
70
        $serializerProphecy
71
            ->serializeLinks($links, $serializationVisitor)
72
            ->shouldNotBeCalled()
73
        ;
74
75
        $linksFactoryProphecy = $this->prophesize('Hateoas\Factory\LinksFactory');
76
        $linksFactoryProphecy
77
            ->create($object, $context)
78
            ->willReturn($links)
79
            ->shouldBeCalledTimes(1)
80
        ;
81
82
        $embeddedsFactoryProphecy = $this->prophesize('Hateoas\Factory\EmbeddedsFactory');
83
        $embeddedsFactoryProphecy
84
            ->create($object, $context)
85
            ->willReturn($embeddeds)
86
            ->shouldBeCalledTimes(1)
87
        ;
88
89
        $eventProphecy = $this->mockEvent($object, $serializationVisitor, $context);
90
91
        $embeddedEventSubscriber = $this->createEventSubscriber(
92
            $serializerProphecy->reveal(),
93
            $linksFactoryProphecy->reveal(),
94
            $embeddedsFactoryProphecy->reveal()
95
        );
96
        $embeddedEventSubscriber->onPostSerialize($eventProphecy->reveal());
97
    }
98
99
    abstract protected function createEventSubscriber($serializer, $linksFactory, $embeddedsFactory);
100
101
    abstract protected function prophesizeSerializer();
102
103
    abstract protected function mockSerializationVisitor();
104
105
    private function mockEvent($object, $serializationVisitor, $context)
106
    {
107
        $eventProphecy = $this->prophesize('JMS\Serializer\EventDispatcher\ObjectEvent');
108
        $eventProphecy->getObject()->willreturn($object);
109
        $eventProphecy->getVisitor()->willreturn($serializationVisitor);
110
        $eventProphecy->getContext()->willreturn($context);
111
112
        return $eventProphecy;
113
    }
114
}
115