Completed
Pull Request — develop (#48)
by Luís
03:01
created

EnvironmentTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 4
dl 12
loc 63
rs 10

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 PHPSC\PagSeguro;
3
4
use PHPSC\PagSeguro\Environments\Production;
5
use PHPSC\PagSeguro\Environments\Sandbox;
6
7
/**
8
 * @author Luís Otávio Cobucci Oblonczyk <[email protected]>
9
 */
10
class EnvironmentTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @var Environment
14
     */
15
    private $environment;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected function setUp()
21
    {
22
        $this->environment = $this->getMockForAbstractClass(Environment::class);
23
24
        $this->environment->expects($this->any())
25
                          ->method('getHost')
26
                          ->willReturn('test.com');
27
28
        $this->environment->expects($this->any())
29
                          ->method('getWsHost')
30
                          ->willReturn('ws.test.com');
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function isValidShouldReturnTrueWhenHostIsProduction()
37
    {
38
        $this->assertTrue(Environment::isValid(Production::WS_HOST));
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function isValidShouldReturnFalseWhenHostIsSandbox()
45
    {
46
        $this->assertTrue(Environment::isValid(Sandbox::WS_HOST));
47
    }
48
49
    /**
50
     * @test
51
     */
52
    public function isValidShouldReturnFalseWhenHostNotProductionOrSandbox()
53
    {
54
        $this->assertFalse(Environment::isValid('example.org'));
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function getWsUrlShouldAppendProtocolAndWsHostToResource()
61
    {
62
        $this->assertEquals('https://ws.test.com/test', $this->environment->getWsUrl('/test'));
63
    }
64
65
    /**
66
     * @test
67
     */
68
    public function getUrlShouldAppendProtocolAndHostToResource()
69
    {
70
        $this->assertEquals('https://test.com/test', $this->environment->getUrl('/test'));
71
    }
72
}
73