Completed
Push — master ( 1f5aaf...c63d45 )
by Miro
04:10 queued 02:00
created

PaginatedKnpLabsRepoFacadeTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 10.13 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 6
dl 8
loc 79
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetchAllMilestones() 0 9 1
A testFetchAllIssues() 0 9 1
A testFetchAllIssuesAndPullRequests() 0 9 1
A getTokenAuthenticatedApiClient() 0 6 1
A provideTestRepo() 8 8 1
A provideTestUser() 0 7 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
namespace tests\DevBoardLib\GithubApiFacade\Repo;
3
4
use DevBoardLib\GithubApiFacade\Client\KnpLabsClientFactory;
5
use DevBoardLib\GithubApiFacade\Repo\PaginatedKnpLabsRepoFacade;
6
use Mockery as m;
7
8
/**
9
 * Class PaginatedKnpLabsRepoFacadeTest.
10
 */
11
class PaginatedKnpLabsRepoFacadeTest extends \PHPUnit_Framework_TestCase
12
{
13
    /**
14
     * @group GithubIntegration
15
     * @group Live
16
     */
17
    public function testFetchAllMilestones()
18
    {
19
        $target = new PaginatedKnpLabsRepoFacade(
20
            $this->getTokenAuthenticatedApiClient(),
21
            $this->provideTestRepo()
22
        );
23
24
        self::assertCount(4, $target->fetchAllMilestones());
25
    }
26
27
    /**
28
     * @group GithubIntegration
29
     * @group Live
30
     * @group wip
31
     */
32
    public function testFetchAllIssues()
33
    {
34
        $target = new PaginatedKnpLabsRepoFacade(
35
            $this->getTokenAuthenticatedApiClient(),
36
            $this->provideTestRepo()
37
        );
38
39
        self::assertCount(10, $target->fetchAllIssues());
40
    }
41
42
    /**
43
     * @group GithubIntegration
44
     * @group Live
45
     * @group wip
46
     */
47
    public function testFetchAllIssuesAndPullRequests()
48
    {
49
        $target = new PaginatedKnpLabsRepoFacade(
50
            $this->getTokenAuthenticatedApiClient(),
51
            $this->provideTestRepo()
52
        );
53
54
        self::assertCount(12, $target->fetchAllIssuesAndPullRequests());
55
    }
56
57
    /**
58
     * @return \Github\Client
59
     */
60
    private function getTokenAuthenticatedApiClient()
61
    {
62
        $factory = new KnpLabsClientFactory();
63
64
        return $factory->createTokenAuthenticatedClient($this->provideTestUser());
65
    }
66
67
    /**
68
     * @return m\MockInterface
69
     */
70 View Code Duplication
    private function provideTestRepo()
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...
71
    {
72
        $githubRepo = m::mock('DevBoardLib\GithubCore\Repo\GithubRepo');
73
        $githubRepo->shouldReceive('getOwner')->andReturn('devboard');
74
        $githubRepo->shouldReceive('getName')->andReturn('test-hitman');
75
76
        return $githubRepo;
77
    }
78
79
    /**
80
     * @return m\MockInterface
81
     */
82
    private function provideTestUser()
83
    {
84
        $user = m::mock('DevBoardLib\GithubApiFacade\Auth\GithubAccessToken');
85
        $user->shouldReceive('getGithubAccessToken')->andReturn(getenv('GITHUB_ACCESS_TOKEN'));
86
87
        return $user;
88
    }
89
}
90