Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117885327
WalletTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
4 KB
Referenced Files
None
Subscribers
None
WalletTest.php
View Options
<?php
namespace
Tests\Feature
;
use
App\User
;
use
App\Wallet
;
use
Tests\TestCase
;
use
Illuminate\Foundation\Testing\WithFaker
;
use
Illuminate\Foundation\Testing\RefreshDatabase
;
class
WalletTest
extends
TestCase
{
private
$users
=
[
'UserWallet1@UserWallet.com'
,
'UserWallet2@UserWallet.com'
,
'UserWallet3@UserWallet.com'
,
'UserWallet4@UserWallet.com'
,
'UserWallet5@UserWallet.com'
,
'WalletControllerA@WalletController.com'
,
'WalletControllerB@WalletController.com'
,
'WalletController2A@WalletController.com'
,
'WalletController2B@WalletController.com'
,
];
public
function
setUp
():
void
{
parent
::
setUp
();
foreach
(
$this
->
users
as
$user
)
{
$this
->
deleteTestUser
(
$user
);
}
}
public
function
tearDown
():
void
{
foreach
(
$this
->
users
as
$user
)
{
$this
->
deleteTestUser
(
$user
);
}
parent
::
tearDown
();
}
/**
* Verify a wallet is created, when a user is created.
*/
public
function
testCreateUserCreatesWallet
():
void
{
$user
=
$this
->
getTestUser
(
'UserWallet1@UserWallet.com'
);
$this
->
assertCount
(
1
,
$user
->
wallets
);
}
/**
* Verify a user can haz more wallets.
*/
public
function
testAddWallet
():
void
{
$user
=
$this
->
getTestUser
(
'UserWallet2@UserWallet.com'
);
$user
->
wallets
()->
save
(
new
Wallet
([
'currency'
=>
'USD'
])
);
$this
->
assertCount
(
2
,
$user
->
wallets
);
$user
->
wallets
()->
each
(
function
(
$wallet
)
{
$this
->
assertEquals
(
0
,
$wallet
->
balance
);
}
);
}
/**
* Verify we can not delete a user wallet that holds balance.
*/
public
function
testDeleteWalletWithCredit
():
void
{
$user
=
$this
->
getTestUser
(
'UserWallet3@UserWallet.com'
);
$user
->
wallets
()->
each
(
function
(
$wallet
)
{
$wallet
->
credit
(
100
)->
save
();
}
);
$user
->
wallets
()->
each
(
function
(
$wallet
)
{
$this
->
assertFalse
(
$wallet
->
delete
());
}
);
}
/**
* Verify we can not delete a wallet that is the last wallet.
*/
public
function
testDeleteLastWallet
():
void
{
$user
=
$this
->
getTestUser
(
'UserWallet4@UserWallet.com'
);
$this
->
assertCount
(
1
,
$user
->
wallets
);
$user
->
wallets
()->
each
(
function
(
$wallet
)
{
$this
->
assertFalse
(
$wallet
->
delete
());
}
);
}
/**
* Verify we can remove a wallet that is an additional wallet.
*/
public
function
testDeleteAddtWallet
():
void
{
$user
=
$this
->
getTestUser
(
'UserWallet5@UserWallet.com'
);
$user
->
wallets
()->
save
(
new
Wallet
([
'currency'
=>
'USD'
])
);
$user
->
wallets
()->
each
(
function
(
$wallet
)
{
if
(
$wallet
->
currency
==
'USD'
)
{
$this
->
assertNotFalse
(
$wallet
->
delete
());
}
}
);
}
/**
* Verify a wallet can be assigned a controller.
*/
public
function
testAddWalletController
():
void
{
$userA
=
$this
->
getTestUser
(
'WalletControllerA@WalletController.com'
);
$userB
=
$this
->
getTestUser
(
'WalletControllerB@WalletController.com'
);
$userA
->
wallets
()->
each
(
function
(
$wallet
)
use
(
$userB
)
{
$wallet
->
addController
(
$userB
);
}
);
$this
->
assertCount
(
1
,
$userB
->
accounts
);
$aWallet
=
$userA
->
wallets
()->
first
();
$bAccount
=
$userB
->
accounts
()->
first
();
$this
->
assertTrue
(
$bAccount
->
id
===
$aWallet
->
id
);
}
/**
* Verify controllers can also be removed from wallets.
*/
public
function
testRemoveWalletController
():
void
{
$userA
=
$this
->
getTestUser
(
'WalletController2A@WalletController.com'
);
$userB
=
$this
->
getTestUser
(
'WalletController2B@WalletController.com'
);
$userA
->
wallets
()->
each
(
function
(
$wallet
)
use
(
$userB
)
{
$wallet
->
addController
(
$userB
);
}
);
$userB
->
refresh
();
$userB
->
accounts
()->
each
(
function
(
$wallet
)
use
(
$userB
)
{
$wallet
->
removeController
(
$userB
);
}
);
$this
->
assertCount
(
0
,
$userB
->
accounts
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Apr 6, 1:58 AM (1 w, 6 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e0/33/8276308023028ac14f736539710e
Default Alt Text
WalletTest.php (4 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline