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 (#563)
by Asmir
05:10
created

testLazyExtensionNotLoadedWhenOldSerializer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
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\SerializerBundle\DependencyInjection\Compiler\TwigExtensionPass;
22
use JMS\SerializerBundle\DependencyInjection\JMSSerializerExtension;
23
use Symfony\Component\DependencyInjection\Compiler\RemoveUnusedDefinitionsPass;
24
use Symfony\Component\DependencyInjection\Compiler\ResolveDefinitionTemplatesPass;
25
use Symfony\Component\DependencyInjection\Compiler\ResolveParameterPlaceHoldersPass;
26
use Symfony\Component\DependencyInjection\ContainerBuilder;
27
28
class TwigExtensionPassTest extends \PHPUnit_Framework_TestCase
29
{
30
    /**
31
     * @return ContainerBuilder
32
     */
33 View Code Duplication
    private function getContainer()
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...
34
    {
35
        $loader = new JMSSerializerExtension();
36
        $container = new ContainerBuilder();
37
38
        $container->getCompilerPassConfig()->setOptimizationPasses(array(
39
            new ResolveParameterPlaceHoldersPass(),
40
            new ResolveDefinitionTemplatesPass(),
41
        ));
42
        $container->getCompilerPassConfig()->setRemovingPasses(array(new RemoveUnusedDefinitionsPass()));
43
44
        $container->setParameter('kernel.debug', true);
45
        $container->setParameter('kernel.cache_dir', sys_get_temp_dir() . '/serializer');
46
        $container->setParameter('kernel.bundles', array());
47
48
        $loader->load([[]], $container);
49
        return $container;
50
    }
51
52
    public function testStandardExtension()
53
    {
54
        $container = $this->getContainer();
55
56
        $pass = new TwigExtensionPass();
57
        $pass->process($container);
58
59
        $extension = $container->getDefinition('jms_serializer.twig_extension.serializer');
60
        $this->assertEquals('%jms_serializer.twig_extension.class%', (string)$extension->getClass());
61
        $this->assertCount(1, $extension->getArguments());
62
63
        $this->assertFalse($container->hasDefinition('jms_serializer.twig_extension.serializer_runtime_helper'));
64
    }
65
66
    public function testLazyExtension()
67
    {
68
        if (!class_exists('JMS\Serializer\Twig\SerializerRuntimeExtension')) {
69
            $this->markTestSkipped("Lazy extensions are supported only by serializer 1.7.0");
70
        }
71
        $container = $this->getContainer();
72
73
        $container->register('twig.runtime_loader');
74
75
        $pass = new TwigExtensionPass();
76
        $pass->process($container);
77
78
        $extension = $container->getDefinition('jms_serializer.twig_extension.serializer');
79
        $this->assertEquals('%jms_serializer.twig_runtime_extension.class%', (string)$extension->getClass());
80
        $this->assertCount(0, $extension->getArguments());
81
82
        $this->assertTrue($container->hasDefinition('jms_serializer.twig_extension.serializer_runtime_helper'));
83
    }
84
85
    public function testLazyExtensionNotLoadedWhenOldSerializer()
86
    {
87
        $container = $this->getContainer();
88
89
        $container->getParameterBag()->add(array(
90
            'jms_serializer.twig_runtime_extension.class' => 'foo',
91
            'jms_serializer.twig_runtime_extension_helper.class' => 'bar',
92
        ));
93
94
        $container->register('twig.runtime_loader');
95
96
        $pass = new TwigExtensionPass();
97
        $pass->process($container);
98
99
        $extension = $container->getDefinition('jms_serializer.twig_extension.serializer');
100
        $this->assertEquals('%jms_serializer.twig_extension.class%', (string)$extension->getClass());
101
        $this->assertCount(1, $extension->getArguments());
102
103
        $this->assertFalse($container->hasDefinition('jms_serializer.twig_extension.serializer_runtime_helper'));
104
    }
105
}
106
107