mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 20:34:48 +00:00
327 lines
9.8 KiB
PHP
327 lines
9.8 KiB
PHP
<?php
|
|
use Carbon\Carbon;
|
|
use FireflyIII\Models\Budget;
|
|
use FireflyIII\Models\BudgetLimit;
|
|
use FireflyIII\Repositories\Budget\BudgetRepository;
|
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:16:07.
|
|
*/
|
|
class BudgetRepositoryTest extends TestCase
|
|
{
|
|
/**
|
|
* @var BudgetRepository
|
|
*/
|
|
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 BudgetRepository;
|
|
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\Budget\BudgetRepository::cleanupBudgets
|
|
*/
|
|
public function testCleanupBudgets()
|
|
{
|
|
// create some budgets:
|
|
for ($i = 0; $i < 3; $i++) {
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
|
|
$limit->budget_id = $budget->id;
|
|
$limit->amount = 0;
|
|
$limit->save();
|
|
}
|
|
|
|
|
|
$this->object->cleanupBudgets();
|
|
|
|
$this->assertCount(0, BudgetLimit::get());
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::destroy
|
|
* @todo Implement testDestroy().
|
|
*/
|
|
public function testDestroy()
|
|
{
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
|
|
$this->object->destroy($budget);
|
|
|
|
$this->assertCount(0, Budget::where('id', $budget->id)->whereNull('deleted_at')->get());
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::expensesOnDay
|
|
* @todo Implement testExpensesOnDay().
|
|
*/
|
|
public function testExpensesOnDay()
|
|
{
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
|
|
$result = $this->object->expensesOnDay($budget, new Carbon);
|
|
|
|
$this->assertEquals(0, $result);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getActiveBudgets
|
|
*/
|
|
public function testGetActiveBudgets()
|
|
{
|
|
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget1->active = 1;
|
|
$budget2->active = 0;
|
|
$budget2->user_id = $budget1->user_id;
|
|
$budget1->save();
|
|
$budget2->save();
|
|
$this->be($budget1->user);
|
|
|
|
$set = $this->object->getActiveBudgets();
|
|
|
|
$this->assertCount(1, $set);
|
|
$this->assertEquals($set->first()->id, $budget1->id);
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgetLimitRepetitions
|
|
*/
|
|
public function testGetBudgetLimitRepetitions()
|
|
{
|
|
$rep = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
|
|
$limit = $rep->budgetlimit;
|
|
$limit->startdate = new Carbon('2015-02-02');
|
|
$rep->startdate = new Carbon('2015-02-02');
|
|
$rep->enddate = new Carbon('2015-02-28');
|
|
$limit->save();
|
|
$rep->save();
|
|
|
|
$set = $this->object->getBudgetLimitRepetitions($rep->budgetlimit->budget, new Carbon('2015-02-01'), new Carbon('2015-02-28'));
|
|
$this->assertCount(2, $set);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgetLimits
|
|
*/
|
|
public function testGetBudgetLimits()
|
|
{
|
|
/** @var Budget $budget */
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$set = $this->object->getBudgetLimits($budget);
|
|
|
|
$this->assertCount(0, $set);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getBudgets
|
|
*/
|
|
public function testGetBudgets()
|
|
{
|
|
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget1->active = 1;
|
|
$budget2->active = 0;
|
|
$budget2->user_id = $budget1->user_id;
|
|
$budget1->save();
|
|
$budget2->save();
|
|
$this->be($budget1->user);
|
|
|
|
$set = $this->object->getBudgets();
|
|
|
|
$this->assertCount(2, $set);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getCurrentRepetition
|
|
*/
|
|
public function testGetCurrentRepetition()
|
|
{
|
|
/** @var Budget $budget */
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$rep = $this->object->getCurrentRepetition($budget, new Carbon);
|
|
$this->assertNull($rep);
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getFirstBudgetLimitDate
|
|
*/
|
|
public function testGetFirstBudgetLimitDate()
|
|
{
|
|
/** @var BudgetLimit $budget */
|
|
$limit = FactoryMuffin::create('FireflyIII\Models\BudgetLimit');
|
|
$date = $this->object->getFirstBudgetLimitDate($limit->budget);
|
|
$this->assertEquals($date->format('Y-m-d'), $limit->startdate->format('Y-m-d'));
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getFirstBudgetLimitDate
|
|
*/
|
|
public function testGetFirstBudgetLimitDateNull()
|
|
{
|
|
/** @var BudgetLimit $budget */
|
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$date = $this->object->getFirstBudgetLimitDate($budget);
|
|
$this->assertNull($date);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getInactiveBudgets
|
|
*/
|
|
public function testGetInactiveBudgets()
|
|
{
|
|
$budget1 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget2 = FactoryMuffin::create('FireflyIII\Models\Budget');
|
|
$budget1->active = 1;
|
|
$budget2->active = 0;
|
|
$budget2->user_id = $budget1->user_id;
|
|
$budget1->save();
|
|
$budget2->save();
|
|
$this->be($budget1->user);
|
|
|
|
$set = $this->object->getInactiveBudgets();
|
|
|
|
$this->assertCount(1, $set);
|
|
$this->assertEquals($set->first()->id, $budget2->id);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getJournals
|
|
* @todo Implement testGetJournals().
|
|
*/
|
|
public function testGetJournals()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLastBudgetLimitDate
|
|
* @todo Implement testGetLastBudgetLimitDate().
|
|
*/
|
|
public function testGetLastBudgetLimitDate()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getLimitAmountOnDate
|
|
* @todo Implement testGetLimitAmountOnDate().
|
|
*/
|
|
public function testGetLimitAmountOnDate()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudget
|
|
* @todo Implement testGetWithoutBudget().
|
|
*/
|
|
public function testGetWithoutBudget()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::getWithoutBudgetSum
|
|
* @todo Implement testGetWithoutBudgetSum().
|
|
*/
|
|
public function testGetWithoutBudgetSum()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInMonth
|
|
* @todo Implement testSpentInMonth().
|
|
*/
|
|
public function testSpentInMonth()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::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\Budget\BudgetRepository::sumBudgetExpensesInPeriod
|
|
* @todo Implement testSumBudgetExpensesInPeriod().
|
|
*/
|
|
public function testSumBudgetExpensesInPeriod()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::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.'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Repositories\Budget\BudgetRepository::updateLimitAmount
|
|
* @todo Implement testUpdateLimitAmount().
|
|
*/
|
|
public function testUpdateLimitAmount()
|
|
{
|
|
// Remove the following lines when you implement this test.
|
|
$this->markTestIncomplete(
|
|
'This test has not been implemented yet.'
|
|
);
|
|
}
|
|
}
|