1 | <?php |
||
15 | abstract class TestCase extends PHPUnit_Framework_TestCase |
||
16 | { |
||
17 | /** |
||
18 | * Variables representing the test modes. On MOCK mode no http request will be made. |
||
19 | * In SANDBOX mode HTTP requests will be made to the Moip::SANDBOX_ENDPOINT, the authentication information |
||
20 | * is retrieved from the MOIP_TOKEN and MOIP_KEY environment variables. |
||
21 | */ |
||
22 | const MOCK = 'mock'; |
||
23 | const SANDBOX = 'sandbox'; |
||
24 | |||
25 | /** |
||
26 | * Intance of \Moip\Moip. |
||
27 | * |
||
28 | * @var \Moip\Moip |
||
29 | **/ |
||
30 | protected $moip; |
||
31 | |||
32 | /** |
||
33 | * @var string current format for dates. |
||
34 | */ |
||
35 | protected $date_format = 'Y-m-d'; |
||
36 | |||
37 | /** |
||
38 | * @var string date used for testing. |
||
39 | */ |
||
40 | protected $date_string = '1989-06-01'; |
||
41 | |||
42 | //todo: add the ability to use the play(https://github.com/rodrigosaito/mockwebserver-player) files from the jada sdk |
||
43 | //the two responses below were based on the moip Java sdk's test files (https://github.com/moip/moip-sdk-java/) |
||
44 | /** |
||
45 | * @var string response from the client moip API. |
||
46 | */ |
||
47 | protected $body_client = '{"id":"CUS-CFMKXQBZNJQQ","ownId":"meu_id_sandbox","fullname":"Jose Silva","email":"[email protected]","phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","state":"SP","country":"BRA","zipCode":"01234000"},"fundingInstruments":[],"createdAt":"2016-02-18T19:55:00.000-02","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-CFMKXQBZNJQQ"}}}'; |
||
48 | |||
49 | /** |
||
50 | * @var string response from the order moip API. |
||
51 | */ |
||
52 | protected $body_order = '{"id":"ORD-HG479ZEIB7LV","ownId":"meu_id_pedido","status":"CREATED","createdAt":"2016-02-19T12:24:55.849-02","updatedAt":"2016-02-19T12:24:55.849-02","amount":{"total":102470,"fees":0,"refunds":0,"liquid":0,"otherReceivers":0,"currency":"BRL","subtotals":{"shipping":1490,"addition":0,"discount":1000,"items":101980}},"items":[{"price":100000,"detail":"Mais info...","quantity":1,"product":"Nome do produto"},{"price":990,"detail":"Abacaxi de terra de areia","quantity":2,"product":"abacaxi"}],"customer":{"id":"CUS-7U5K9KWG8DBZ","ownId":"meu_id_saasdadadsnasdasddboxssssssssss","fullname":"Jose Silva","createdAt":"2016-02-18T20:03:28.000-02","birthDate":"1989-06-01T00:00:00.000-03","email":"[email protected]","phone":{"countryCode":"55","areaCode":"11","number":"66778899"},"taxDocument":{"type":"CPF","number":"22222222222"},"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/customers/CUS-7U5K9KWG8DBZ"}}},"payments":[],"refunds":[],"entries":[],"events":[{"type":"ORDER.CREATED","createdAt":"2016-02-19T12:24:55.849-02","description":""}],"receivers":[{"moipAccount":{"id":"MPA-7ED9D2D0BC81","login":"[email protected]","fullname":"Carmen Elisabete de Menezes ME"},"type":"PRIMARY","amount":{"total":102470,"fees":0,"refunds":0}}],"shippingAddress":{"zipCode":"01234000","street":"Avenida Faria Lima","streetNumber":"2927","complement":"8","city":"Sao Paulo","district":"Itaim","state":"SP","country":"BRA"},"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-HG479ZEIB7LV"},"checkout":{"payOnlineBankDebitItau":{"redirectHref":"https://checkout-sandbox.moip.com.br/debit/itau/ORD-HG479ZEIB7LV"},"payCreditCard":{"redirectHref":"https://checkout-sandbox.moip.com.br/creditcard/ORD-HG479ZEIB7LV"},"payBoleto":{"redirectHref":"https://checkout-sandbox.moip.com.br/boleto/ORD-HG479ZEIB7LV"}}}}'; |
||
53 | |||
54 | /** |
||
55 | * @var string response from moip API. |
||
56 | */ |
||
57 | protected $body_cc_pay_pci = '{"id":"PAY-L6J2NKS9OGYU","status":"IN_ANALYSIS","delayCapture":false,"amount":{"total":102470,"fees":5695,"refunds":0,"liquid":96775,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"creditCard":{"id":"CRC-2TJ13YB4Y1WU","brand":"MASTERCARD","first6":"555566","last4":"8884","holder":{"birthdate":"1989-06-01","birthDate":"1989-06-01","taxDocument":{"type":"CPF","number":"22222222222"},"fullname":"Jose Silva"}},"method":"CREDIT_CARD"},"fees":[{"type":"TRANSACTION","amount":5695}],"events":[{"type":"PAYMENT.IN_ANALYSIS","createdAt":"2016-02-19T18:18:54.535-02"},{"type":"PAYMENT.CREATED","createdAt":"2016-02-19T18:18:51.946-02"}],"_links":{"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-8UDL4K9VRJTB","title":"ORD-8UDL4K9VRJTB"},"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-L6J2NKS9OGYU"}},"createdAt":"2016-02-19T18:18:51.944-02","updatedAt":"2016-02-19T18:18:54.535-02"}'; |
||
58 | |||
59 | /** |
||
60 | * @var string response from moip API. |
||
61 | */ |
||
62 | protected $body_billet_pay = '{"id":"PAY-XNVIBO5MIQ9S","status":"WAITING","delayCapture":false,"amount":{"total":102470,"fees":3645,"refunds":0,"liquid":98825,"currency":"BRL"},"installmentCount":1,"fundingInstrument":{"boleto":{"expirationDate":"2016-05-21","lineCode":"23793.39126 60000.062608 32001.747909 7 68010000102470"},"method":"BOLETO"},"fees":[{"type":"TRANSACTION","amount":3645}],"events":[{"type":"PAYMENT.CREATED","createdAt":"2016-05-20T15:19:47.000-03"},{"type":"PAYMENT.WAITING","createdAt":"2016-05-20T15:19:47.000-03"}],"_links":{"order":{"href":"https://sandbox.moip.com.br/v2/orders/ORD-3KSQDBJSTIF6","title":"ORD-3KSQDBJSTIF6"},"payBoleto":{"redirectHref":"https://checkout-sandbox.moip.com.br/boleto/PAY-XNVIBO5MIQ9S"},"self":{"href":"https://sandbox.moip.com.br/v2/payments/PAY-XNVIBO5MIQ9S"}},"updatedAt":"2016-05-20T15:19:47.000-03","createdAt":"2016-05-20T15:19:47.000-03"}'; |
||
63 | |||
64 | /** |
||
65 | * @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode. |
||
66 | */ |
||
67 | protected $last_cus_id = 'meu_id_customer'; |
||
68 | |||
69 | /** |
||
70 | * @var string same as `$last_cus_id` but for orders. |
||
71 | * |
||
72 | * @see $last_cus_id |
||
73 | */ |
||
74 | protected $last_ord_id = 'meu_id_pedido'; |
||
75 | |||
76 | protected $sandbox_mock = self::MOCK; |
||
77 | |||
78 | /** |
||
79 | * Sets up the fixture, for example, open a network connection. |
||
80 | * This method is called before a test is executed. |
||
81 | */ |
||
82 | public function setUp() |
||
97 | |||
98 | /** |
||
99 | * If in MOCK mode returns a mocked Requests_Sessesion if in SANDBOX mode, creates a new session. |
||
100 | * |
||
101 | * @param string $body what the request will return |
||
102 | * @param int $status_code what http code the request will return |
||
103 | */ |
||
104 | public function mockHttpSession($body, $status_code = 200) |
||
118 | |||
119 | /** |
||
120 | * Creates a customer. |
||
121 | * |
||
122 | * @return Customer |
||
123 | */ |
||
124 | public function createCustomer() |
||
143 | |||
144 | /** |
||
145 | * Creates a account. |
||
146 | * |
||
147 | * @return Account |
||
148 | */ |
||
149 | public function createAccount() |
||
168 | |||
169 | /** |
||
170 | * Creates an order. |
||
171 | * |
||
172 | * @return Orders |
||
173 | */ |
||
174 | public function createOrder() |
||
191 | |||
192 | /** |
||
193 | * Tears down the fixture, for example, close a network connection. |
||
194 | * This method is called after a test is executed. |
||
195 | */ |
||
196 | public function tearDown() |
||
200 | } |
||
201 |