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 | //todo: add the ability to use the play(https://github.com/rodrigosaito/mockwebserver-player) files from the jada sdk |
||
42 | //the two responses below were based on the moip Java sdk's test files (https://github.com/moip/moip-sdk-java/) |
||
43 | /** |
||
44 | * @var string response from the client moip API. |
||
45 | */ |
||
46 | protected $body_client; |
||
47 | |||
48 | /** |
||
49 | * @var string response from the order moip API. |
||
50 | */ |
||
51 | protected $body_order; |
||
52 | |||
53 | /** |
||
54 | * @var string response from moip API. |
||
55 | */ |
||
56 | protected $body_cc_pay_pci; |
||
57 | |||
58 | /** |
||
59 | * @var string response from moip API. |
||
60 | */ |
||
61 | protected $body_cc_pay_pci_store; |
||
62 | |||
63 | /** |
||
64 | * @var string response from moip API. |
||
65 | */ |
||
66 | protected $body_cc_pay_pci_escrow; |
||
67 | |||
68 | /** |
||
69 | * @var string response from moip API. |
||
70 | */ |
||
71 | protected $body_release_escrow; |
||
72 | |||
73 | /** |
||
74 | * @var string response from moip API. |
||
75 | */ |
||
76 | protected $body_billet_pay; |
||
77 | |||
78 | /** |
||
79 | * @var string response from moip API. |
||
80 | */ |
||
81 | protected $body_refund_full_bankaccount; |
||
82 | |||
83 | /** |
||
84 | * @var string response from moip API. |
||
85 | */ |
||
86 | protected $body_refund_partial_bankaccount; |
||
87 | |||
88 | /** |
||
89 | * @var string response from moip API. |
||
90 | */ |
||
91 | protected $body_notification_preference; |
||
92 | |||
93 | /** |
||
94 | * @var string response from moip API. |
||
95 | */ |
||
96 | protected $body_moip_account; |
||
97 | |||
98 | /** |
||
99 | * @var string response from moip API. |
||
100 | */ |
||
101 | protected $body_order_list; |
||
102 | |||
103 | /** |
||
104 | * @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode. |
||
105 | */ |
||
106 | protected $last_cus_id = 'meu_id_customer'; |
||
107 | |||
108 | /** |
||
109 | * @var string same as `$last_cus_id` but for orders. |
||
110 | * |
||
111 | * @see $last_cus_id |
||
112 | */ |
||
113 | protected $last_ord_id = 'meu_id_pedido'; |
||
114 | protected $sandbox_mock = self::MOCK; |
||
115 | |||
116 | public function __construct() { |
||
145 | |||
146 | /** |
||
147 | * Sets up the fixture, for example, open a network connection. |
||
148 | * This method is called before a test is executed. |
||
149 | */ |
||
150 | public function setUp() |
||
164 | |||
165 | /** |
||
166 | * Method to read JSON from a file. |
||
167 | * |
||
168 | * @param string $filename location of file |
||
169 | */ |
||
170 | public function readJsonFile($filename) |
||
174 | |||
175 | /** |
||
176 | * If in MOCK mode returns a mocked Requests_Sessesion if in SANDBOX mode, creates a new session. |
||
177 | * |
||
178 | * @param string $body what the request will return |
||
179 | * @param int $status_code what http code the request will return |
||
180 | */ |
||
181 | public function mockHttpSession($body, $status_code = 200) |
||
195 | |||
196 | /** |
||
197 | * Creates a customer. |
||
198 | * |
||
199 | * @return Customer |
||
200 | */ |
||
201 | public function createCustomer() |
||
219 | |||
220 | /** |
||
221 | * Creates a account. |
||
222 | * |
||
223 | * @return Account |
||
224 | */ |
||
225 | public function createAccount() |
||
244 | |||
245 | /** |
||
246 | * Creates an order. |
||
247 | * |
||
248 | * @return Orders |
||
249 | */ |
||
250 | public function createOrder() |
||
267 | |||
268 | /** |
||
269 | * Tears down the fixture, for example, close a network connection. |
||
270 | * This method is called after a test is executed. |
||
271 | */ |
||
272 | public function tearDown() |
||
276 | } |
||
277 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: