Completed
Push — master ( 4a5840...1f0278 )
by
unknown
11s
created

CustomerTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetBirthDateDateTime() 0 8 1
A testSetBirthDateString() 0 7 1
A testCustomerCreate() 0 12 1
A testShippingAddress() 0 14 1
A testCreateCreditCard() 0 22 1
1
<?php
2
3
namespace Moip\Tests\Resource;
4
5
use Moip\Resource\Customer;
6
use Moip\Tests\TestCase;
7
8
/**
9
 * class CustomerTest.
10
 */
11
class CustomerTest extends TestCase
12
{
13
    /**
14
     * MoipTest if the Customer object accepts a \DateTime object and correctly transforms it.
15
     */
16
    public function testSetBirthDateDateTime()
17
    {
18
        $dt = \DateTime::createFromFormat($this->date_format, $this->date_string);
19
        $customer = $this->moip->customers()->setBirthDate($dt);
0 ignored issues
show
Security Bug introduced by
It seems like $dt defined by \DateTime::createFromFor...at, $this->date_string) on line 18 can also be of type false; however, Moip\Resource\Customer::setBirthDate() does only seem to accept object<DateTime>|string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
20
        $this->assertEquals($dt, $customer->getBirthDate());
21
        $exp = "{\"birthDate\":\"$this->date_string\"}";
22
        $this->assertJsonStringEqualsJsonString($exp, json_encode($customer));
23
    }
24
25
    /**
26
     * MoipTest if the Customer object accepts a date string as argument.
27
     */
28
    public function testSetBirthDateString()
29
    {
30
        $customer = $this->moip->customers()->setBirthDate($this->date_string);
31
        $exp = "{\"birthDate\":\"$this->date_string\"}";
32
        $this->assertEquals($customer->getBirthDate()->format($this->date_format), $this->date_string);
33
        $this->assertJsonStringEqualsJsonString($exp, json_encode($customer));
34
    }
35
36
    /**
37
     * MoipTest customer creation.
38
     */
39
    public function testCustomerCreate()
40
    {
41
        $this->mockHttpSession($this->body_client);
42
43
        $customer_original = $this->createCustomer();
44
        /** @var Customer $customer */
45
        $customer = $customer_original->create();
46
47
        $this->assertEquals($customer_original->getFullname(), $customer->getFullname());
48
        $this->assertEquals($customer_original->getPhoneNumber(), $customer->getPhoneNumber());
49
        $this->assertEquals($customer_original->getBirthDate(), $customer->getBirthDate());
50
    }
51
52
    /**
53
     * MoipTest customer shipping address.
54
     */
55
    public function testShippingAddress()
56
    {
57
        $this->mockHttpSession($this->body_client);
58
        $customer_original = $this->createCustomer();
59
        $customer = $customer_original->create();
60
        /* @var Customer $customer */
61
        $this->assertEquals($customer_original->getShippingAddress()->street, $customer->getShippingAddress()->street);
62
        $this->assertEquals($customer_original->getShippingAddress()->streetNumber, $customer->getShippingAddress()->streetNumber);
63
        $this->assertEquals($customer_original->getShippingAddress()->complement, $customer->getShippingAddress()->complement);
64
        $this->assertEquals($customer_original->getShippingAddress()->city, $customer->getShippingAddress()->city);
65
        $this->assertEquals($customer_original->getShippingAddress()->state, $customer->getShippingAddress()->state);
66
        $this->assertEquals($customer_original->getShippingAddress()->country, $customer->getShippingAddress()->country);
67
        $this->assertEquals($customer_original->getShippingAddress()->zipCode, $customer->getShippingAddress()->zipCode);
68
    }
69
70
    /**
71
     * MoipTest create credit card for customer.
72
     */
73
    public function testCreateCreditCard()
74
    {
75
        $this->mockHttpSession($this->body_client);
76
        $customer = $this->createCustomer()->create();
77
78
        $this->mockHttpSession($this->body_add_credit_card);
0 ignored issues
show
Bug introduced by
The property body_add_credit_card 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...
79
80
        $creditCard = $this->moip->customers()->creditCard()
81
            ->setExpirationMonth('05')
82
            ->setExpirationYear(2018)
83
            ->setNumber('4012001037141112')
84
            ->setCVC('123')
85
            ->setFullName('Jose Portador da Silva')
86
            ->setBirthDate('1988-12-30')
87
            ->setTaxDocument('CPF', '33333333333')
88
            ->setPhone('55', '11', '66778899')
89
            ->create($customer->getId());
90
91
        $this->assertNotEmpty($creditCard->getId());
92
        $this->assertEquals($creditCard->getFirst6(), '401200');
93
        $this->assertEquals($creditCard->getLast4(), '1112');
94
    }
95
}
96