Completed
Push — master ( 4517c4...dc88ca )
by
unknown
05:54
created

RefundTest::testRefundOrderCreditCardPartial()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Tests\Resource;
4
5
use Moip\Tests\TestCase;
6
7
class RefundTest extends TestCase
8
{
9
    public function testRefundOrderCreditCardFull()
10
    {
11
        $order = $this->paymentCreditCard(false);
12
13
        $this->mockHttpSession($this->body_order_refund_full_cc);
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
14
        $refund = $order->refunds()->creditCardFull();
15
16
        $this->assertNotEmpty($refund->getId());
17
        $this->assertEquals('FULL', $refund->getType());
18
    }
19
20
    public function testRefundOrderCreditCardPartial()
21
    {
22
        $order = $this->paymentCreditCard(false);
23
24
        $this->mockHttpSession($this->body_order_refund_partial_cc);
0 ignored issues
show
Bug introduced by
The property body_order_refund_partial_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
25
        $refund = $order->refunds()->creditCardPartial(5000);
26
27
        $this->assertNotEmpty($refund->getId());
28
        $this->assertEquals('PARTIAL', $refund->getType());
29
    }
30
31 View Code Duplication
    public function testRefundOrderBankAccountFull()
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...
32
    {
33
        $order = $this->paymentBoleto(false);
34
35
        $this->mockHttpSession($this->body_order_refund_full_bankaccount);
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
        $refund = $order->refunds()
37
            ->bankAccountFull('CHECKING', '001', '1584', '9', '00210169', '6', $order->getCustomer());
38
39
        $this->assertNotEmpty($refund->getId());
40
        $this->assertEquals('FULL', $refund->getType());
41
    }
42
43 View Code Duplication
    public function testRefundOrderBankAccountPartial()
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...
44
    {
45
        $order = $this->paymentBoleto(false);
46
47
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
0 ignored issues
show
Bug introduced by
The property body_payment_refund_partial_bankaccount does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
        $refund = $order->refunds()
49
            ->bankAccountPartial(20000, 'SAVING', '001', '1584', '9', '00210169', '6', $order->getCustomer());
50
51
        $this->assertNotEmpty($refund->getId());
52
        $this->assertEquals('PARTIAL', $refund->getType());
53
    }
54
55
    public function testRefundPaymentCreditCardFull()
56
    {
57
        $payment = $this->paymentCreditCard();
58
59
        $this->mockHttpSession($this->body_payment_refund_full_cc);
0 ignored issues
show
Bug introduced by
The property body_payment_refund_full_cc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
        $refund = $payment->refunds()->creditCardFull();
61
62
        $this->assertNotEmpty($refund->getId());
63
        $this->assertEquals('FULL', $refund->getType());
64
    }
65
66 View Code Duplication
    public function testRefundPaymentCreditCardPartial()
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...
67
    {
68
        $payment = $this->paymentCreditCard();
69
70
        $this->mockHttpSession($this->body_payment_refund_partial_cc);
0 ignored issues
show
Bug introduced by
The property body_payment_refund_partial_cc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
71
        $refund = $payment->refunds()->creditCardPartial(5000);
72
73
        $this->assertNotEmpty($refund->getId());
74
        $this->assertEquals('PARTIAL', $refund->getType());
75
    }
76
77 View Code Duplication
    public function testRefundPaymentBankAccountFull()
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...
78
    {
79
        $payment = $this->paymentBoleto();
80
81
        $this->mockHttpSession($this->body_payment_refund_full_bankaccount);
0 ignored issues
show
Bug introduced by
The property body_payment_refund_full_bankaccount does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
82
        $refund = $payment->refunds()
83
            ->bankAccountFull('CHECKING', '001', '1584', '9', '00210169', '6', $payment->getOrder()->getCustomer());
84
85
        $this->assertNotEmpty($refund->getId());
86
        $this->assertEquals('FULL', $refund->getType());
87
    }
88
89 View Code Duplication
    public function testRefundPaymentBankAccountPartial()
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...
90
    {
91
        $payment = $this->paymentBoleto();
92
93
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
94
        $refund = $payment->refunds()
95
            ->bankAccountPartial(20000, 'SAVING', '001', '1584', '9', '00210169', '6', $payment->getOrder()->getCustomer());
96
97
        $this->assertNotEmpty($refund->getId());
98
        $this->assertEquals('PARTIAL', $refund->getType());
99
    }
100
101 View Code Duplication
    public function testRefundCCFullWithResourceId()
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...
102
    {
103
        $payment = $this->paymentCreditCard();
104
105
        $this->mockHttpSession($this->body_payment_refund_full_cc);
106
        $refund = $this->moip->refunds()->creditCard($payment->getId());
107
108
        $this->assertNotEmpty($refund->getId());
109
        $this->assertEquals('FULL', $refund->getType());
110
    }
111
112 View Code Duplication
    public function testRefundCCPartialWithResourceId()
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...
113
    {
114
        $payment = $this->paymentCreditCard();
115
116
        $this->mockHttpSession($this->body_payment_refund_partial_cc);
117
        $refund = $this->moip->refunds()->creditCard($payment->getId(), 5000);
118
119
        $this->assertNotEmpty($refund->getId());
120
        $this->assertEquals('PARTIAL', $refund->getType());
121
    }
122
123 View Code Duplication
    public function testRefundBankAccountFullWithResourceId()
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...
124
    {
125
        $payment = $this->paymentBoleto();
126
127
        $this->mockHttpSession($this->body_payment_refund_full_bankaccount);
128
        $refund = $this->moip->refunds()->bankAccount($payment->getId(), $this->bankAccount());
129
130
        $this->assertNotEmpty($refund->getId());
131
        $this->assertEquals('FULL', $refund->getType());
132
    }
133
134 View Code Duplication
    public function testRefundBankAccountPartialWithResourceId()
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...
135
    {
136
        $payment = $this->paymentBoleto();
137
138
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
139
        $refund = $this->moip->refunds()->bankAccount($payment->getId(), $this->bankAccount(), 5000);
140
141
        $this->assertNotEmpty($refund->getId());
142
        $this->assertEquals('PARTIAL', $refund->getType());
143
    }
144
145 View Code Duplication
    public function testRefundOrderCCFullWithResourceId()
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...
146
    {
147
        $order = $this->paymentCreditCard(false);
148
149
        $this->mockHttpSession($this->body_order_refund_full_cc);
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
150
        $refund = $this->moip->refunds()->creditCard($order->getId());
151
152
        $this->assertNotEmpty($refund->getId());
153
        $this->assertEquals('FULL', $refund->getType());
154
    }
155
156 View Code Duplication
    public function testRefundOrderCCPartialWithResourceId()
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...
157
    {
158
        $order = $this->paymentCreditCard(false);
159
160
        $this->mockHttpSession($this->body_order_refund_partial_cc);
0 ignored issues
show
Bug introduced by
The property body_order_refund_partial_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
161
        $refund = $this->moip->refunds()->creditCard($order->getId(), 5000);
162
163
        $this->assertNotEmpty($refund->getId());
164
        $this->assertEquals('PARTIAL', $refund->getType());
165
    }
166
167 View Code Duplication
    public function testRefundOrderBankAccountFullWithResourceId()
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...
168
    {
169
        $order = $this->paymentBoleto(false);
170
171
        $this->mockHttpSession($this->body_order_refund_full_bankaccount);
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
172
        $refund = $this->moip->refunds()->bankAccount($order->getId(), $this->bankAccount());
173
174
        $this->assertNotEmpty($refund->getId());
175
        $this->assertEquals('FULL', $refund->getType());
176
    }
177
178 View Code Duplication
    public function testRefundOrderBankAccountPartialWithResourceId()
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...
179
    {
180
        $order = $this->paymentBoleto(false);
181
182
        $this->mockHttpSession($this->body_order_refund_partial_bankaccount);
0 ignored issues
show
Bug introduced by
The property body_order_refund_partial_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
183
        $refund = $this->moip->refunds()->bankAccount($order->getId(), $this->bankAccount(), 5000);
184
185
        $this->assertNotEmpty($refund->getId());
186
        $this->assertEquals('PARTIAL', $refund->getType());
187
    }
188
189
    private function bankAccount()
190
    {
191
        return $this->moip->bankaccount()
192
            ->setType('CHECKING')
193
            ->setBankNumber('237')
194
            ->setAgencyNumber('12346')
195
            ->setAgencyCheckNumber('0')
196
            ->setAccountNumber('12345679')
197
            ->setAccountCheckNumber('7')
198
            ->setHolder('Jose Silva', '22222222222', 'CPF');
199
    }
200
201 View Code Duplication
    private function paymentBoleto($returnPayment = true)
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...
202
    {
203
        $this->mockHttpSession($this->body_order);
204
        $order = $this->createOrder()->create();
205
        $this->mockHttpSession($this->body_billet_pay);
206
        $payment = $order->payments()
0 ignored issues
show
Bug introduced by
The method payments does only exist in Moip\Resource\Orders, but not in stdClass.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
207
            ->setBoleto(new \DateTime('today +1day'),'http://dev.moip.com.br/images/logo-header-moip.png')
208
            ->execute();
209
        $this->mockHttpSession('');
210
        $payment->authorize();
211
212
        return $returnPayment ? $payment : $order;
213
    }
214
215 View Code Duplication
    private function paymentCreditCard($returnPayment = true)
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...
216
    {
217
        $this->mockHttpSession($this->body_order);
218
        $order = $this->createOrder()->create();
219
        $this->mockHttpSession($this->body_cc_pay_pci);
220
        $payment = ($order->payments()->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer())->execute());
0 ignored issues
show
Bug introduced by
The method payments does only exist in Moip\Resource\Orders, but not in stdClass.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
221
222
        return $returnPayment ? $payment : $order;
223
    }
224
}
225