Completed
Pull Request — master (#247)
by
unknown
14:42
created

TestCase::createHolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 1
eloc 7
c 2
b 1
f 1
nc 1
nop 0
dl 0
loc 10
rs 9.4285
1
<?php
2
3
namespace Moip\Tests;
4
5
use Moip\Auth\OAuth;
6
use Moip\Moip;
7
use Moip\Resource\Customer;
8
use Moip\Resource\Holder;
9
use Moip\Resource\Orders;
10
use PHPUnit\Framework\TestCase as BaseTestCase;
11
use Requests_Response;
12
13
/**
14
 * class TestCase.
15
 */
16
abstract class TestCase extends BaseTestCase
17
{
18
    /**
19
     * Variables representing the test modes. On MOCK mode no http request will be made.
20
     * In SANDBOX mode HTTP requests will be made to the Moip::SANDBOX_ENDPOINT, the authentication information
21
     * is retrieved from the MOIP_TOKEN and MOIP_KEY environment variables.
22
     */
23
    const MOCK = 'mock';
24
    const SANDBOX = 'sandbox';
25
26
    /**
27
     * Intance of \Moip\Moip.
28
     *
29
     * @var \Moip\Moip
30
     * */
31
    protected $moip;
32
33
    /**
34
     * @var string current format for dates.
35
     */
36
    protected $date_format = 'Y-m-d';
37
38
    /**
39
     * @var string date used for testing.
40
     */
41
    protected $date_string = '1989-06-01';
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;
48
49
    /**
50
     * @var string response from the order moip API.
51
     */
52
    protected $body_order;
53
54
    /**
55
     * @var string response from moip API.
56
     */
57
    protected $body_cc_pay_pci;
58
59
    /**
60
     * @var string response from moip API.
61
     */
62
    protected $body_cc_pay_pci_store;
63
64
    /**
65
     * @var string response from moip API.
66
     */
67
    protected $body_cc_pay_pci_escrow;
68
69
    /**
70
     * @var string response from moip API.
71
     */
72
    protected $body_release_escrow;
73
74
    /**
75
     * @var string response from moip API.
76
     */
77
    protected $body_billet_pay;
78
79
    /**
80
     * @var string response from moip API.
81
     */
82
    protected $body_refund_full_bankaccount;
83
84
    /**
85
     * @var string response from moip API.
86
     */
87
    protected $body_refund_partial_bankaccount;
88
89
    /**
90
     * @var string response from moip API.
91
     */
92
    protected $body_notification_preference;
93
94
    /**
95
     * @var string response from moip API.
96
     */
97
    protected $body_moip_account_create;
98
99
    /**
100
     * @var string response from moip API.
101
     */
102
    protected $body_moip_account_get;
103
104
    /**
105
     * @var string response from moip API.
106
     */
107
    protected $body_order_list;
108
109
    /**
110
     * @var string response from moip API.
111
     */
112
    protected $body_notification_list;
113
114
    /**
115
     * @var string response from moip API.
116
     */
117
    protected $body_transfers_create;
118
119
    /**
120
     * @var string response from moip API.
121
     */
122
    protected $body_transfers_list;
123
124
    /**
125
     * @var string response from moip API.
126
     */
127
    protected $body_transfers_revert;
128
129
    /**
130
     * @var string response from moip API.
131
     */
132
    protected $body_bank_account_create;
133
134
    /**
135
     * @var string response from moip API.
136
     */
137
    protected $body_bank_account_list;
138
139
    /**
140
     * @var string response from moip API.
141
     */
142
    protected $body_bank_account_update;
143
144
    /**
145
     * @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode.
146
     */
147
    protected $last_cus_id = 'meu_id_customer';
148
149
    /**
150
     * @var string same as `$last_cus_id` but for orders.
151
     *
152
     * @see $last_cus_id
153
     */
154
    protected $last_ord_id = 'meu_id_pedido';
155
    protected $sandbox_mock = self::MOCK;
156
157
    public function __construct()
158
    {
159
        parent::__construct();
160
161
        $this->body_client = $this->readJsonFile('jsons/customer/create');
162
163
        $this->body_order = $this->readJsonFile('jsons/order/create');
164
165
        $this->body_cc_pay_pci = $this->readJsonFile('jsons/payment/create_cc_pci');
166
167
        $this->body_cc_pay_pci_store = $this->readJsonFile('jsons/payment/create_cc_pci_store');
168
169
        $this->body_cc_pay_pci_escrow = $this->readJsonFile('jsons/payment/create_cc_pci_escrow');
170
171
        $this->body_release_escrow = $this->readJsonFile('jsons/escrow/release');
172
173
        $this->body_billet_pay = $this->readJsonFile('jsons/payment/create_billet');
174
175
        $this->body_billet_multipay = $this->readJsonFile('jsons/multipayment/create_billet');
0 ignored issues
show
Bug introduced by
The property body_billet_multipay 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...
176
177
        $this->body_refund_full_bankaccount = $this->readJsonFile('jsons/refund/full_bankaccount');
178
179
        $this->body_cc_multipay = $this->readJsonFile('jsons/multipayment/create_cc');
0 ignored issues
show
Bug introduced by
The property body_cc_multipay 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...
180
181
        $this->body_notification_preference = $this->readJsonFile('jsons/notification/create');
182
183
        $this->body_moip_account_create = $this->readJsonFile('jsons/account/create');
184
185
        $this->body_moip_account_get = $this->readJsonFile('jsons/account/get');
186
187
        $this->body_order_list = $this->readJsonFile('jsons/order/get_list');
188
189
        $this->body_add_credit_card = $this->readJsonFile('jsons/customer/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...
190
191
        $this->body_list_webhook_no_filter = $this->readJsonFile('jsons/webhooks/get_no_filter');
0 ignored issues
show
Bug introduced by
The property body_list_webhook_no_filter 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...
192
193
        $this->body_list_webhook_pagination = $this->readJsonFile('jsons/webhooks/get_pagination');
0 ignored issues
show
Bug introduced by
The property body_list_webhook_pagination 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...
194
195
        $this->body_list_webhook_all_filters = $this->readJsonFile('jsons/webhooks/get_all_filters');
0 ignored issues
show
Bug introduced by
The property body_list_webhook_all_filters 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...
196
197
        $this->body_notification_list = $this->readJsonFile('jsons/notification/list');
198
199
        $this->body_multiorder = $this->readJsonFile('jsons/multiorder/create');
0 ignored issues
show
Bug introduced by
The property body_multiorder 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...
200
201
        $this->body_cc_delay_capture = $this->readJsonFile('jsons/payment/create_cc_delay_capture');
0 ignored issues
show
Bug introduced by
The property body_cc_delay_capture 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...
202
203
        $this->body_capture_pay = $this->readJsonFile('jsons/payment/capture');
0 ignored issues
show
Bug introduced by
The property body_capture_pay 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...
204
205
        $this->body_capture_multipay = $this->readJsonFile('jsons/multipayment/capture');
0 ignored issues
show
Bug introduced by
The property body_capture_multipay 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...
206
207
        $this->body_cancel_pay = $this->readJsonFile('jsons/payment/cancel_pre_authorized');
0 ignored issues
show
Bug introduced by
The property body_cancel_pay 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...
208
209
        $this->body_cancel_multipay = $this->readJsonFile('jsons/multipayment/cancel_pre_authorized');
0 ignored issues
show
Bug introduced by
The property body_cancel_multipay 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...
210
211
        $this->body_get_pay = $this->readJsonFile('jsons/payment/get');
0 ignored issues
show
Bug introduced by
The property body_get_pay 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...
212
213
        $this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get');
0 ignored issues
show
Bug introduced by
The property body_get_multipay 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...
214
215
        $this->body_keys = $this->readJsonFile('jsons/keys/get');
0 ignored issues
show
Bug introduced by
The property body_keys 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...
216
217
        $this->body_transfers_create = $this->readJsonFile('jsons/transfers/create');
218
219
        $this->body_transfers_list = $this->readJsonFile('jsons/transfers/list');
220
221
        $this->body_transfers_revert = $this->readJsonFile('jsons/transfers/revert');
222
223
        $this->body_keys = $this->readJsonFile('jsons/keys/get');
224
225
        $this->body_order_refund_full_bankaccount = $this->readJsonFile('jsons/refund/order_full_bankaccount');
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
226
227
        $this->body_payment_refund_full_bankaccount = $this->readJsonFile('jsons/refund/payment_full_bankaccount');
0 ignored issues
show
Bug introduced by
The property body_payment_refund_full_bankaccount 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...
228
229
        $this->body_order_refund_partial_bankaccount = $this->readJsonFile('jsons/refund/order_partial_bankaccount');
0 ignored issues
show
Bug introduced by
The property body_order_refund_partial_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
230
231
        $this->body_payment_refund_partial_bankaccount = $this->readJsonFile('jsons/refund/payment_partial_bankaccount');
0 ignored issues
show
Bug introduced by
The property body_payment_refund_partial_bankaccount 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...
232
233
        $this->body_order_refund_full_cc = $this->readJsonFile('jsons/refund/order_full_cc');
0 ignored issues
show
Bug introduced by
The property body_order_refund_full_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
234
235
        $this->body_payment_refund_full_cc = $this->readJsonFile('jsons/refund/payment_full_cc');
0 ignored issues
show
Bug introduced by
The property body_payment_refund_full_cc 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...
236
237
        $this->body_order_refund_partial_cc = $this->readJsonFile('jsons/refund/order_partial_cc');
0 ignored issues
show
Bug introduced by
The property body_order_refund_partial_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
238
239
        $this->body_payment_refund_partial_cc = $this->readJsonFile('jsons/refund/payment_partial_cc');
0 ignored issues
show
Bug introduced by
The property body_payment_refund_partial_cc 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...
240
241
        $this->body_bank_account_create = $this->readJsonFile('jsons/bank_account/create');
242
243
        $this->body_bank_account_list = $this->readJsonFile('jsons/bank_account/list');
244
245
        $this->body_bank_account_update = $this->readJsonFile('jsons/bank_account/update');
246
    }
247
248
    /**
249
     * Sets up the fixture, for example, open a network connection.
250
     * This method is called before a test is executed.
251
     */
252
    public function setUp()
253
    {
254
        // check if we can run the request on sandbox
255
        $moip_access_token = getenv('MOIP_ACCESS_TOKEN');
256
257
        if ($moip_access_token) {
258
            $this->sandbox_mock = self::SANDBOX;
259
            $auth = new OAuth($moip_access_token);
260
        } else {
261
            $this->sandbox_mock = self::MOCK;
262
            $auth = $this->getMockBuilder('\Moip\Contracts\Authentication')->getMock();
263
        }
264
        $this->moip = new Moip($auth, Moip::ENDPOINT_SANDBOX);
265
    }
266
267
    /**
268
     * Method to read JSON from a file.
269
     *
270
     * @param string $filename location of file
271
     */
272
    public function readJsonFile($filename)
273
    {
274
        return file_get_contents($filename.'.json', FILE_USE_INCLUDE_PATH);
275
    }
276
277
    /**
278
     * If in MOCK mode returns a mocked Requests_Sessesion if in SANDBOX mode, creates a new session.
279
     *
280
     * @param string $body        what the request will return
281
     * @param int    $status_code what http code the request will return
282
     */
283
    public function mockHttpSession($body, $status_code = 200)
284
    {
285
        if ($this->sandbox_mock == self::SANDBOX) {
286
            $this->moip->createNewSession();
287
288
            return;
289
        }
290
        $resp = new Requests_Response();
291
        $resp->body = $body;
292
        $resp->status_code = $status_code;
293
        $sess = $this->getMockBuilder('\Requests_Session')->getMock();
294
        $sess->expects($this->once())->method('request')->willReturn($resp);
295
        $this->moip->setSession($sess);
0 ignored issues
show
Documentation introduced by
$sess is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Requests_Session>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
296
    }
297
298
    /**
299
     * Creates a customer.
300
     *
301
     * @return Customer
302
     */
303
    public function createCustomer()
304
    {
305
        if ($this->sandbox_mock == self::SANDBOX) {
306
            $this->last_cus_id = uniqid('CUS-');
307
        } else {
308
            $this->last_cus_id = 'meu_id_sandbox';
309
        }
310
311
        $customer = $this->moip->customers()->setOwnId($this->last_cus_id)
312
            ->setBirthDate(\DateTime::createFromFormat($this->date_format, $this->date_string))
313
            ->setFullname('Jose Silva')
314
            ->setEmail('[email protected]')
315
            ->setTaxDocument('22222222222', 'CPF')
316
            ->setPhone(11, 66778899, 55)
317
            ->addAddress(Customer::ADDRESS_SHIPPING, 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', '8');
318
319
        return $customer;
320
    }
321
322
    /**
323
     * Creates a holder.
324
     *
325
     * @return Holder
326
     */
327
    public function createHolder()
328
    {
329
        $holder = $this->moip->holders()->setFullname('Jose Silva')
330
            ->setBirthDate(\DateTime::createFromFormat($this->date_format, $this->date_string))
0 ignored issues
show
Security Bug introduced by
It seems like \DateTime::createFromFor...at, $this->date_string) targeting DateTime::createFromFormat() can also be of type false; however, Moip\Resource\Holder::setBirthDate() does only seem to accept object<DateTime>|string, did you maybe forget to handle an error condition?
Loading history...
331
            ->setTaxDocument('22222222222', 'CPF')
332
            ->setPhone(11, 66778899, 55)
333
            ->setAddress(Holder::ADDRESS_BILLING, 'Avenida Faria Lima', '2927', 'Itaim', 'Sao Paulo', 'SP', '01234000', '8');
334
335
        return $holder;
336
    }
337
338
    /**
339
     * Creates a account.
340
     *
341
     * @return Account
342
     */
343
    public function createAccount()
344
    {
345
        $moip = new Moip(new OAuth('1tldio91gi74r34zv30d4saz8yuuws5'), Moip::ENDPOINT_SANDBOX);
346
347
        $uniqEmail = 'fulano'.uniqid('MPA-').'@detal123.com.br';
348
349
        $account = $moip->accounts()
350
            ->setEmail($uniqEmail)
351
            ->setName('Fulano')
352
            ->setLastName('de Tal')
353
            ->setBirthDate('1987-11-27')
354
            ->setTaxDocument('22222222222')
355
            ->setPhone(11, 988888888)
356
            ->addAddress('Av. Ibirapuera', '2035', 'Moema', 'Sao Paulo', 'SP', '04078010')
357
            ->setIdentityDocument('411111115', 'SSP', '2000-05-06')
358
            ->create();
359
360
        return $account;
361
    }
362
363
    /**
364
     * Creates an order.
365
     *
366
     * @return Orders
367
     */
368
    public function createOrder()
369
    {
370 View Code Duplication
        if ($this->sandbox_mock == self::SANDBOX) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
371
            $this->last_ord_id = uniqid('ORD-');
372
        } else {
373
            $this->last_ord_id = 'meu_id_pedido';
374
        }
375
376
        $order = $this->moip->orders()->setCustomer($this->createCustomer())
377
            ->addItem('Nome do produto', 1, 'Mais info...', 100000)
378
            ->addItem('abacaxi', 2, 'Abacaxi de terra de areia', 990)
379
            ->setDiscount(1000)
380
            ->setShippingAmount(1490)
381
            ->setOwnId($this->last_ord_id);
382
383
        return $order;
384
    }
385
386
    /**
387
     * Creates a multiorder.
388
     *
389
     * @return Multiorders
390
     */
391
    public function createMultiorder()
392
    {
393 View Code Duplication
        if ($this->sandbox_mock == self::SANDBOX) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
394
            $this->last_ord_id = uniqid('MOR-');
395
        } else {
396
            $this->last_ord_id = 'meu_id_pedido';
397
        }
398
399
        $order = $this->moip->orders()->setOwnId(uniqid())
400
            ->addItem('bicicleta 1', 1, 'sku1', 10000)
401
            ->addItem('bicicleta 2', 1, 'sku2', 11000)
402
            ->addItem('bicicleta 3', 1, 'sku3', 12000)
403
            ->addItem('bicicleta 4', 1, 'sku4', 13000)
404
            ->setShippingAmount(3000)
405
            ->setAddition(1000)
406
            ->setDiscount(5000)
407
            ->setCustomer($this->createCustomer())
408
            ->addReceiver('MPA-VB5OGTVPCI52', 'PRIMARY', null);
409
410
        $order2 = $this->moip->orders()->setOwnId(uniqid())
411
            ->addItem('bicicleta 1', 1, 'sku1', 10000)
412
            ->addItem('bicicleta 2', 1, 'sku2', 11000)
413
            ->addItem('bicicleta 3', 1, 'sku3', 12000)
414
            ->setShippingAmount(3000)
415
            ->setAddition(1000)
416
            ->setDiscount(5000)
417
            ->setCustomer($this->createCustomer())
418
            ->addReceiver('MPA-IFYRB1HBL73Z', 'PRIMARY', null);
419
420
        $multiorder = $this->moip->multiorders()
421
                ->setOwnId(uniqid())
422
                ->addOrder($order)
423
                ->addOrder($order2);
424
425
        return $multiorder;
426
    }
427
428
    /**
429
     * Tears down the fixture, for example, close a network connection.
430
     * This method is called after a test is executed.
431
     */
432
    public function tearDown()
433
    {
434
        $this->moip = null;
435
    }
436
}
437