2014-07-05 12:44:26 -05:00
|
|
|
<?php
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-07-08 07:04:02 -05:00
|
|
|
use Mockery as m;
|
|
|
|
|
2014-07-06 08:18:11 -05:00
|
|
|
class AccountControllerTest extends TestCase
|
|
|
|
{
|
2014-07-05 12:44:26 -05:00
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2014-07-08 07:04:02 -05:00
|
|
|
Artisan::call('migrate');
|
|
|
|
Artisan::call('db:seed');
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|
|
|
|
|
2014-07-08 01:07:15 -05:00
|
|
|
public function testIndex()
|
|
|
|
{
|
2014-07-08 07:04:02 -05:00
|
|
|
// mock account type(s):
|
|
|
|
$personal = $this->mock('AccountType');
|
2014-07-25 06:02:01 -05:00
|
|
|
$personal->shouldReceive('getAttribute', 'description')->andReturn('Default account');
|
2014-07-08 07:04:02 -05:00
|
|
|
|
|
|
|
$bene = $this->mock('AccountType');
|
2014-07-25 06:02:01 -05:00
|
|
|
$bene->shouldReceive('getAttribute', 'description')->andReturn('Beneficiary account');
|
2014-07-08 07:04:02 -05:00
|
|
|
|
|
|
|
$initial = $this->mock('AccountType');
|
2014-07-25 06:02:01 -05:00
|
|
|
$initial->shouldReceive('getAttribute', 'description')->andReturn('Initial balance account');
|
2014-07-08 07:04:02 -05:00
|
|
|
|
|
|
|
$cash = $this->mock('AccountType');
|
2014-07-25 06:02:01 -05:00
|
|
|
$cash->shouldReceive('getAttribute', 'description')->andReturn('Cash account');
|
2014-07-08 07:04:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
// mock account(s)
|
|
|
|
$one = $this->mock('Account');
|
|
|
|
$one->shouldReceive('getAttribute')->andReturn($personal);
|
|
|
|
|
|
|
|
$two = $this->mock('Account');
|
|
|
|
$two->shouldReceive('getAttribute')->andReturn($bene);
|
|
|
|
|
|
|
|
$three = $this->mock('Account');
|
|
|
|
$three->shouldReceive('getAttribute')->andReturn($initial);
|
|
|
|
|
|
|
|
$four = $this->mock('Account');
|
|
|
|
$four->shouldReceive('getAttribute')->andReturn($cash);
|
2014-07-25 06:02:01 -05:00
|
|
|
$c = new \Illuminate\Database\Eloquent\Collection([$one, $two, $three, $four]);
|
2014-07-08 07:04:02 -05:00
|
|
|
|
|
|
|
// mock account repository:
|
|
|
|
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
|
|
|
$accounts->shouldReceive('get')->andReturn($c);
|
|
|
|
|
|
|
|
|
2014-07-06 14:07:52 -05:00
|
|
|
$list = [
|
2014-07-08 07:04:02 -05:00
|
|
|
'personal' => [$one],
|
|
|
|
'beneficiaries' => [$two],
|
|
|
|
'initial' => [$three],
|
|
|
|
'cash' => [$four]
|
2014-07-06 14:07:52 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
// mock:
|
|
|
|
View::shouldReceive('share');
|
|
|
|
View::shouldReceive('make')->with('accounts.index')->once()->andReturn(\Mockery::self())
|
2014-07-25 06:02:01 -05:00
|
|
|
->shouldReceive('with')->once()->with('accounts', $list)->andReturn(\Mockery::self())
|
2014-07-08 07:04:02 -05:00
|
|
|
->shouldReceive('with')->once()->with('total', 4)->andReturn(\Mockery::self());
|
|
|
|
|
2014-07-06 14:07:52 -05:00
|
|
|
|
|
|
|
// call
|
|
|
|
$this->call('GET', '/accounts');
|
|
|
|
|
|
|
|
// test
|
|
|
|
$this->assertResponseOk();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-07-05 12:44:26 -05:00
|
|
|
public function testCreate()
|
|
|
|
{
|
|
|
|
// mock:
|
2014-07-06 08:18:11 -05:00
|
|
|
View::shouldReceive('share');
|
2014-07-05 12:44:26 -05:00
|
|
|
View::shouldReceive('make')->with('accounts.create');
|
|
|
|
|
|
|
|
// call
|
|
|
|
$this->call('GET', '/accounts/create');
|
|
|
|
|
|
|
|
// test
|
|
|
|
$this->assertResponseOk();
|
|
|
|
}
|
2014-07-06 08:18:11 -05:00
|
|
|
|
|
|
|
public function testShow()
|
|
|
|
{
|
2014-07-06 14:07:52 -05:00
|
|
|
// mock account repository:
|
|
|
|
$accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
|
|
|
|
$accounts->shouldReceive('get')->with(1)->andReturn([]);
|
2014-07-06 08:18:11 -05:00
|
|
|
|
2014-07-06 14:07:52 -05:00
|
|
|
// call
|
|
|
|
$this->call('GET', '/accounts/1');
|
|
|
|
|
|
|
|
// test
|
|
|
|
$this->assertResponseOk();
|
2014-07-06 08:18:11 -05:00
|
|
|
}
|
2014-07-08 01:07:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
public function tearDown()
|
|
|
|
{
|
|
|
|
Mockery::close();
|
|
|
|
}
|
2014-07-05 12:44:26 -05:00
|
|
|
}
|