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.
Completed
Push — master ( 1978d2...e2f699 )
by William
03:55
created

Hateoas/Tests/Serializer/ExclusionManagerTest.php (2 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Hateoas\Tests\Serializer;
4
5
use Hateoas\Configuration\Exclusion;
6
use Hateoas\Configuration\Relation;
7
use Hateoas\Serializer\ExclusionManager;
8
use JMS\Serializer\Context;
9
use JMS\Serializer\SerializationContext;
10
use Hateoas\Tests\TestCase;
11
12
class ExclusionManagerTest extends TestCase
13
{
14 View Code Duplication
    public function testDoesNotSkipNonNullEmbedded()
15
    {
16
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
17
18
        $object = new \StdClass();
19
        $relation = new Relation('foo', 'foo', 'foo');
20
        $context = SerializationContext::create();
21
22
        $this
23
            ->boolean($exclusionManager->shouldSkipEmbedded($object, $relation, $context))
24
                ->isFalse()
25
        ;
26
    }
27
28 View Code Duplication
    public function testSkipNullEmbedded()
29
    {
30
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
31
32
        $object = new \StdClass();
33
        $relation = new Relation('foo', 'foo');
34
        $context = SerializationContext::create();
35
36
        $this
37
            ->boolean($exclusionManager->shouldSkipEmbedded($object, $relation, $context))
38
                ->isTrue()
39
        ;
40
    }
41
42 View Code Duplication
    public function testDoesNotSkipNonNullLink()
43
    {
44
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
45
46
        $object = new \StdClass();
47
        $relation = new Relation('foo', 'foo');
48
        $context = SerializationContext::create();
49
50
        $this
51
            ->boolean($exclusionManager->shouldSkipLink($object, $relation, $context))
52
                ->isFalse()
53
        ;
54
    }
55
56 View Code Duplication
    public function testSkipNullLink()
57
    {
58
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
59
60
        $object = new \StdClass();
61
        $relation = new Relation('foo', null, 'foo');
62
        $context = SerializationContext::create();
63
64
        $this
65
            ->boolean($exclusionManager->shouldSkipLink($object, $relation, $context))
66
                ->isTrue()
67
        ;
68
    }
69
70
    public function testSkip()
71
    {
72
        $test = $this;
73
        $exclusionStrategyCallback = function ($args) use ($test) {
74
            $test
75
                ->array($args[0]->groups)
76
                    ->isEqualTo(array('foo', 'bar'))
77
                ->float($args[0]->sinceVersion)
78
                    ->isEqualTo(1.1)
79
                ->float($args[0]->untilVersion)
80
                    ->isEqualTo(1.7)
81
                ->integer($args[0]->maxDepth)
82
                    ->isEqualTo(77)
83
            ;
84
        };
85
86
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
87
        $exclusionStrategy = $this->mockExclusionStrategy(true, $exclusionStrategyCallback, 2);
88
89
        $object = new \StdClass();
90
        $exclusion = new Exclusion(
91
            array('foo', 'bar'),
92
            1.1,
93
            1.7,
94
            77
95
        );
96
        $relation = new Relation('foo', 'foo', 'foo', array(), $exclusion);
97
        $context = SerializationContext::create()
98
            ->addExclusionStrategy($exclusionStrategy)
99
        ;
100
101
        $this
0 ignored issues
show
The method boolean() does not exist on mageekguy\atoum\asserters\boolean. Did you maybe mean isBoolean()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
102
            ->boolean($exclusionManager->shouldSkipLink($object, $relation, $context))
103
                ->isTrue()
104
            ->boolean($exclusionManager->shouldSkipEmbedded($object, $relation, $context))
105
                ->isTrue()
106
        ;
107
    }
108
109 View Code Duplication
    public function testSkipEmbedded()
110
    {
111
        $exclusionManager = new ExclusionManager($this->mockExpressionEvaluator());
112
113
        $object = new \StdClass();
114
        $relation = new Relation('foo', 'foo', 'foo');
115
        $context = SerializationContext::create()
116
            ->addExclusionStrategy($this->mockExclusionStrategy(true))
117
        ;
118
119
        $this
120
            ->boolean($exclusionManager->shouldSkipEmbedded($object, $relation, $context))
121
                ->isTrue()
122
        ;
123
    }
124
125
    /**
126
     * @dataProvider getTestSkipExcludeIfData
127
     */
128
    public function testSkipExcludeIf($exclude)
129
    {
130
        $object = (object) array('name' => 'adrien');
131
        $exclusion = new Exclusion(null, null, null, null, 'expr(stuff)');
132
        $relation = new Relation('foo', 'foo', 'foo', array(), $exclusion);
133
        $context = SerializationContext::create();
134
135
        $expressionEvaluatorProphecy = $this->prophesizeExpressionEvaluator();
136
        $expressionEvaluatorProphecy
137
            ->evaluate('expr(stuff)', $object)
138
            ->willReturn($exclude)
139
        ;
140
        $exclusionManager = new ExclusionManager($expressionEvaluatorProphecy->reveal());
141
142
        $this
0 ignored issues
show
The method boolean() does not exist on mageekguy\atoum\asserters\boolean. Did you maybe mean isBoolean()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
143
            ->boolean($exclusionManager->shouldSkipLink($object, $relation, $context))
144
                ->isEqualTo($exclude)
145
            ->boolean($exclusionManager->shouldSkipEmbedded($object, $relation, $context))
146
                ->isEqualTo($exclude)
147
        ;
148
    }
149
150
    public function getTestSkipExcludeIfData()
151
    {
152
        return array(
153
            array(true),
154
            array(false),
155
        );
156
    }
157
158
    /**
159
     * @param \Closure $shouldSkipPropertyCallback
160
     * @param integer $calledTimes
161
     */
162
    private function mockExclusionStrategy($shouldSkipProperty = false, $shouldSkipPropertyCallback = null, $calledTimes = null)
163
    {
164
        $exclusionStrategyProphecy = $this->prophesize('JMS\Serializer\Exclusion\ExclusionStrategyInterface');
165
        $method = $exclusionStrategyProphecy
166
            ->shouldSkipProperty(
167
                $this->arg->type('Hateoas\Serializer\Metadata\RelationPropertyMetadata'),
168
                $this->arg->type('JMS\Serializer\SerializationContext')
169
            )
170
            ->will(function () use ($shouldSkipProperty, $shouldSkipPropertyCallback) {
171
                if (null !== $shouldSkipPropertyCallback) {
172
                    call_user_func_array($shouldSkipPropertyCallback, func_get_args());
173
                }
174
175
                return $shouldSkipProperty;
176
            })
177
        ;
178
179
        if (null !== $calledTimes) {
180
            $method->shouldBeCalledTimes($calledTimes);
181
        }
182
183
        return $exclusionStrategyProphecy->reveal();
184
    }
185
186
    private function mockExpressionEvaluator()
187
    {
188
        return $this->prophesizeExpressionEvaluator()->reveal();
189
    }
190
191
    private function prophesizeExpressionEvaluator()
192
    {
193
        return $this->prophesize('Hateoas\Expression\ExpressionEvaluator');
194
    }
195
}
196