Completed
Push — master ( 61d54e...4a5166 )
by Sam
03:19
created

ProjectTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 69
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 23
loc 69
c 1
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testBasicMetadata() 0 16 1
A testNamespaces() 11 11 1
A testSingleWiki() 12 12 1
A testExists() 0 11 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 Xtools;
4
5
use PHPUnit_Framework_TestCase;
6
7
class ProjectTest extends PHPUnit_Framework_TestCase
8
{
9
10
    /**
11
     * A project has its own domain name, database name, URL, script path, and article path.
12
     */
13
    public function testBasicMetadata()
14
    {
15
        $projectRepo = $this->getMock(ProjectRepository::class);
16
        $projectRepo->expects($this->once())
17
            ->method('getOne')
18
            ->willReturn(['url' => 'https://test.example.org', 'dbname' => 'test_wiki']);
19
20
        $project = new Project('testWiki');
21
        $project->setRepository($projectRepo);
22
        $this->assertEquals('test.example.org', $project->getDomain());
23
        $this->assertEquals('test_wiki', $project->getDatabaseName());
24
        $this->assertEquals('https://test.example.org/', $project->getUrl());
25
        $this->assertEquals('/w/index.php', $project->getScriptPath());
26
        $this->assertEquals('/wiki/', $project->getArticlePath());
27
        $this->assertTrue($project->exists());
28
    }
29
30
    /**
31
     * A project has a set of namespaces, comprising integer IDs and string titles.
32
     */
33 View Code Duplication
    public function testNamespaces()
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
        $projectRepo = $this->getMock(ProjectRepository::class);
36
        $projectRepo->expects($this->once())
37
            ->method('getMetadata')
38
            ->willReturn(['namespaces' => [0 => 'Article', 1 => 'Article_talk']]);
39
40
        $project = new Project('testWiki');
41
        $project->setRepository($projectRepo);
42
        $this->assertCount(2, $project->getNamespaces());
43
    }
44
45
    /**
46
     * Xtools can be run in single-wiki mode, where there is only one project.
47
     */
48 View Code Duplication
    public function testSingleWiki()
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...
49
    {
50
        $projectRepo = new ProjectRepository();
51
        $projectRepo->setSingleMetadata([
52
            'url' => 'https://example.org/a-wiki/',
53
            'dbname' => 'example_wiki',
54
        ]);
55
        $project = new Project('disregarded_wiki_name');
56
        $project->setRepository($projectRepo);
57
        $this->assertEquals('example_wiki', $project->getDatabaseName());
58
        $this->assertEquals('https://example.org/a-wiki/', $project->getUrl());
59
    }
60
61
    /**
62
     * A project is considered to exist if it has at least a domain name.
63
     */
64
    public function testExists()
65
    {
66
        $projectRepo = $this->getMock(ProjectRepository::class);
67
        $projectRepo->expects($this->once())
68
            ->method('getOne')
69
            ->willReturn([]);
70
71
        $project = new Project('testWiki');
72
        $project->setRepository($projectRepo);
73
        $this->assertFalse($project->exists());
74
    }
75
}
76