First tests for account repository.

This commit is contained in:
James Cole
2015-05-05 20:46:13 +02:00
parent 69ad757e8b
commit f54f1611b5
4 changed files with 410 additions and 3 deletions

View File

@@ -8,8 +8,8 @@ DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
CACHE_DRIVER=file
SESSION_DRIVER=file
CACHE_DRIVER=array
SESSION_DRIVER=array
EMAIL_SMTP=
EMAIL_USERNAME=

View File

@@ -23,6 +23,7 @@ use Log;
use Session;
use Steam;
/**
* Class AccountRepository
*

2
pu.sh
View File

@@ -11,7 +11,7 @@ fi
if [ ! -z "$1" ]
then
phpunit --verbose tests/controllers/$1.php
phpunit --verbose tests/repositories/$1.php
fi
# restore .env file

View File

@@ -0,0 +1,406 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Account\AccountRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 16:33:55.
*/
class AccountRepositoryTest extends TestCase
{
/**
* @var AccountRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new AccountRepository;
parent::setUp();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
parent::tearDown();
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::countAccounts
* @todo Implement testCountAccounts().
*/
public function testCountAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$type = $account->accountType->type;
$this->be($account->user);
$this->assertEquals(1, $this->object->countAccounts([$type]));
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::destroy
*/
public function testDestroy()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$id = $account->id;
$this->be($account->user);
$this->object->destroy($account);
// cannot find account:
$this->assertCount(0, Account::whereId($id)->whereNotNull('deleted_at')->get());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getAccounts
*/
public function testGetAccounts()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$type = $account->accountType->type;
$this->be($account->user);
$this->assertCount(1, $this->object->getAccounts([$type]));
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getCreditCards
* @todo Implement testGetCreditCards().
*/
public function testGetCreditCards()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// create account meta object:
$meta = new AccountMeta;
$meta->name = 'accountRole';
$meta->data = 'ccAsset';
$meta->account_id = $account->id;
$meta->save();
// meta account type
$meta = new AccountMeta;
$meta->name = 'ccType';
$meta->data = 'monthlyFull';
$meta->account_id = $account->id;
$meta->save();
// login
$this->be($account->user);
// test!
$this->assertCount(1, $this->object->getCreditCards());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFirstTransaction
* @todo Implement testGetFirstTransaction().
*/
public function testGetFirstTransaction()
{
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// two matching transactions:
$first = Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal->id,
'amount' => 100,
]
);
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal->id,
'amount' => -100,
]
);
// login
$this->be($account->user);
$oldest = $this->object->getFirstTransaction($journal, $account);
$this->assertEquals($oldest->amount, $first->amount);
$this->assertEquals($oldest->id, $first->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts
*/
public function testGetFrontpageAccounts()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
// making two account types is kind of cheating but it works.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
/** @var Preference $preference */
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = [];
$preference->save();
$this->be($account->user);
$set = $this->object->getFrontpageAccounts($preference);
$this->assertEquals($account->id, $set->first()->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageAccounts
* @todo Implement testGetFrontpageAccounts().
*/
public function testGetFrontpageAccountsWithPreference()
{
FactoryMuffin::create('FireflyIII\Models\AccountType');
FactoryMuffin::create('FireflyIII\Models\AccountType');
// making two account types is kind of cheating but it works.
$account = FactoryMuffin::create('FireflyIII\Models\Account');
/** @var Preference $preference */
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = [$account->id];
$preference->save();
$this->be($account->user);
$set = $this->object->getFrontpageAccounts($preference);
$this->assertEquals($account->id, $set->first()->id);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getFrontpageTransactions
*/
public function testGetFrontpageTransactions()
{
// three journals
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// three dates (one is out of bounds)
$journal1->date = new Carbon('2012-01-02');
$journal1->user_id = $account->user_id;
$journal2->date = new Carbon('2012-01-09');
$journal2->user_id = $account->user_id;
$journal3->date = new Carbon('2012-02-02');
$journal3->user_id = $account->user_id;
// save all
$journal1->save();
$journal2->save();
$journal3->save();
// transactions to match the dates (one per journal will do)
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal1->id,
'amount' => 100
]
);
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal2->id,
'amount' => 100
]
);
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal3->id,
'amount' => 100
]
);
// be user
$this->be($journal1->user);
// get set:
$set = $this->object->getFrontpageTransactions($account, new Carbon('2012-01-01'), new Carbon('2012-01-31'));
// should have two left.
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getJournals
*/
public function testGetJournals()
{
$date = new Carbon;
// three journals
/** @var Account $account */
$account = FactoryMuffin::create('FireflyIII\Models\Account');
$journal1 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal2 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal3 = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
// three dates (one is out of bounds)
$journal1->date = $date;
$journal1->user_id = $account->user_id;
$journal2->date = $date;
$journal2->user_id = $account->user_id;
$journal3->date = $date;
$journal3->user_id = $account->user_id;
// save all
$journal1->save();
$journal2->save();
$journal3->save();
// transactions to match the dates (one per journal will do)
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal1->id,
'amount' => 100
]
);
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal2->id,
'amount' => 100
]
);
Transaction::create(
[
'account_id' => $account->id,
'transaction_journal_id' => $journal3->id,
'amount' => 100
]
);
// be user
$this->be($journal1->user);
// get paginator:
/** @var LengthAwarePaginator $paginator */
$paginator = $this->object->getJournals($account, 1);
// should have three entries:
$this->assertEquals(3, $paginator->count());
$this->assertEquals(1, $paginator->currentPage());
$this->assertFalse($paginator->isEmpty());
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getLastActivity
* @todo Implement testGetLastActivity().
*/
public function testGetLastActivity()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getPiggyBankAccounts
* @todo Implement testGetPiggyBankAccounts().
*/
public function testGetPiggyBankAccounts()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getSavingsAccounts
* @todo Implement testGetSavingsAccounts().
*/
public function testGetSavingsAccounts()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::getTransfersInRange
* @todo Implement testGetTransfersInRange().
*/
public function testGetTransfersInRange()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::leftOnAccount
* @todo Implement testLeftOnAccount().
*/
public function testLeftOnAccount()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::openingBalanceTransaction
* @todo Implement testOpeningBalanceTransaction().
*/
public function testOpeningBalanceTransaction()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::store
* @todo Implement testStore().
*/
public function testStore()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::sumOfEverything
* @todo Implement testSumOfEverything().
*/
public function testSumOfEverything()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
/**
* @covers FireflyIII\Repositories\Account\AccountRepository::update
* @todo Implement testUpdate().
*/
public function testUpdate()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete('This test has not been implemented yet.');
}
}