Completed
Push — master ( 1f0278...22c246 )
by
unknown
12s
created

testCapturePreAuthorizedMultiPayment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 15
loc 15
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 PaymentTest extends TestCase
8
{
9
    //todo: credit card hash
10
11
    /**
12
     * MoipTest creating a credit card payment, passing all credit card data.
13
     */
14
    public function testCreditCardPCI()
15
    {
16
        $this->mockHttpSession($this->body_order);
17
        $order = $this->createOrder()->create();
18
        $this->mockHttpSession($this->body_cc_pay_pci);
19
        $cc = '5555666677778884';
20
        $payment = $order->payments()->setCreditCard(5, 2018, $cc, 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...
21
        $this->assertNotEmpty($payment->getFundingInstrument()->creditCard);
22
        $first6 = $payment->getFundingInstrument()->creditCard->first6;
23
        $last4 = $payment->getFundingInstrument()->creditCard->last4;
24
        $this->assertEquals($first6, substr($cc, 0, 6));
25
        $this->assertEquals($last4, substr($cc, -4));
26
    }
27
28
    /**
29
     * MoipTest creating a billet payment.
30
     */
31 View Code Duplication
    public function testBillet()
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
        $this->mockHttpSession($this->body_order);
34
        $order = $this->createOrder()->create();
35
        $this->mockHttpSession($this->body_billet_pay);
36
        $payment = $order->payments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->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...
37
        $this->assertNotEmpty($payment->getFundingInstrument()->boleto);
38
    }
39
40 View Code Duplication
    public function testCreditCardPCIStore()
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...
41
    {
42
        $this->mockHttpSession($this->body_order);
43
        $order = $this->createOrder()->create();
44
        $cc = '5555666677778884';
45
        $this->mockHttpSession($this->body_cc_pay_pci_store);
46
        $payment = $order->payments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false)->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...
47
        $this->assertFalse($payment->getFundingInstrument()->creditCard->store);
48
        $this->assertNotEmpty($payment->getId());
49
    }
50
51 View Code Duplication
    public function testShouldCreateEscrowPaymentWithCreditCard()
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...
52
    {
53
        $this->mockHttpSession($this->body_order);
54
        $order = $this->createOrder()->create();
55
        $cc = '5555666677778884';
56
        $this->mockHttpSession($this->body_cc_pay_pci_escrow);
57
        $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...
58
            ->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false)
59
            ->setEscrow('teste de descricao')
60
            ->execute();
61
        $this->assertEquals('teste de descricao', $payment->getEscrow()->description);
62
    }
63
64
    /**
65
     * MoipTest creating a credit card multipayment, passing all credit card data.
66
     */
67
    public function testMultipaymentCreditCardPCI()
68
    {
69
        $this->mockHttpSession($this->body_multiorder);
0 ignored issues
show
Bug introduced by
The property body_multiorder 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...
70
        $order = $this->createMultiorder()->create();
71
        $this->mockHttpSession($this->body_cc_multipay);
0 ignored issues
show
Bug introduced by
The property body_cc_multipay 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...
72
        $cc = '4012001037141112';
73
        $payment = $order->multipayments()->setCreditCard(5, 2018, $cc, 123, $this->createCustomer())->execute();
74
75
        $first6 = $payment->getPayments()[0]->fundingInstrument->creditCard->first6;
76
        $last4 = $payment->getPayments()[0]->fundingInstrument->creditCard->last4;
77
        $this->assertEquals($first6, substr($cc, 0, 6));
78
        $this->assertEquals($last4, substr($cc, -4));
79
    }
80
81
    /**
82
     * MoipTest creating a billet multipayment.
83
     */
84 View Code Duplication
    public function testMultipaymentBillet()
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...
85
    {
86
        $this->mockHttpSession($this->body_multiorder);
87
        $order = $this->createMultiorder()->create();
88
        $this->mockHttpSession($this->body_billet_multipay);
0 ignored issues
show
Bug introduced by
The property body_billet_multipay 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...
89
        $payment = $order->multipayments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute();
90
        $this->assertNotEmpty($payment->getFundingInstrument()->boleto);
91
    }
