Expanded some tests.

This commit is contained in:
James Cole 2015-05-22 20:25:12 +02:00
parent c10efbb170
commit 54c6ca9f45
7 changed files with 62 additions and 10 deletions

View File

@ -74,7 +74,9 @@ class ReportQuery implements ReportQueryInterface
if ($journal->amount != 0) { if ($journal->amount != 0) {
return $journal; return $journal;
} }
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd
); );
return $data; return $data;
@ -191,7 +193,9 @@ class ReportQuery implements ReportQueryInterface
if ($journal->amount != 0) { if ($journal->amount != 0) {
return $journal; return $journal;
} }
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd
); );
return $data; return $data;
@ -237,14 +241,11 @@ class ReportQuery implements ReportQueryInterface
Auth::user()->transactionjournals() Auth::user()->transactionjournals()
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id') ->leftJoin('budget_transaction_journal', 'budget_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
->where('transactions.amount', '<', 0)
->transactionTypes(['Withdrawal']) ->transactionTypes(['Withdrawal'])
->where('transactions.account_id', $account->id) ->where('transactions.account_id', $account->id)
->before($end) ->before($end)
->after($start) ->after($start)
->whereNull('budget_transaction_journal.budget_id') ->whereNull('budget_transaction_journal.budget_id')->get(['transaction_journals.*'])->sum('amount'));
->sum('transactions.amount')
);
} }
/** /**

View File

@ -148,8 +148,8 @@ class Cleanup
} }
unset($set, $entry, $metadata); unset($set, $entry, $metadata);
//encrypt budget limit amount //encrypt budget limit amount
//encrypt limit repetition amount //encrypt limit repetition amount
//encrypt piggy bank event amount //encrypt piggy bank event amount
//encrypt piggy bank repetition currentamount //encrypt piggy bank repetition currentamount

View File

@ -192,7 +192,7 @@ FactoryMuffin::define(
return RandomString::generateRandomString(3); return RandomString::generateRandomString(3);
}, },
'symbol' => function () { 'symbol' => function () {
return RandomString::generateRandomString(1); return RandomString::generateRandomString(2);
}, },
'name' => 'word' 'name' => 'word'
] ]

View File

@ -70,6 +70,7 @@ class ReportHelperTest extends TestCase
* @covers FireflyIII\Helpers\Report\ReportHelper::getBalanceReport * @covers FireflyIII\Helpers\Report\ReportHelper::getBalanceReport
* @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts * @covers FireflyIII\Helpers\Report\ReportQuery::getAllAccounts
* @covers FireflyIII\Helpers\Report\ReportQuery::spentInBudgetCorrected * @covers FireflyIII\Helpers\Report\ReportQuery::spentInBudgetCorrected
* @covers FireflyIII\Helpers\Report\ReportQuery::spentNoBudget
*/ */
public function testGetBalanceReport() public function testGetBalanceReport()
{ {

View File

@ -36,6 +36,22 @@ class BillRepositoryTest extends TestCase
parent::tearDown(); parent::tearDown();
} }
public function testBillPaymentsInRange()
{
$bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
// payment:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->date = $start;
$journal->bill_id = $bill->id;
$journal->save();
$this->object->billPaymentsInRange($bill, $start, $end);
}
/** /**
* @covers FireflyIII\Repositories\Bill\BillRepository::createFakeBill * @covers FireflyIII\Repositories\Bill\BillRepository::createFakeBill
*/ */
@ -58,8 +74,8 @@ class BillRepositoryTest extends TestCase
*/ */
public function testDestroy() public function testDestroy()
{ {
$bill = FactoryMuffin::create('FireflyIII\Models\Bill'); $bill = FactoryMuffin::create('FireflyIII\Models\Bill');
$accountId = $bill->id; $accountId = $bill->id;
$this->object->destroy($bill); $this->object->destroy($bill);
// cannot find bill: // cannot find bill:
@ -284,6 +300,7 @@ class BillRepositoryTest extends TestCase
/** /**
* One * One
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*
* @covers FireflyIII\Repositories\Bill\BillRepository::scan * @covers FireflyIII\Repositories\Bill\BillRepository::scan
*/ */
public function testScanMatch() public function testScanMatch()

View File

@ -295,7 +295,18 @@ class BudgetRepositoryTest extends TestCase
{ {
$budget = FactoryMuffin::create('FireflyIII\Models\Budget'); $budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon); $amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, false);
$this->assertEquals(0, $amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInPeriodCorrected
*/
public function testSpentInPeriodCorrectedShared()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->spentInPeriodCorrected($budget, new Carbon, new Carbon, true);
$this->assertEquals(0, $amount); $this->assertEquals(0, $amount);
} }

View File

@ -99,6 +99,15 @@ class CategoryRepositoryTest extends TestCase
$category->save(); $category->save();
} }
// another journal, same category:
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$journal->transaction_type_id = $type->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
$this->be($user); $this->be($user);
$set = $this->object->getCategoriesAndExpensesCorrected(new Carbon('2015-02-01'), new Carbon('2015-02-28')); $set = $this->object->getCategoriesAndExpensesCorrected(new Carbon('2015-02-01'), new Carbon('2015-02-28'));
$this->assertCount(5, $set); $this->assertCount(5, $set);
@ -196,7 +205,20 @@ class CategoryRepositoryTest extends TestCase
public function testSpentInPeriodSumCorrected() public function testSpentInPeriodSumCorrected()
{ {
$category = FactoryMuffin::create('FireflyIII\Models\Category'); $category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon); $sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, false);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodCorrected
*/
public function testSpentInPeriodSumCorrectedShared()
{
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentInPeriodCorrected($category, new Carbon, new Carbon, true);
$this->assertEquals(0, $sum); $this->assertEquals(0, $sum);