Finished budget repository tests.

This commit is contained in:
James Cole 2015-05-09 10:23:13 +02:00
parent 75e279ea0d
commit 317b02d1b9
2 changed files with 119 additions and 54 deletions

View File

@ -1,7 +1,6 @@
<?php <?php
use League\FactoryMuffin\Facade as FactoryMuffin; use League\FactoryMuffin\Facade as FactoryMuffin;
if (!class_exists('RandomString')) { if (!class_exists('RandomString')) {
/** /**
* Class RandomString * Class RandomString
@ -140,7 +139,9 @@ FactoryMuffin::define(
'budget_limit_id' => 'factory|FireflyIII\Models\BudgetLimit', 'budget_limit_id' => 'factory|FireflyIII\Models\BudgetLimit',
'startdate' => 'date', 'startdate' => 'date',
'enddate' => 'date', 'enddate' => 'date',
'amount' => 'integer', 'amount' => function () {
return rand(1, 100);
},
] ]
); );
@ -149,7 +150,9 @@ FactoryMuffin::define(
[ [
'budget_id' => 'factory|FireflyIII\Models\Budget', 'budget_id' => 'factory|FireflyIII\Models\Budget',
'startdate' => 'date', 'startdate' => 'date',
'amount' => 'integer', 'amount' => function () {
return rand(1, 100);
},
'repeats' => 'false', 'repeats' => 'false',
'repeat_freq' => 'monthly', 'repeat_freq' => 'monthly',
@ -220,7 +223,9 @@ FactoryMuffin::define(
[ [
'account_id' => 'factory|FireflyIII\Models\Account', 'account_id' => 'factory|FireflyIII\Models\Account',
'name' => 'sentence', 'name' => 'sentence',
'targetamount' => 'integer', 'targetamount' => function () {
return rand(1, 100);
},
'startdate' => 'date', 'startdate' => 'date',
'targetdate' => 'date', 'targetdate' => 'date',
'reminder_skip' => 0, 'reminder_skip' => 0,

View File

@ -3,6 +3,7 @@ use Carbon\Carbon;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Repositories\Budget\BudgetRepository; use FireflyIII\Repositories\Budget\BudgetRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use League\FactoryMuffin\Facade as FactoryMuffin; use League\FactoryMuffin\Facade as FactoryMuffin;
/** /**
@ -207,121 +208,180 @@ class BudgetRepositoryTest extends TestCase
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getJournals * @covers FireflyIII\Repositories\Budget\BudgetRepository::getJournals
* @todo Implement testGetJournals().
*/ */
public function testGetJournals() public function testGetJournals()
{ {
// Remove the following lines when you implement this test. $repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$this->markTestIncomplete(
'This test has not been implemented yet.' $set = $this->object->getJournals($repetition->budgetlimit->budget, $repetition);
); $this->assertTrue($set instanceof LengthAwarePaginator);
$this->assertCount(0, $set);
$this->assertEquals(1, $set->currentPage());
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate * @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate
* @todo Implement testGetLastBudgetLimitDate().
*/ */
public function testGetLastBudgetLimitDate() public function testGetLastBudgetLimitDate()
{ {
// Remove the following lines when you implement this test. /** @var BudgetLimit $budget */
$this->markTestIncomplete( $limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
'This test has not been implemented yet.' $date = $this->object->getLastBudgetLimitDate($limit->budget);
); $this->assertEquals($date->format('Y-m-d'), $limit->startdate->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate
*/
public function testGetLastBudgetLimitDateNull()
{
/** @var Budget $budget */
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$date = $this->object->getLastBudgetLimitDate($budget);
$ownDate = Carbon::now()->startOfYear();
$this->assertEquals($date->format('Y-m-d'), $ownDate->format('Y-m-d'));
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate * @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate
* @todo Implement testGetLimitAmountOnDate().
*/ */
public function testGetLimitAmountOnDate() public function testGetLimitAmountOnDate()
{ {
// Remove the following lines when you implement this test. $rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
$this->markTestIncomplete(
'This test has not been implemented yet.' $amount = $this->object->getLimitAmountOnDate($rep->budgetlimit->budget, $rep->startdate);
);
$this->assertEquals($rep->amount, $amount);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate
*/
public function testGetLimitAmountOnDateNull()
{
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$amount = $this->object->getLimitAmountOnDate($budget, new Carbon);
$this->assertNull($amount);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudget * @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudget
* @todo Implement testGetWithoutBudget().
*/ */
public function testGetWithoutBudget() public function testGetWithoutBudget()
{ {
// Remove the following lines when you implement this test. $user = FactoryMuffin::create('FireflyIII\User');
$this->markTestIncomplete( $this->be($user);
'This test has not been implemented yet.' $set = $this->object->getWithoutBudget(new Carbon, new Carbon);
); $this->assertCount(0, $set);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudgetSum * @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudgetSum
* @todo Implement testGetWithoutBudgetSum().
*/ */
public function testGetWithoutBudgetSum() public function testGetWithoutBudgetSum()
{ {
// Remove the following lines when you implement this test. $user = FactoryMuffin::create('FireflyIII\User');
$this->markTestIncomplete( $this->be($user);
'This test has not been implemented yet.' $sum = $this->object->getWithoutBudgetSum(new Carbon, new Carbon);
); $this->assertEquals(0, $sum);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInMonth * @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInMonth
* @todo Implement testSpentInMonth().
*/ */
public function testSpentInMonth() public function testSpentInMonth()
{ {
// Remove the following lines when you implement this test. $budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->markTestIncomplete(
'This test has not been implemented yet.' $amount = $this->object->spentInMonth($budget, new Carbon);
); $this->assertEquals(0, $amount);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::store * @covers FireflyIII\Repositories\Budget\BudgetRepository::store
* @todo Implement testStore().
*/ */
public function testStore() public function testStore()
{ {
// Remove the following lines when you implement this test. $user = FactoryMuffin::create('FireflyIII\User');
$this->markTestIncomplete(
'This test has not been implemented yet.' $data = [
); 'name' => 'new budget ' . rand(1, 100),
'user' => $user->id
];
$result = $this->object->store($data);
$this->assertTrue($result instanceof Budget);
$this->assertEquals($result->name, $data['name']);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::sumBudgetExpensesInPeriod * @covers FireflyIII\Repositories\Budget\BudgetRepository::sumBudgetExpensesInPeriod
* @todo Implement testSumBudgetExpensesInPeriod().
*/ */
public function testSumBudgetExpensesInPeriod() public function testSumBudgetExpensesInPeriod()
{ {
// Remove the following lines when you implement this test. $budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->markTestIncomplete( $result = $this->object->sumBudgetExpensesInPeriod($budget, new Carbon, new Carbon);
'This test has not been implemented yet.' $this->assertEquals(0, $result);
);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::update * @covers FireflyIII\Repositories\Budget\BudgetRepository::update
* @todo Implement testUpdate().
*/ */
public function testUpdate() public function testUpdate()
{ {
// Remove the following lines when you implement this test. $budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->markTestIncomplete(
'This test has not been implemented yet.' $data = [
); 'name' => 'update budget ' . rand(1, 100),
'active' => true
];
$result = $this->object->update($budget, $data);
$this->assertTrue($result instanceof Budget);
$this->assertEquals($result->name, $data['name']);
$this->assertEquals($result->id, $budget->id);
} }
/** /**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount * @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
* @todo Implement testUpdateLimitAmount().
*/ */
public function testUpdateLimitAmount() public function testUpdateLimitAmount()
{ {
// Remove the following lines when you implement this test. $budget = FactoryMuffin::create('FireflyIII\Models\Budget');
$this->markTestIncomplete(
'This test has not been implemented yet.' $result = $this->object->updateLimitAmount($budget, new Carbon, 100);
);
$this->assertTrue($result instanceof BudgetLimit);
$this->assertEquals($result->amount, 100);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
*/
public function testUpdateLimitAmountExisting()
{
$budgetLimit= FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$result = $this->object->updateLimitAmount($budgetLimit->budget, $budgetLimit->startdate, 100);
$this->assertTrue($result instanceof BudgetLimit);
$this->assertEquals($result->amount, 100);
}
/**
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
*/
public function testUpdateLimitAmountZero()
{
$budgetLimit= FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
$result = $this->object->updateLimitAmount($budgetLimit->budget, $budgetLimit->startdate, 0);
$this->assertTrue($result instanceof BudgetLimit);
$this->assertEquals($result->amount, 0);
$this->assertNull($result->id);
} }
} }