Completed
Push — master ( 2e7298...3749b5 )
by
unknown
11s
created

tTaxDocumentIsValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Moip\Tests\Resource;
4
5
use Moip\Resource\Customer;
6
use Moip\Tests\MoipTestCase;
7
8
/**
9
 * class CustomerTest.
10
 */
11
class CustomerTest extends MoipTestCase
12
{
13
    /**
14
     * Test 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
     * Test 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
     * Test 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
     * Test 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