92
93 View Code Duplication
    public function testCapturePreAuthorizedPayment()
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...
94
    {
95
        $this->mockHttpSession($this->body_order);
96
        $order = $this->createOrder()->create();
97
        $this->mockHttpSession($this->body_cc_delay_capture);
0 ignored issues
show
Bug introduced by
The property body_cc_delay_capture 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...
98
        $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...
99
            ->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false)
100
            ->setDelayCapture(true)
101
            ->execute();
102
103
        $this->mockHttpSession($this->body_capture_pay);
0 ignored issues
show
Bug introduced by
The property body_capture_pay 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...
104
        $captured_payment = $payment->capture();
105
106
        $this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
107
    }
108
109 View Code Duplication
    public function testCapturePreAuthorizedMultiPayment()
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...
110
    {
111
        $this->mockHttpSession($this->body_multiorder);
112
        $order = $this->createMultiorder()->create();
113
        $this->mockHttpSession($this->body_cc_multipay);
114
        $payment = $order->multipayments()
115
            ->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())
116
            ->setDelayCapture(true)
117
            ->execute();
118
119
        $this->mockHttpSession($this->body_capture_multipay);
0 ignored issues
show
Bug introduced by
The property body_capture_multipay 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...
120
        $captured_payment = $payment->capture();
121
122
        $this->assertEquals('AUTHORIZED', $captured_payment->getStatus());
123
    }
124
125 View Code Duplication
    public function testCancelPreAuthorizedMultiPayment()
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...
126
    {
127
        $this->mockHttpSession($this->body_multiorder);
128
        $order = $this->createMultiorder()->create();
129
        $this->mockHttpSession($this->body_cc_multipay);
130
        $payment = $order->multipayments()
131
            ->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())
132
            ->setDelayCapture(true)
133
            ->execute();
134
135
        $this->mockHttpSession($this->body_cancel_multipay);
0 ignored issues
show
Bug introduced by
The property body_cancel_multipay 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...
136
        $cancelled_payment = $payment->cancel();
137
138
        $this->assertEquals('CANCELLED', $cancelled_payment->getStatus());
139
    }
140
141 View Code Duplication
    public function testCancelPreAuthorizedPayment()
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...
142
    {
143
        $this->mockHttpSession($this->body_order);
144
        $order = $this->createOrder()->create();
145
        $this->mockHttpSession($this->body_cc_delay_capture);
146
        $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...
147
            ->setCreditCard(5, 2018, '5555666677778884', 123, $this->createCustomer(), false)
148
            ->setDelayCapture(true)
149
            ->execute();
150
151
        $this->mockHttpSession($this->body_cancel_pay);
0 ignored issues
show
Bug introduced by
The property body_cancel_pay 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...
152
        $cancelled_payment = $payment->cancel();
153
154
        $this->assertEquals('CANCELLED', $cancelled_payment->getStatus());
155
    }
156
157
    public function testGetPayment()
158
    {
159
        $this->mockHttpSession($this->body_order);
160
        $order = $this->createOrder()->create();
161
        $this->mockHttpSession($this->body_cc_pay_pci);
162
        $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...
163
164
        $this->mockHttpSession($this->body_get_pay);
0 ignored issues
show
Bug introduced by
The property body_get_pay 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...
165
        $payment_get = $this->moip->payments()->get($payment->getId());
166
167
        $this->assertEquals($payment_get->getAmount()->total, 102470);
168
        $this->assertEquals($payment_get->getFundingInstrument()->method, 'CREDIT_CARD');
169
        $this->assertEquals($payment_get->getInstallmentCount(), 1);
170
    }
171
172
    public function testGetMultiPayment()
173
    {
174
        $this->mockHttpSession($this->body_multiorder);
175
        $order = $this->createMultiorder()->create();
176
        $this->mockHttpSession($this->body_cc_multipay);
177
        $payment = $order->multipayments()->setCreditCard(5, 2018, '4012001037141112', 123, $this->createCustomer())->execute();
178
179
        $this->mockHttpSession($this->body_get_multipay);
0 ignored issues
show
Bug introduced by
The property body_get_multipay 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...
180
        $payment_get = $this->moip->payments()->get($payment->getId());
181
182
        $this->assertEquals($payment_get->getAmount()->total, 77000);
183
        $this->assertNotNull($payment_get->getPayments());
184
    }
185
}
186