Completed
Push — master ( 1b5410...64fdd0 )
by Jean C.
28s
created

testShouldCreateEscrowPaymentWithCreditCard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 12
loc 12
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
    public function testBillet()
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