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 ( 705157...0b8fba )
by
unknown
12s
created

SitemapCompilerPassTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 19.63 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 6
dl 21
loc 107
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 15 1
A testProcess() 0 27 2
A testProcessWithNoServices() 11 11 1
A testProcessWithStaticUrls() 0 28 1
A testProcessWithEmptyGroups() 10 10 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
/*
4
 * (c) Christian Gripp <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Core23\SitemapBundle\Tests\DependencyInjection\Compiler;
11
12
use Core23\SitemapBundle\Definition\DefintionManagerInterface;
13
use Core23\SitemapBundle\DependencyInjection\Compiler\SitemapCompilerPass;
14
use Core23\SitemapBundle\Sitemap\SitemapServiceManagerInterface;
15
use Core23\SitemapBundle\Sitemap\StaticSitemapService;
16
use PHPUnit\Framework\TestCase;
17
use Prophecy\Argument;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Reference;
21
22
final class SitemapCompilerPassTest extends TestCase
23
{
24
    private $serviceManager;
25
26
    private $definitionManager;
27
28
    /**
29
     * @var ContainerBuilder
30
     */
31
    private $container;
32
33
    protected function setUp(): void
34
    {
35
        $this->serviceManager = $this->prophesize(Definition::class);
36
        $this->serviceManager->hasTag('core23.sitemap')
37
            ->willReturn(false)
38
        ;
39
        $this->definitionManager = $this->prophesize(Definition::class);
40
        $this->definitionManager->hasTag('core23.sitemap')
41
            ->willReturn(false)
42
        ;
43
44
        $this->container = new ContainerBuilder();
45
        $this->container->setDefinition(SitemapServiceManagerInterface::class, $this->serviceManager->reveal());
46
        $this->container->setDefinition(DefintionManagerInterface::class, $this->definitionManager->reveal());
47
    }
48
49
    public function testProcess(): void
50
    {
51
        $this->serviceManager->addMethodCall('addSitemap', Argument::that(static function ($args) {
52
            return 'acme.sitemap' === $args[0] && $args[1] instanceof Reference;
53
        }))
54
        ->shouldBeCalled()
55
        ;
56
57
        $this->definitionManager->addMethodCall('addDefinition', [
58
            'acme.sitemap',
59
        ])
60
        ->shouldBeCalled()
61
        ;
62
63
        $sitemapDefinition = new Definition();
64
        $sitemapDefinition->addTag('core23.sitemap');
65
66
        $this->container->setParameter('core23_sitemap.static_urls', []);
67
        $this->container->setDefinition('acme.sitemap', $sitemapDefinition);
68
69
        $compiler = new SitemapCompilerPass();
70
        $compiler->process($this->container);
71
72
        static::assertTrue($sitemapDefinition->isPublic());
73
74
        $this->definitionManager->addMethodCall('addDefintion', Argument::any())->shouldNotHaveBeenCalled();
75
    }
76
77 View Code Duplication
    public function testProcessWithNoServices(): void
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...
78
    {
79
        $this->container->setParameter('core23_sitemap.static_urls', []);
80
81
        $compiler = new SitemapCompilerPass();
82
        $compiler->process($this->container);
83
84
        static::assertSame([], $this->container->getParameter('core23_sitemap.static_urls'));
85
86
        $this->definitionManager->addMethodCall('addDefintion', Argument::any())->shouldNotHaveBeenCalled();
87
    }
88
89
    public function testProcessWithStaticUrls(): void
90
    {
91
        $this->definitionManager->addMethodCall('addDefinition', [
92
            StaticSitemapService::class,
93
            [
94
                [
95
                    'url'        => 'http://example.com',
96
                    'priority'   => 100,
97
                    'changefreq' => 'daily',
98
                ],
99
            ],
100
        ])
101
            ->shouldBeCalled()
102
        ;
103
104
        $this->container->setParameter('core23_sitemap.static_urls', [
105
            'static' => [
106
                [
107
                    'url'        => 'http://example.com',
108
                    'priority'   => 100,
109
                    'changefreq' => 'daily',
110
                ],
111
            ],
112
        ]);
113
114
        $compiler = new SitemapCompilerPass();
115
        $compiler->process($this->container);
116
    }
117
118 View Code Duplication
    public function testProcessWithEmptyGroups(): void
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...
119
    {
120
        $this->container->setParameter('core23_sitemap.static_urls', []);
121
122
        $compiler = new SitemapCompilerPass();
123
        $compiler->process($this->container);
124
125
        $this->serviceManager->addMethodCall(Argument::any())->shouldNotBeCalled();
126
        $this->definitionManager->addMethodCall(Argument::any())->shouldNotBeCalled();
127
    }
128
}
129