Passed
Pull Request — master (#81)
by
unknown
04:38 queued 01:05
created

GesdinetJWTRefreshTokenExtensionSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 102
Duplicated Lines 38.24 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 5
dl 39
loc 102
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 1
A it_is_initializable() 0 4 1
B it_should_set_parameters_correctly() 0 27 1
A it_should_configure_the_default_naming_generator() 0 17 1
A it_should_throw_an_exception_if_specifying_a_non_existent_name_generator_service() 18 18 1
A it_should_configure_a_custom_name_generator() 21 21 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace spec\Gesdinet\JWTRefreshTokenBundle\DependencyInjection;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
use Symfony\Component\DependencyInjection\Alias;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
10
class GesdinetJWTRefreshTokenExtensionSpec extends ObjectBehavior
11
{
12
    public function let(ContainerBuilder $container)
13
    {
14
        $container->fileExists(dirname(dirname(__DIR__)).'/DependencyInjection/../Resources/config/services.yml')
15
                  ->willReturn(true);
16
        $container->has('gesdinet.jwtrefreshtoken.name_generator.underscore')
17
                  ->willReturn(true);
18
    }
19
20
    public function it_is_initializable()
21
    {
22
        $this->shouldHaveType('Gesdinet\JWTRefreshTokenBundle\DependencyInjection\GesdinetJWTRefreshTokenExtension');
23
    }
24
25
    public function it_should_set_parameters_correctly(ContainerBuilder $container)
26
    {
27
        // setParameter calls with default values
28
        $container->setParameter('gesdinet_jwt_refresh_token.ttl', 2592000)
29
                  ->shouldBeCalled();
30
        $container->setParameter('gesdinet_jwt_refresh_token.ttl_update', false)
31
                  ->shouldBeCalled();
32
        $container->setParameter('gesdinet_jwt_refresh_token.security.firewall', 'api')
33
                  ->shouldBeCalled();
34
        $container->setParameter('gesdinet_jwt_refresh_token.user_provider', null)
35
                  ->shouldBeCalled();
36
        $container->setParameter('gesdinet.jwtrefreshtoken.refresh_token.class', 'Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken')
37
                  ->shouldBeCalled();
38
        $container->setParameter('gesdinet.jwtrefreshtoken.entity_manager.id', 'doctrine.orm.entity_manager')
39
                  ->shouldBeCalled();
40
41
        // Ignore these calls
42
        $container->has(Argument::cetera())
43
                  ->willReturn();
44
        $container->setDefinition(Argument::cetera())
45
                  ->willReturn();
46
        $container->setAlias(Argument::cetera())
47
                  ->willReturn();
48
49
        $configs = array();
50
        $this->load($configs, $container);
51
    }
52
53
    public function it_should_configure_the_default_naming_generator(ContainerBuilder $container)
54
    {
55
        $container->setAlias(
56
            'gesdinet.jwtrefreshtoken.name_generator.default',
57
            Argument::exact(new Alias('gesdinet.jwtrefreshtoken.name_generator.underscore'))
58
        )
59
                  ->shouldBeCalled();
60
61
        // Ignore these calls
62
        $container->setParameter(Argument::cetera())
63
                  ->willReturn();
64
        $container->setDefinition(Argument::cetera())
65
                  ->willReturn();
66
67
        $configs = array();
68
        $this->load($configs, $container);
69
    }
70
71 View Code Duplication
    public function it_should_throw_an_exception_if_specifying_a_non_existent_name_generator_service(
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...
72
        ContainerBuilder $container
73
    ) {
74
        $container->has('some.service.name')
75
                  ->willReturn(false);
76
77
        // Ignore these calls
78
        $container->setParameter(Argument::cetera())
79
                  ->willReturn();
80
        $container->setDefinition(Argument::cetera())
81
                  ->willReturn();
82
        $container->setAlias(Argument::cetera())
83
                  ->willReturn();
84
85
        $configs = array(array('parameter_name_generator' => 'some.service.name'));
86
        $this->shouldThrow('\Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException')
87
             ->during('load', array($configs, $container));
88
    }
89
90 View Code Duplication
    public function it_should_configure_a_custom_name_generator(ContainerBuilder $container)
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...
91
    {
92
        // Expectations
93
        $container->setAlias('gesdinet.jwtrefreshtoken.name_generator.default', 'some.service.name')
94
                  ->shouldBeCalled();
95
96
        // Stubs
97
        $container->has('some.service.name')
98
                  ->willReturn(true);
99
100
        // Ignore these calls
101
        $container->setParameter(Argument::cetera())
102
                  ->willReturn();
103
        $container->setDefinition(Argument::cetera())
104
                  ->willReturn();
105
        $container->setAlias(Argument::cetera())
106
                  ->willReturn();
107
108
        $configs = array(array('parameter_name_generator' => 'some.service.name'));
109
        $this->load($configs, $container);
110
    }
111
}
112