Completed
Pull Request — develop (#41)
by Vinicius
03:09
created

RequestTest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 148
Duplicated Lines 9.46 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

12 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A constructShouldConfigureTheAttributes() 0 4 1
A getPreApprovalShouldReturnConfiguredPreApproval() 0 4 1
A getReferenceShouldReturnConfiguredReference() 0 6 1
A setReferenceShouldChangeTheAttribute() 0 6 1
A getRedirectToShouldReturnConfiguredRedirectTo() 0 6 1
A setRedirectToShouldChangeTheAttribute() 0 6 1
A getReviewOnShouldReturnConfiguredReviewOn() 0 6 1
A setReviewOnToShouldChangeTheAttribute() 0 6 1
A getCustomerShouldReturnConfiguredCustomer() 7 7 1
A setCustomerToShouldChangeTheAttribute() 7 7 1
B testSerializeShouldXMLFull() 0 31 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 PHPSC\PagSeguro\Requests\PreApprovals;
3
4
use SimpleXMLElement;
5
use DateTime;
6
use PHPSC\PagSeguro\Customer\Customer;
7
use PHPSC\PagSeguro\Customer\Phone;
8
use PHPSC\PagSeguro\Customer\Address;
9
10
/**
11
 * @author Adelar Tiemann Junior <[email protected]>
12
 */
13
class RequestTest extends \PHPUnit_Framework_TestCase
14
{
15
    /**
16
     * @var Request
17
     */
18
    private $request;
19
    
20
    /**
21
     * @var PreApproval
22
     */
23
    private $preApproval;
24
25
    protected function setUp()
26
    {
27
        $this->preApproval = $this->getMock(PreApproval::class, [], [], '', false);
28
        $this->request = new Request($this->preApproval);
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function constructShouldConfigureTheAttributes()
35
    {
36
        $this->assertAttributeInstanceOf(PreApproval::class, 'preApproval', $this->request);
37
    }
38
39
    /**
40
     * @test
41
     */
42
    public function getPreApprovalShouldReturnConfiguredPreApproval()
43
    {
44
        $this->assertInstanceOf(PreApproval::class, $this->request->getPreApproval());
45
    }
46
47
    /**
48
     * @test
49
     */
50
    public function getReferenceShouldReturnConfiguredReference()
51
    {
52
        $this->request->setReference('someRef');
53
        
54
        $this->assertEquals('someRef', $this->request->getReference());
55
    }
56
57
    /**
58
     * @test
59
     */
60
    public function setReferenceShouldChangeTheAttribute()
61
    {
62
        $this->request->setReference('test');
63
        
64
        $this->assertAttributeEquals('test', 'reference', $this->request);
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function getRedirectToShouldReturnConfiguredRedirectTo()
71
    {
72
        $this->request->setRedirectTo('someRedirect');
73
        
74
        $this->assertEquals('someRedirect', $this->request->getRedirectTo());
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function setRedirectToShouldChangeTheAttribute()
81
    {
82
        $this->request->setRedirectTo('otherRedirect');
83
        
84
        $this->assertAttributeEquals('otherRedirect', 'redirectTo', $this->request);
85
    }
86
87
    /**
88
     * @test
89
     */
90
    public function getReviewOnShouldReturnConfiguredReviewOn()
91
    {
92
        $this->request->setReviewOn('someReview');
93
        
94
        $this->assertEquals('someReview', $this->request->getReviewOn());
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function setReviewOnToShouldChangeTheAttribute()
101
    {
102
        $this->request->setReviewOn('otherReview');
103
        
104
        $this->assertAttributeEquals('otherReview', 'reviewOn', $this->request);
105
    }
106
107
    /**
108
     * @test
109
     */
110 View Code Duplication
    public function getCustomerShouldReturnConfiguredCustomer()
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...
111
    {
112
        $customer = $this->getMock(Customer::class, [], [], '', false);
113
        $this->request->setCustomer($customer);
114
        
115
        $this->assertSame($customer, $this->request->getCustomer());
116
    }
117
118
    /**
119
     * @test
120
     */
121 View Code Duplication
    public function setCustomerToShouldChangeTheAttribute()
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...
122
    {
123
        $customer = $this->getMock(Customer::class, [], [], '', false);
124
        $this->request->setCustomer($customer);
125
        
126
        $this->assertAttributeSame($customer, 'customer', $this->request);
127
    }
128
129
    public function testSerializeShouldXMLFull()
130
    {
131
        $preApproval = new PreApproval;
132
        $preApproval->setChargeType('auto');
133
        $preApproval->setName('Assinatura Revista');
134
        $preApproval->setPeriod('MONTHLY');
135
        $preApproval->setFinalDate(new DateTime('2016-11-18', new \DateTimeZone('UTC')));
136
        $preApproval->setMaxTotalAmount(3000);
137
        $preApproval->setDetails('Cobranca Mensal da Revista');
138
        $preApproval->setAmountPerPayment(100);
139
        $preApproval->setMaxAmountPerPayment(150);
140
        $preApproval->setInitialDate(new DateTime('2015-11-18', new \DateTimeZone('UTC')));
141
        $preApproval->setMaxPaymentsPerPeriod(12);
142
        $preApproval->setMaxAmountPerPeriod(1200);
143
144
        $customerAddress = new Address('AC', 'Sao Maite', '99500-079', 'Centro', 'Rua David Delgado', '55', 'Fundos');
145
        $customerPhone = new Phone('11', '99999999');
146
        $customer = new Customer('[email protected]', 'FooBar', $customerPhone, $customerAddress);
147
148
        $request = new Request($preApproval);
149
        $request->setCustomer($customer);
150
        $request->setReference('abcdef');
151
        $request->setReviewOn('http://localhost/return.php');
152
        $request->setRedirectTo('http://localhost/success.php');
153
154
        $xml = $request->xmlSerialize();
155
156
        $this->assertInstanceOf(SimpleXMLElement::class, $xml);
157
        $expected = simplexml_load_file(__DIR__.'/xml/preAprovalsRequestFull.xml');
158
        $this->assertEquals($expected, $xml);
159
    }
160
}
161