Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 7ab6900

Browse files
author
Kleyton Basilio Pilon
committed
test(Transfers): Added tests to transfers
1 parent 8c03c93 commit 7ab6900

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

tests/Resource/TransfersListTest.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Moip\Tests\Resource;
4+
5+
use Moip\Helper\Pagination;
6+
use Moip\Tests\TestCase;
7+
8+
class TransfersListTest extends TestCase
9+
{
10+
public function testShouldGetTransfersList()
11+
{
12+
$this->mockHttpSession($this->body_transfers_list);
13+
14+
$transfers = $this->moip->transfers()->getList(new Pagination(10, 0));
15+
16+
$this->assertNotNull($transfers->getTransfers());
17+
}
18+
}

tests/Resource/TransfersTest.php

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
namespace Moip\Tests\Resource;
4+
5+
use Moip\Tests\TestCase;
6+
7+
class TransfersTest extends TestCase
8+
{
9+
private function createTransfer()
10+
{
11+
$this->mockHttpSession($this->body_transfers_create);
12+
13+
$amount = 500;
14+
$bank_number = '001';
15+
$agency_number = '1111';
16+
$agency_check_number = '2';
17+
$account_number = '9999';
18+
$account_check_number = '8';
19+
$holder_name = 'Integração Taxa por canal';
20+
$tax_document = '033.575.852-51';
21+
$transfer = $this->moip->transfers()
22+
->setTransfers($amount, $bank_number, $agency_number, $agency_check_number, $account_number, $account_check_number)
23+
->setHolder($holder_name, $tax_document)
24+
->execute();
25+
26+
return $transfer;
27+
}
28+
29+
public function testShouldCreateTransfer()
30+
{
31+
$transfer = $this->createTransfer();
32+
$this->assertNotEmpty($transfer->getId());
33+
}
34+
35+
public function testShouldGetTransfer()
36+
{
37+
$this->mockHttpSession($this->body_transfers_create);
38+
39+
$transfer_id = 'TRA-28HRLYNLMUFH';
40+
41+
$transfer = $this->moip->transfers()->get($transfer_id);
42+
$this->assertEquals($transfer_id, $transfer->getId());
43+
44+
$transfer_data = $transfer->getTransfers();
45+
$this->assertEquals(500, $transfer_data->amount);
46+
47+
$transfer_instrument = $transfer_data->transferInstrument;
48+
$this->assertEquals('BANK_ACCOUNT', $transfer_instrument->method);
49+
50+
$bank_account = $transfer_instrument->bankAccount;
51+
$this->assertEquals('001', $bank_account->bankNumber);
52+
$this->assertEquals('1111', $bank_account->agencyNumber);
53+
$this->assertEquals('2', $bank_account->agencyCheckNumber);
54+
$this->assertEquals('9999', $bank_account->accountNumber);
55+
$this->assertEquals('8', $bank_account->accountCheckNumber);
56+
57+
$holder = $transfer->getHolder();
58+
$this->assertEquals('Integração Taxa por canal', $holder->fullname);
59+
60+
$tax_document = $holder->taxDocument;
61+
$this->assertEquals('033.575.852-51', $tax_document->number);
62+
}
63+
64+
public function testShouldRevertTransfer()
65+
{
66+
$this->mockHttpSession($this->body_transfers_revert);
67+
68+
$transfer_id = 'TRA-28HRLYNLMUFH';
69+
70+
$transfer = $this->moip->transfers()->revert($transfer_id);
71+
$this->assertNotEmpty($transfer->getId());
72+
}
73+
}

tests/TestCase.php

+21
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
105105
*/
106106
protected $body_notification_list;
107107

108+
/**
109+
* @var string response from moip API.
110+
*/
111+
protected $body_transfers_create;
112+
113+
/**
114+
* @var string response from moip API.
115+
*/
116+
protected $body_transfers_list;
117+
118+
/**
119+
* @var string response from moip API.
120+
*/
121+
protected $body_transfers_revert;
122+
108123
/**
109124
* @var string holds the last generated customer ownId. In mock mode it'll be always the default, but it changes on sandbox mode.
110125
*/
@@ -175,6 +190,12 @@ public function __construct()
175190
$this->body_get_pay = $this->readJsonFile('jsons/payment/get');
176191

