AbstractSitemapServiceTestCaseTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 80.73 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 88
loc 109
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testAssertSitemapCount() 18 18 1
A testAssertUrlNotCalled() 19 19 1
A testAssertLastmod() 17 17 1
A testAssertPriority() 17 17 1
A testAssertChangeFreq() 17 17 1
A createService() 0 4 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\Test;
11
12
use Core23\SitemapBundle\Definition\SitemapDefinitionInterface;
13
use Core23\SitemapBundle\Model\Url;
14
use Core23\SitemapBundle\Sitemap\SitemapServiceInterface;
15
use Core23\SitemapBundle\Test\AbstractSitemapServiceTestCase as ParentTestCase;
16
use DateTime;
17
use PHPUnit\Framework\AssertionFailedError;
18
19
final class AbstractSitemapServiceTestCaseTest extends ParentTestCase
20
{
21
    private $serviceMock;
22
23
    protected function setUp(): void
24
    {
25
        $this->serviceMock = $this->prophesize(SitemapServiceInterface::class);
26
27
        parent::setUp();
28
    }
29
30 View Code Duplication
    public function testAssertSitemapCount(): void
0 ignored issues
show
Duplication introduced by core23
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...
31
    {
32
        $this->expectException(AssertionFailedError::class);
33
        $this->expectExceptionMessage('Failed asserting that actual size 2 matches expected size 1.');
34
35
        $sitemap = $this->prophesize(SitemapDefinitionInterface::class);
36
37
        $this->serviceMock->execute($sitemap)
38
            ->willReturn([
39
                new Url('/path/foo', 20, Url::FREQUENCE_DAILY),
40
                new Url('/path/bar', 20, Url::FREQUENCE_DAILY),
41
            ])
42
        ;
43
44
        $this->assertSitemap('/path/bar', 20, Url::FREQUENCE_DAILY);
45
46
        $this->process($sitemap->reveal());
47
    }
48
49 View Code Duplication
    public function testAssertUrlNotCalled(): void
0 ignored issues
show
Duplication introduced by core23
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...
50
    {
51
        $this->expectException(AssertionFailedError::class);
52
        $this->expectExceptionMessage("The url '/path/foo' was not expected to be called.");
53
54
        $sitemap = $this->prophesize(SitemapDefinitionInterface::class);
55
56
        $this->serviceMock->execute($sitemap)
57
            ->willReturn(
58
                [
59
                    new Url('/path/foo', 20, Url::FREQUENCE_DAILY),
60
                ]
61
            )
62
        ;
63
64
        $this->assertSitemap('/path/bar', 20, Url::FREQUENCE_DAILY);
65
66
        $this->process($sitemap->reveal());
67
    }
68
69 View Code Duplication
    public function testAssertLastmod(): void
0 ignored issues
show
Duplication introduced by core23
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...
70
    {
71
        $this->expectException(AssertionFailedError::class);
72
        $this->expectExceptionMessage("The url '/path/foo' was expected with a different lastmod.");
73
74
        $sitemap = $this->prophesize(SitemapDefinitionInterface::class);
75
76
        $this->serviceMock->execute($sitemap)
77
            ->willReturn([
78
                new Url('/path/foo', 20, Url::FREQUENCE_DAILY, new DateTime('2018-10-02')),
79
            ])
80
        ;
81
82
        $this->assertSitemap('/path/foo', 20, Url::FREQUENCE_DAILY, new DateTime('2018-10-01'));
83
84
        $this->process($sitemap->reveal());
85
    }
86
87 View Code Duplication
    public function testAssertPriority(): void
0 ignored issues
show
Duplication introduced by core23
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...
88
    {
89
        $this->expectException(AssertionFailedError::class);
90
        $this->expectExceptionMessage("The url '/path/foo' was expected with 20 priority. 60 given.");
91
92
        $sitemap = $this->prophesize(SitemapDefinitionInterface::class);
93
94
        $this->serviceMock->execute($sitemap)
95
            ->willReturn([
96
                new Url('/path/foo', 60, Url::FREQUENCE_DAILY),
97
            ])
98
        ;
99
100
        $this->assertSitemap('/path/foo', 20, Url::FREQUENCE_DAILY);
101
102
        $this->process($sitemap->reveal());
103
    }
104
105 View Code Duplication
    public function testAssertChangeFreq(): void
0 ignored issues
show
Duplication introduced by core23
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...
106
    {
107
        $this->expectException(AssertionFailedError::class);
108
        $this->expectExceptionMessage("The url '/path/foo' was expected with weekly changefreq. daily given.");
109
110
        $sitemap = $this->prophesize(SitemapDefinitionInterface::class);
111
112
        $this->serviceMock->execute($sitemap)
113
            ->willReturn([
114
                new Url('/path/foo', 20, Url::FREQUENCE_DAILY),
115
            ])
116
        ;
117
118
        $this->assertSitemap('/path/foo', 20, Url::FREQUENCE_WEEKLY);
119
120
        $this->process($sitemap->reveal());
121
    }
122
123
    protected function createService(): SitemapServiceInterface
124
    {
125
        return $this->serviceMock->reveal();
126
    }
127
}
128