Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92740602
ResourceTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 23, 08:00
Size
17 KB
Mime Type
text/x-php
Expires
Mon, Nov 25, 08:00 (1 d, 19 h)
Engine
blob
Format
Raw Data
Handle
22492268
Attached To
rPH Phabricator
ResourceTest.php
View Options
<?php
namespace
Balanced\Test
;
\Balanced\Bootstrap
::
init
();
\RESTful\Bootstrap
::
init
();
\Httpful\Bootstrap
::
init
();
use
Balanced\Resource
;
use
Balanced\Settings
;
use
Balanced\APIKey
;
use
Balanced\Marketplace
;
use
Balanced\Credit
;
use
Balanced\Debit
;
use
Balanced\Refund
;
use
Balanced\Account
;
use
Balanced\Merchant
;
use
Balanced\BankAccount
;
use
Balanced\Card
;
use
Balanced\Hold
;
use
\RESTful\Collection
;
class
APIKeyTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$this
->
expectOutputString
(
''
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/api_keys'
);
return
;
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\A
PIKey'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/api_keys/1234'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\A
PIKey'
,
'ids'
=>
array
(
'id'
=>
'1234'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
}
class
MarketplaceTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/marketplaces'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\M
arketplace'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/marketplaces/1122'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\M
arketplace'
,
'ids'
=>
array
(
'id'
=>
'1122'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testCreateCard
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\C
ard'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'street_address'
=>
'123 Fake Street'
,
'city'
=>
'Jollywood'
,
'region'
=>
''
,
'postal_code'
=>
'90210'
,
'name'
=>
'khalkhalash'
,
'card_number'
=>
'4112344112344113'
,
'security_code'
=>
'123'
,
'expiration_month'
=>
12
,
'expiration_year'
=>
2013
,
));
$marketplace
=
new
Marketplace
(
array
(
'cards'
=>
$collection
));
$marketplace
->
createCard
(
'123 Fake Street'
,
'Jollywood'
,
''
,
'90210'
,
'khalkhalash'
,
'4112344112344113'
,
'123'
,
12
,
2013
);
}
function
testCreateBankAccount
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\B
ankAccount'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'name'
=>
'Homer Jay'
,
'account_number'
=>
'112233a'
,
'routing_number'
=>
'121042882'
,
'type'
=>
'savings'
,
'meta'
=>
null
));
$marketplace
=
new
Marketplace
(
array
(
'bank_accounts'
=>
$collection
));
$marketplace
->
createBankAccount
(
'Homer Jay'
,
'112233a'
,
'121042882'
,
'savings'
);
}
function
testCreateAccount
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\A
ccount'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'email_address'
=>
'role-less@example.com'
,
'meta'
=>
array
(
'test#'
=>
'test_d'
)
));
$marketplace
=
new
Marketplace
(
array
(
'accounts'
=>
$collection
));
$marketplace
->
createAccount
(
'role-less@example.com'
,
array
(
'test#'
=>
'test_d'
)
);
}
function
testCreateBuyer
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\A
ccount'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'email_address'
=>
'buyer@example.com'
,
'card_uri'
=>
'/some/card/uri'
,
'meta'
=>
array
(
'test#'
=>
'test_d'
),
'name'
=>
'Buy Er'
));
$marketplace
=
new
Marketplace
(
array
(
'accounts'
=>
$collection
));
$marketplace
->
createBuyer
(
'buyer@example.com'
,
'/some/card/uri'
,
array
(
'test#'
=>
'test_d'
),
'Buy Er'
);
}
}
class
AccountTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/accounts'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\A
ccount'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/accounts/0099'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\A
ccount'
,
'ids'
=>
array
(
'id'
=>
'0099'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testCredit
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\C
redit'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
101
,
'description'
=>
'something sweet'
,
'meta'
=>
null
,
'destination_uri'
=>
null
,
'appears_on_statement_as'
=>
null
));
$account
=
new
Account
(
array
(
'credits'
=>
$collection
));
$account
->
credit
(
101
,
'something sweet'
);
}
function
testDebit
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\D
ebit'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
9911
,
'description'
=>
'something tangy'
,
'appears_on_statement_as'
=>
'BAL*TANG'
,
'meta'
=>
null
,
'source_uri'
=>
null
,
'on_behalf_of_uri'
=>
null
,
));
$account
=
new
Account
(
array
(
'debits'
=>
$collection
));
$account
->
debit
(
9911
,
'BAL*TANG'
,
'something tangy'
);
}
function
testHold
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\H
old'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
1243
,
'description'
=>
'something crispy'
,
'source_uri'
=>
'/some/card/uri'
,
'meta'
=>
array
(
'test#'
=>
'test_d'
)
));
$account
=
new
Account
(
array
(
'holds'
=>
$collection
));
$account
->
hold
(
1243
,
'something crispy'
,
'/some/card/uri'
,
array
(
'test#'
=>
'test_d'
)
);
}
function
testAddCard
()
{
$account
=
$this
->
getMock
(
'
\B
alanced
\A
ccount'
,
array
(
'save'
)
);
$account
->
expects
(
$this
->
once
())
->
method
(
'save'
)
->
with
();
$account
->
addCard
(
'/my/new/card/121212'
);
$this
->
assertEquals
(
$account
->
card_uri
,
'/my/new/card/121212'
);
}
function
testAddBankAccount
()
{
$account
=
$this
->
getMock
(
'
\B
alanced
\A
ccount'
,
array
(
'save'
)
);
$account
->
expects
(
$this
->
once
())
->
method
(
'save'
)
->
with
();
$account
->
addBankAccount
(
'/my/new/bank_account/121212'
);
$this
->
assertEquals
(
$account
->
bank_account_uri
,
'/my/new/bank_account/121212'
);
}
function
testPromotToMerchant
()
{
$account
=
$this
->
getMock
(
'
\B
alanced
\A
ccount'
,
array
(
'save'
)
);
$account
->
expects
(
$this
->
once
())
->
method
(
'save'
)
->
with
();
$merchant
=
array
(
'type'
=>
'person'
,
'name'
=>
'William James'
,
'tax_id'
=>
'393-48-3992'
,
'street_address'
=>
'167 West 74th Street'
,
'postal_code'
=>
'10023'
,
'dob'
=>
'1842-01-01'
,
'phone_number'
=>
'+16505551234'
,
'country_code'
=>
'USA'
);
$account
->
promoteToMerchant
(
$merchant
);
$this
->
assertEquals
(
$account
->
merchant
,
$merchant
);
}
}
class
HoldTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/holds'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\H
old'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/holds/112233'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\H
old'
,
'ids'
=>
array
(
'id'
=>
'112233'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testVoid
()
{
$hold
=
$this
->
getMock
(
'
\B
alanced
\H
old'
,
array
(
'save'
)
);
$hold
->
expects
(
$this
->
once
())
->
method
(
'save'
)
->
with
();
$hold
->
void
();
$this
->
assertTrue
(
$hold
->
is_void
);
}
function
testCapture
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\D
ebit'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'hold_uri'
=>
'some/hold/uri'
,
'amount'
=>
2211
,
));
$account
=
new
Account
(
array
(
'debits'
=>
$collection
));
$hold
=
new
Hold
(
array
(
'uri'
=>
'some/hold/uri'
,
'account'
=>
$account
));
$hold
->
capture
(
2211
);
}
}
class
CreditTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/credits'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\C
redit'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/credits/9988'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\C
redit'
,
'ids'
=>
array
(
'id'
=>
'9988'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
}
class
DebitTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/debits'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\D
ebit'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/debits/4545'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\D
ebit'
,
'ids'
=>
array
(
'id'
=>
'4545'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testRefund
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\R
efund'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
5645
,
'description'
=>
null
,
'meta'
=>
array
(
'test#'
=>
'test_d'
)
));
$debit
=
new
Debit
(
array
(
'refunds'
=>
$collection
));
$debit
->
refund
(
5645
,
null
,
array
(
'test#'
=>
'test_d'
));
}
}
class
RefundTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/refunds'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\R
efund'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/refunds/1287'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\R
efund'
,
'ids'
=>
array
(
'id'
=>
'1287'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
}
class
BankAccountTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/bank_accounts'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\B
ankAccount'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/bank_accounts/887766'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\B
ankAccount'
,
'ids'
=>
array
(
'id'
=>
'887766'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testCreditAccount
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\C
redit'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
101
,
'description'
=>
'something super sweet'
,
'meta'
=>
null
,
'destination_uri'
=>
'/some/other/uri'
,
'appears_on_statement_as'
=>
null
));
$account
=
new
Account
(
array
(
'credits'
=>
$collection
));
$bank_account
=
new
BankAccount
(
array
(
'uri'
=>
'/some/other/uri'
,
'account'
=>
$account
));
$bank_account
->
credit
(
101
,
'something super sweet'
);
}
function
testCreditAccountless
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\C
redit'
,
'some/uri'
,
null
)
);
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
101
,
'description'
=>
'something super sweet'
,
));
$bank_account
=
new
BankAccount
(
array
(
'uri'
=>
'/some/other/uri'
,
'account'
=>
null
,
'credits'
=>
$collection
,
));
$bank_account
->
credit
(
101
,
'something super sweet'
);
}
}
class
CardTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/cards'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\C
ard'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/cards/136asd6713'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\C
ard'
,
'ids'
=>
array
(
'id'
=>
'136asd6713'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
function
testDebit
()
{
$collection
=
$this
->
getMock
(
'
\R
ESTful
\C
ollection'
,
array
(
'create'
),
array
(
'
\B
alanced
\D
ebit'
,
'some/uri'
,
null
)
);
$account
=
new
Account
(
array
(
'debits'
=>
$collection
));
$card
=
new
Card
(
array
(
'uri'
=>
'/some/uri'
,
'account'
=>
$account
));
$collection
->
expects
(
$this
->
once
())
->
method
(
'create'
)
->
with
(
array
(
'amount'
=>
9911
,
'description'
=>
'something tangy'
,
'appears_on_statement_as'
=>
'BAL*TANG'
,
'meta'
=>
null
,
'source_uri'
=>
'/some/uri'
,
'on_behalf_of_uri'
=>
null
,
));
$card
->
debit
(
9911
,
'BAL*TANG'
,
'something tangy'
);
}
/**
* @expectedException \UnexpectedValueException
*/
function
testNotAssociatedDebit
()
{
$card
=
new
Card
(
array
(
'uri'
=>
'/some/uri'
,
'account'
=>
null
));
$card
->
debit
(
9911
,
'BAL*TANG'
,
'something tangy'
);
}
}
class
MerchantTest
extends
\PHPUnit_Framework_TestCase
{
function
testRegistry
()
{
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/merchants'
);
$expected
=
array
(
'collection'
=>
true
,
'class'
=>
'Balanced
\M
erchant'
,
);
$this
->
assertEquals
(
$expected
,
$result
);
$result
=
Resource
::
getRegistry
()->
match
(
'/v1/merchants/136asd6713'
);
$expected
=
array
(
'collection'
=>
false
,
'class'
=>
'Balanced
\M
erchant'
,
'ids'
=>
array
(
'id'
=>
'136asd6713'
),
);
$this
->
assertEquals
(
$expected
,
$result
);
}
}
Event Timeline
Log In to Comment