This should fix the tests.

This commit is contained in:
James Cole 2016-02-04 11:07:34 +01:00
parent f0bb462f1c
commit 93d9c44585
3 changed files with 55 additions and 47 deletions

View File

@ -14,6 +14,7 @@ use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Rule;
@ -31,6 +32,7 @@ use Log;
*/
class TestData
{
/**
* @param User $user
*/
@ -103,6 +105,31 @@ class TestData
}
/**
* @param User $user
* @param Carbon $current
* @param $name
* @param $amount
*/
public static function createBudgetLimit(User $user, Carbon $current, $name, $amount)
{
$start = clone $current;
$end = clone $current;
$budget = self::findBudget($user, $name);
$start->startOfMonth();
$end->endOfMonth();
BudgetLimit::create(
[
'budget_id' => $budget->id,
'startdate' => $start->format('Y-m-d'),
'amount' => $amount,
'repeats' => 0,
'repeat_freq' => 'monthly',
]
);
}
/**
* @param User $user
*/
@ -110,6 +137,7 @@ class TestData
{
Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
// some empty budgets.
foreach (['A', 'B', 'C', 'D', "E"] as $letter) {
@ -378,5 +406,24 @@ class TestData
return null;
}
/**
* @param User $user
* @param $name
*
* @return Budget|null
*/
public static function findBudget(User $user, $name)
{
/** @var Budget $budget */
foreach (Budget::get() as $budget) {
if ($budget->name == $name && $user->id == $budget->user_id) {
return $budget;
break;
}
}
return null;
}
}

View File

@ -3,8 +3,6 @@
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Attachment;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Category;
use FireflyIII\Models\Role;
use FireflyIII\Models\Transaction;
@ -55,6 +53,11 @@ class TestDataSeeder extends Seeder
// create some budgets for user #1
TestData::createBudgets($user);
// create budget limits for these budgets
TestData::createBudgetLimit($user, new Carbon, 'Groceries', 400);
TestData::createBudgetLimit($user, new Carbon, 'Bills', 1000);
TestData::createBudgetLimit($user, new Carbon, 'Car', 100);
// create some categories for user #1
$this->createCategories($user);

View File

@ -487,9 +487,9 @@ class VisualTestDataSeeder extends Seeder
$this->createCar($current);
// budget limit for this month, on "Groceries".
$this->createBudgetLimit($current, 'Groceries', 400);
$this->createBudgetLimit($current, 'Bills', 1000);
$this->createBudgetLimit($current, 'Car', 100);
TestData::createBudgetLimit($current, 'Groceries', 400);
TestData::createBudgetLimit($current, 'Bills', 1000);
TestData::createBudgetLimit($current, 'Car', 100);
echo 'Created test data for ' . $month . "\n";
$current->addMonth();
@ -497,30 +497,6 @@ class VisualTestDataSeeder extends Seeder
}
/**
* @param Carbon $current
* @param $name
* @param $amount
*/
protected function createBudgetLimit(Carbon $current, $name, $amount)
{
$start = clone $current;
$end = clone $current;
$budget = $this->findBudget($name);
$start->startOfMonth();
$end->endOfMonth();
BudgetLimit::create(
[
'budget_id' => $budget->id,
'startdate' => $start->format('Y-m-d'),
'amount' => $amount,
'repeats' => 0,
'repeat_freq' => 'monthly',
]
);
}
/**
* @param $date
*
@ -1085,24 +1061,6 @@ class VisualTestDataSeeder extends Seeder
return null;
}
/**
* @param $name
*
* @return Budget|null
*/
protected function findBudget($name)
{
/** @var Budget $budget */
foreach (Budget::get() as $budget) {
if ($budget->name == $name && $this->user->id == $budget->user_id) {
return $budget;
break;
}
}
return null;
}
/**
* @param $name
*