Completed
Push — master ( f9a368...59d319 )
by
unknown
02:44
created

PageTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 205
Duplicated Lines 10.73 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 22
loc 205
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testTitles() 0 22 1
A testExists() 0 23 1
A testId() 11 11 1
A testUrls() 11 11 1
A testUsersEdits() 0 20 1
B testWikidataErrors() 0 40 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
 * This file contains only the PageTest class.
4
 */
5
6
namespace Tests\Xtools;
7
8
// use PHPUnit_Framework_TestCase;
9
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
10
use Xtools\Page;
11
use Xtools\PagesRepository;
12
use Xtools\Project;
13
use Xtools\ProjectRepository;
14
use Xtools\User;
15
16
/**
17
 * Tests for the Page class.
18
 */
19
class PageTest extends KernelTestCase
20
{
21
    /** @var Container The Symfony container. */
22
    protected $container;
23
24
    /**
25
     * A page has a title and an HTML display title.
26
     */
27
    public function testTitles()
28
    {
29
        $project = new Project('TestProject');
30
        $pageRepo = $this->getMock(PagesRepository::class, ['getPageInfo']);
31
        $data = [
32
            [$project, 'Test_Page_1', ['title' => 'Test_Page_1']],
33
            [$project, 'Test_Page_2', ['title' => 'Test_Page_2', 'displaytitle' => '<em>Test</em> page 2']],
34
        ];
35
        $pageRepo->method('getPageInfo')->will($this->returnValueMap($data));
36
37
        // Page with no display title.
38
        $page = new Page($project, 'Test_Page_1');
39
        $page->setRepository($pageRepo);
40
        $this->assertEquals('Test_Page_1', $page->getTitle());
41
        $this->assertEquals('Test_Page_1', $page->getDisplayTitle());
42
43
        // Page with a display title.
44
        $page = new Page($project, 'Test_Page_2');
45
        $page->setRepository($pageRepo);
46
        $this->assertEquals('Test_Page_2', $page->getTitle());
47
        $this->assertEquals('<em>Test</em> page 2', $page->getDisplayTitle());
48
    }
49
50
    /**
51
     * A page either exists or doesn't.
52
     */
53
    public function testExists()
54
    {
55
        $pageRepo = $this->getMock(PagesRepository::class, ['getPageInfo']);
56
        $project = new Project('TestProject');
57
        // Mock data (last element of each array is the return value).
58
        $data = [
59
            [$project, 'Existing_page', []],
60
            [$project, 'Missing_page', ['missing' => '']],
61
        ];
62
        $pageRepo //->expects($this->exactly(2))
1 ignored issue
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
63
            ->method('getPageInfo')
64
            ->will($this->returnValueMap($data));
65
66
        // Existing page.
67
        $page1 = new Page($project, 'Existing_page');
68
        $page1->setRepository($pageRepo);
69
        $this->assertTrue($page1->exists());
70
71
        // Missing page.
72
        $page2 = new Page($project, 'Missing_page');
73
        $page2->setRepository($pageRepo);
74
        $this->assertFalse($page2->exists());
75
    }
76
77
    /**
78
     * A page has an integer ID on a given project.
79
     */
80 View Code Duplication
    public function testId()
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...
81
    {
82
        $pageRepo = $this->getMock(PagesRepository::class, ['getPageInfo']);
83
        $pageRepo->expects($this->once())
84
            ->method('getPageInfo')
85
            ->willReturn(['pageid' => '42']);
86
87
        $page = new Page(new Project('TestProject'), 'Test_Page');
88
        $page->setRepository($pageRepo);
89
        $this->assertEquals(42, $page->getId());
90
    }
91
92
    /**
93
     * A page has a URL.
94
     */
95 View Code Duplication
    public function testUrls()
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...
96
    {
97
        $pageRepo = $this->getMock(PagesRepository::class, ['getPageInfo']);
98
        $pageRepo->expects($this->once())
99
            ->method('getPageInfo')
100
            ->willReturn(['fullurl' => 'https://example.org/Page']);
101
102
        $page = new Page(new Project('exampleWiki'), 'Page');
103
        $page->setRepository($pageRepo);
104
        $this->assertEquals('https://example.org/Page', $page->getUrl());
105
    }
106
107
    /**
108
     * A list of a single user's edits on this page can be retrieved, along with the count of
109
     * these revisions, and the total bytes added and removed.
110
     * @TODO this is not finished yet
111
     */
112
    public function testUsersEdits()
113
    {
114
        $pageRepo = $this->getMock(PagesRepository::class, ['getRevisions']);
115
        $pageRepo
116
            ->method('getRevisions')
117
            ->with()
118
            ->willReturn([
119
                [
120
                    'id' => '1',
121
                    'timestamp' => '20170505100000',
122
                    'length_change' => '1',
123
                    'comment' => 'One'
124
                ],
125
            ]);
126
127
        $page = new Page(new Project('exampleWiki'), 'Page');
128
        $page->setRepository($pageRepo);
129
        $user = new User('Testuser');
0 ignored issues
show
Unused Code introduced by
$user is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
130
        //$this->assertCount(3, $page->getRevisions($user)->getCount());
1 ignored issue
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
131
    }
132
133
    /**
134
     * Wikidata errors. With this test getWikidataInfo doesn't return a Description,
135
     *     so getWikidataErrors should complain accordingly
136
     */
137
    public function testWikidataErrors()
138
    {
139
        $pageRepo = $this->getMock(PagesRepository::class, ['getWikidataInfo', 'getPageInfo']);
140
141
        $pageRepo
142
            ->method('getWikidataInfo')
143
            ->with()
144
            ->willReturn([
145
                [
146
                    'term' => 'label',
147
                    'term_text' => 'My article',
148
                ],
149
            ]);
150
        $pageRepo
151
            ->method('getPageInfo')
152
            ->with()
153
            ->willReturn([
154
                'pagelanguage' => 'en',
155
                'pageprops' => [
156
                    'wikibase_item' => 'Q123',
157
                ],
158
            ]);
159
160
        $page = new Page(new Project('exampleWiki'), 'Page');
161
        $page->setRepository($pageRepo);
162
163
        $wikidataErrors = $page->getWikidataErrors();
164
165
        $this->assertArraySubset(
166
            [
167
                'prio' => 3,
168
                'name' => 'Wikidata',
169
            ],
170
            $wikidataErrors[0]
171
        );
172
        $this->assertContains(
173
            'Description',
174
            $wikidataErrors[0]['notice']
175
        );
176
    }
177
178
    // public function testPageAssessments()
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
179
    // {
180
    //     $projectRepo = $this->getMock(ProjectRepository::class, ['getAssessmentsConfig']);
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
181
    //     $projectRepo
182
    //         ->method('getAssessmentsConfig')
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
183
    //         ->willReturn([
184
    //             'wikiproject_prefix' => 'Wikipedia:WikiProject_'
1 ignored issue
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
185
    //         ]);
186
187
    //     $project = $this->getMock(Project::class, ['getDomain']);
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
188
    //     $project
189
    //         ->method('getDomain')
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
190
    //         ->willReturn('test.wiki.org');
1 ignored issue
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
    //     $project->setRepository($projectRepo);
1 ignored issue
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
192
193
    //     $pageRepo = $this->getMock(PagesRepository::class, ['getAssessments', 'getPageInfo']);
1 ignored issue
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
194
    //     $pageRepo
195
    //         ->method('getAssessments')
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
196
    //         ->with($project)
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
197
    //         ->willReturn([
198
    //             [
199
    //                 'wikiproject' => 'Military history',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
200
    //                 'class' => 'Start',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
    //                 'importance' => 'Low',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
202
    //             ],
203
    //             [
204
    //                 'wikiproject' => 'Firearms',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
205
    //                 'class' => 'C',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
206
    //                 'importance' => 'High',
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
207
    //             ],
208
    //         ]);
209
    //     $pageRepo
210
    //         ->method('getPageInfo')
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
211
    //         ->with($project, 'Test_page')
1 ignored issue
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
212
    //         ->willReturn([
213
    //             'pageid' => 5,
1 ignored issue
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
214
    //         ]);
215
216
    //     $page = new Page($project, 'Test_page');
1 ignored issue
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
217
    //     $page->setRepository($pageRepo);
1 ignored issue
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
218
219
    //     $assessments = $page->getAssessments();
1 ignored issue
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
220
221
    //     $this->assertEquals('C', $assessments['assessment']);
1 ignored issue
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
222
    // }
223
}
224