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); |
|
|
|
|
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
|
|
|
$this->assertEquals($customer_original->getTaxDocumentType(), $customer->getTaxDocumentType()); |
51
|
|
|
$this->assertEquals($customer_original->getTaxDocumentNumber(), $customer->getTaxDocumentNumber()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* MoipTest customer shipping address. |
56
|
|
|
*/ |
57
|
|
|
public function testShippingAddress() |
58
|
|
|
{ |
59
|
|
|
$this->mockHttpSession($this->body_client); |
60
|
|
|
$customer_original = $this->createCustomer(); |
61
|
|
|
$customer = $customer_original->create(); |
62
|
|
|
/* @var Customer $customer */ |
63
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->street, $customer->getShippingAddress()->street); |
64
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->streetNumber, $customer->getShippingAddress()->streetNumber); |
65
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->complement, $customer->getShippingAddress()->complement); |
66
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->city, $customer->getShippingAddress()->city); |
67
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->state, $customer->getShippingAddress()->state); |
68
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->country, $customer->getShippingAddress()->country); |
69
|
|
|
$this->assertEquals($customer_original->getShippingAddress()->zipCode, $customer->getShippingAddress()->zipCode); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* MoipTest create credit card for customer. |
74
|
|
|
*/ |
75
|
|
|
public function testCreateCreditCard() |
76
|
|
|
{ |
77
|
|
|
$this->mockHttpSession($this->body_client); |
78
|
|
|
$customer = $this->createCustomer()->create(); |
79
|
|
|
|
80
|
|
|
$this->mockHttpSession($this->body_add_credit_card); |
|
|
|
|
81
|
|
|
|
82
|
|
|
$creditCard = $this->moip->customers()->creditCard() |
83
|
|
|
->setExpirationMonth('05') |
84
|
|
|
->setExpirationYear(2018) |
85
|
|
|
->setNumber('4012001037141112') |
86
|
|
|
->setCVC('123') |
87
|
|
|
->setFullName('Jose Portador da Silva') |
88
|
|
|
->setBirthDate('1988-12-30') |
89
|
|
|
->setTaxDocument('CPF', '33333333333') |
90
|
|
|
->setPhone('55', '11', '66778899') |
91
|
|
|
->create($customer->getId()); |
92
|
|
|
|
93
|
|
|
$this->assertNotEmpty($creditCard->getId()); |
94
|
|
|
$this->assertEquals($creditCard->getFirst6(), '401200'); |
95
|
|
|
$this->assertEquals($creditCard->getLast4(), '1112'); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
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 returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.