177192
$this->body_get_multipay = $this->readJsonFile('jsons/multipayment/get');
193+
194+
$this->body_transfers_create = $this->readJsonFile('jsons/transfers/create');
195+
196+
$this->body_transfers_list = $this->readJsonFile('jsons/transfers/list');
197+
198+
$this->body_transfers_revert = $this->readJsonFile('jsons/transfers/revert');
178199
}
179200

180201
/**

tests/jsons/transfers/create.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"updatedAt":"2015-10-01T17:24:25.160-03","fee":0,"amount":500,"id":"TRA-28HRLYNLMUFH","transferInstrument":{"method":"BANK_ACCOUNT","bankAccount":{"id":"BKA-I268MOXX85BF","agencyNumber":"1111","holder":{"taxDocument":{"number":"033.575.852-51","type":"CPF"},"fullname":"Integração Taxa por canal"},"accountNumber":"9999","accountCheckNumber":"8","bankName":"BANCO DO BRASIL S.A.","type":"CHECKING","agencyCheckNumber":"2","bankNumber":"001"}},"status":"REQUESTED","createdAt":"2015-10-01T17:24:25.160-03","events":[{"createdAt":"2015-10-01T17:24:25.000-03","description":"Requested","type":"TRANSFER.REQUESTED"}],"entries":[{"external_id":"ENT-X3CG3TR5DRW4","scheduledFor":"2015-10-01T17:24:25.000-03","status":"SETTLED","moipAccount":{"account":"MPA-UVJPXXO25KYX"},"fees":[{"amount":0,"type":"FIXED_FEE"}],"type":"TRANSFER_TO_BANK_ACCOUNT","grossAmount":-500,"moipAccountId":9125,"updatedAt":"2015-10-01T17:24:25.835-03","id":197194,"installment":{"amount":1,"number":1},"references":[{"value":"APP-GLQRIP429OK7","type":"CHANNEL"}],"eventId":"TRA-28HRLYNLMUFH","createdAt":"2015-10-01T17:24:25.775-03","description":"Transferencia para conta bancaria - Transferencia TRA-28HRLYNLMUFH","settledAt":"2015-10-01T17:24:25.835-03","liquidAmount":-500}],"_links":{"self":{"href":"https://sandbox.moip.com.br/v2/transfers/TRA-28HRLYNLMUFH"}}}

tests/jsons/transfers/list.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"summary":{"amount":2,"count":2},"transfers":[{"fee":0,"amount":500,"updatedAt":"2015-10-22T17:33:49.000-02","id":"TRA-08T6Z0ELJIPB","transferInstrument":{"method":"BANK_ACCOUNT","bankAccount":{"id":"BKA-RYW7ICQBW126","agencyNumber":"1111","holder":{"taxDocument":{"number":"255.328.259-12","type":"CPF"},"fullname":"Jose Silva dos Santos"},"accountNumber":"9999","accountCheckNumber":"8","bankName":"BANCO DO BRASIL S.A.","type":"CHECKING","agencyCheckNumber":"2","bankNumber":"001"}},"status":"REQUESTED","createdAt":"2015-10-22T17:33:49.000-02","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/transfers/TRA-08T6Z0ELJIPB"}}},{"fee":0,"amount":1199,"updatedAt":"2015-10-26T12:01:38.000-02","id":"TRA-BVVSKE5K26GG","transferInstrument":{"moipAccount":{"id":"MPA-Y51WUXLPHBJJ","email":"ryu@labs.moip.com.br","login":"ryu@labs.moip.com.br","fullname":"Ryu Silva"},"method":"MOIP_ACCOUNT"},"status":"COMPLETED","createdAt":"2015-10-26T12:01:38.000-02","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/transfers/TRA-BVVSKE5K26GG"}}}],"_links":{"previous":{"href":"https://sandbox.moip.com.br/v2/transfers?offset=0&limit=20"},"next":{"href":"https://sandbox.moip.com.br/v2/transfers?offset=20&limit=20"}}}

tests/jsons/transfers/revert.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"fee":0,"amount":1000,"id":"TRA-B0W5FD5FCADG","transferInstrument":{"moipAccount":{"id":"MPA-AE2OAL41CBB1","email":"iori@labs.moip.com.br","login":"iori@labs.moip.com.br","fullname":"Iori Yagami"},"method":"MOIP_ACCOUNT"},"status":"REVERSED","createdAt":"2015-10-15T16:18:41-0300","_links":{"self":{"href":"https://sandbox.moip.com.br/v2/transfers/TRA-B0W5FD5FCADG"}}}

0 commit comments

Comments
 (0)