Completed
Push — develop ( bc21b0...0bdfd4 )
by Adam
24:26 queued 09:29
created

BuilderTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 79
Duplicated Lines 25.32 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 3
dl 20
loc 79
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCreateConfiguredClient() 0 6 1
A testWithEndpoint() 0 6 1
A testWithCredentials() 0 8 1
A testAppendPlugin() 10 10 1
A testPrependPlugin() 10 10 1
A testWithLearningOptOut() 0 6 1
A testWithApiKey() 0 6 1
A testWithVersion() 0 6 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 IBM\Watson\Common\tests\HttpClient;
4
5
use Http\Client\Common\Plugin;
6
use Http\Client\Common\PluginClient;
7
use Http\Client\HttpClient;
8
use Http\Message\MessageFactory;
9
use Http\Message\UriFactory;
10
use IBM\Watson\Common\HttpClient\Builder;
11
use PHPUnit\Framework\TestCase;
12
use Mockery as m;
13
14
class BuilderTest extends TestCase
15
{
16
    private $httpClient;
17
    private $messageFactory;
18
    private $uriFactory;
19
20
    public function setUp()
21
    {
22
        $this->httpClient = m::mock(HttpClient::class);
23
        $this->messageFactory = m::mock(MessageFactory::class);
24
        $this->uriFactory = m::mock(UriFactory::class);
25
    }
26
27
    public function testCreateConfiguredClient()
28
    {
29
        $client = (new Builder())->createConfiguredClient();
30
31
        $this->assertInstanceOf(PluginClient::class, $client);
32
    }
33
34
    public function testWithEndpoint()
35
    {
36
        $client = (new Builder())->withEndpoint('https://mockurl.test')->createConfiguredClient();
37
38
        $this->assertInstanceOf(PluginClient::class, $client);
39
    }
40
41
    public function testWithCredentials()
42
    {
43
        $client = (new Builder())
44
            ->withCredentials('adam', 'password')
45
            ->createConfiguredClient();
46
47
        $this->assertInstanceOf(PluginClient::class, $client);
48
    }
49
50 View Code Duplication
    public function testAppendPlugin()
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...
51
    {
52
        $plugin1 = m::mock(Plugin::class);
53
        $plugin2 = m::mock(Plugin::class);
54
        $plugin3 = m::mock(Plugin::class);
55
56
        $client = (new Builder())->appendPlugin($plugin1, $plugin2, $plugin3)->createConfiguredClient();
57
58
        $this->assertInstanceOf(PluginClient::class, $client);
59
    }
60
61 View Code Duplication
    public function testPrependPlugin()
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...
62
    {
63
        $plugin1 = m::mock(Plugin::class);
64
        $plugin2 = m::mock(Plugin::class);
65
        $plugin3 = m::mock(Plugin::class);
66
67
        $client = (new Builder())->prependPlugin($plugin1, $plugin2, $plugin3)->createConfiguredClient();
68
69
        $this->assertInstanceOf(PluginClient::class, $client);
70
    }
71
72
    public function testWithLearningOptOut()
73
    {
74
        $client = (new Builder())->withLearningOptOut()->createConfiguredClient();
75
76
        $this->assertInstanceOf(PluginClient::class, $client);
77
    }
78
79
    public function testWithApiKey()
80
    {
81
        $client = (new Builder())->withApiKey('somekey')->createConfiguredClient();
82
83
        $this->assertInstanceOf(PluginClient::class, $client);
84
    }
85
86
    public function testWithVersion()
87
    {
88
        $client = (new Builder())->withVersion('123')->createConfiguredClient();
89
90
        $this->assertInstanceOf(PluginClient::class, $client);
91
    }
92
}
93