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
Pull Request — master (#552)
by Asmir
03:11
created

CustomHandlerPassTest::testHandlerDirection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 9.3142
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
/*
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace JMS\SerializerBundle\Tests\DependencyInjection;
20
21
use JMS\Serializer\Exception\RuntimeException;
22
use JMS\SerializerBundle\DependencyInjection\Compiler\CustomHandlersPass;
23
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
24
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
25
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
26
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
27
use Symfony\Component\DependencyInjection\ContainerBuilder;
28
use Symfony\Component\DependencyInjection\Definition;
29
30
class CustomHandlerPassTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @param array $configs
34
     * @return ContainerBuilder
35
     */
36 View Code Duplication
    private function getContainer(array $configs = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $loader = new JMSSerializerExtension();
39
        $container = new ContainerBuilder();
40
41
        $container->getCompilerPassConfig()->setOptimizationPasses(array(
42
            new ResolveParameterPlaceHoldersPass(),
43
            new ResolveDefinitionTemplatesPass(),
44
        ));
45
        $container->getCompilerPassConfig()->setRemovingPasses(array(new RemoveUnusedDefinitionsPass()));
46
47
        $container->setParameter('kernel.debug', true);
48
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
49
        $container->setParameter('kernel.bundles', array());
50
        $container->setParameter('kernel.bundles', array());
51
52
        $loader->load(['jms_serializer' => $configs], $container);
53
54
        // remove other subscribers
55
        foreach (array_keys($container->findTaggedServiceIds('jms_serializer.handler')) as $id) {
56
            $container->removeDefinition($id);
57
        }
58
        foreach (array_keys($container->findTaggedServiceIds('jms_serializer.subscribing_handler')) as $id) {
59
            $container->removeDefinition($id);
60
        }
61
62
        return $container;
63
    }
64
65
    public function testHandler()
66
    {
67
        $container = $this->getContainer();
68
69
        $def = new Definition('Foo');
70
        $def->addTag('jms_serializer.handler', [
71
            'type' => 'DateTime',
72
            'format' => 'json',
73
        ]);
74
        $container->setDefinition('my_service', $def);
75
76
        $pass = new CustomHandlersPass();
77
        $pass->process($container);
78
79
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
80
81
        $this->assertEquals([
82
            2 => ['DateTime' => ['json' => ['my_service', 'deserializeDateTimeFromjson']]],
83
            1 => ['DateTime' => ['json' => ['my_service', 'serializeDateTimeTojson']]]
84
        ], $args[1]);
85
    }
86
87
    public function testHandlerDirection()
88
    {
89
        $container = $this->getContainer();
90
91
        $def = new Definition('Foo');
92
        $def->addTag('jms_serializer.handler', [
93
            'type' => 'DateTime',
94
            'format' => 'json',
95
            'direction' => 'SERIALIZATION',
96
        ]);
97
        $container->setDefinition('my_service', $def);
98
99
        $pass = new CustomHandlersPass();
100
        $pass->process($container);
101
102
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
103
104
        $this->assertEquals([
105
            1 => ['DateTime' => ['json' => ['my_service', 'serializeDateTimeTojson']]]
106
        ], $args[1]);
107
    }
108
109
    /**
110
     * @expectedException RuntimeException
111
     * @expectedExceptionMessage The direction "bar" of tag "jms_serializer.handler" of service "my_service" does not exist
112
     */
113
    public function testHandlerIncorrectDirection()
114
    {
115
        $container = $this->getContainer();
116
117
        $def = new Definition('Foo');
118
        $def->addTag('jms_serializer.handler', [
119
            'type' => 'DateTime',
120
            'format' => 'json',
121
            'direction' => 'bar',
122
        ]);
123
        $container->setDefinition('my_service', $def);
124
125
        $pass = new CustomHandlersPass();
126
        $pass->process($container);
127
    }
128
129
    /**
130
     * @expectedException RuntimeException
131
     * @expectedExceptionMessage Each tag named "jms_serializer.handler" of service "my_service" must have at least two attributes: "type" and "format"
132
     */
133 View Code Duplication
    public function testHandlerMustHaveTypeAndFormat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        $container = $this->getContainer();
136
137
        $def = new Definition('Foo');
138
        $def->addTag('jms_serializer.handler');
139
        $container->setDefinition('my_service', $def);
140
141
        $pass = new CustomHandlersPass();
142
        $pass->process($container);
143
    }
144
145
    public function testSubscribingHandler()
146
    {
147
        $container = $this->getContainer();
148
149
        $def = new Definition('JMS\SerializerBundle\Tests\DependencyInjection\Fixture\SubscribingHandler');
150
        $def->addTag('jms_serializer.subscribing_handler');
151
        $container->setDefinition('my_service', $def);
152
153
        $pass = new CustomHandlersPass();
154
        $pass->process($container);
155
156
        $args = $container->getDefinition('jms_serializer.handler_registry')->getArguments();
157
158
        $this->assertEquals([
159
            1 => ['DateTime' => ['json' => ['my_service', 'onDateTime']]]
160
        ], $args[1]);
161
    }
162
163
    /**
164
     * @expectedException RuntimeException
165
     * @expectedExceptionMessage The service "my_service" must implement the SubscribingHandlerInterface
166
     */
167 View Code Duplication
    public function testSubscribingHandlerInterface()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
    {
169
        $container = $this->getContainer();
170
171
        $def = new Definition('JMS\SerializerBundle\Tests\DependencyInjection\Fixture\SimpleObject');
172
        $def->addTag('jms_serializer.subscribing_handler');
173
        $container->setDefinition('my_service', $def);
174
175
        $pass = new CustomHandlersPass();
176
        $pass->process($container);
177
    }
178
}
179