mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
This should fix the tests.
This commit is contained in:
parent
f0bb462f1c
commit
93d9c44585
@ -14,6 +14,7 @@ use FireflyIII\Models\Account;
|
|||||||
use FireflyIII\Models\AccountMeta;
|
use FireflyIII\Models\AccountMeta;
|
||||||
use FireflyIII\Models\Bill;
|
use FireflyIII\Models\Bill;
|
||||||
use FireflyIII\Models\Budget;
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\BudgetLimit;
|
||||||
use FireflyIII\Models\PiggyBank;
|
use FireflyIII\Models\PiggyBank;
|
||||||
use FireflyIII\Models\PiggyBankEvent;
|
use FireflyIII\Models\PiggyBankEvent;
|
||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
@ -31,6 +32,7 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class TestData
|
class TestData
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User $user
|
* @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
|
* @param User $user
|
||||||
*/
|
*/
|
||||||
@ -110,6 +137,7 @@ class TestData
|
|||||||
{
|
{
|
||||||
Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
Budget::firstOrCreateEncrypted(['name' => 'Groceries', 'user_id' => $user->id]);
|
||||||
Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
Budget::firstOrCreateEncrypted(['name' => 'Bills', 'user_id' => $user->id]);
|
||||||
|
Budget::firstOrCreateEncrypted(['name' => 'Car', 'user_id' => $user->id]);
|
||||||
|
|
||||||
// some empty budgets.
|
// some empty budgets.
|
||||||
foreach (['A', 'B', 'C', 'D', "E"] as $letter) {
|
foreach (['A', 'B', 'C', 'D', "E"] as $letter) {
|
||||||
@ -378,5 +406,24 @@ class TestData
|
|||||||
return null;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\Attachment;
|
use FireflyIII\Models\Attachment;
|
||||||
use FireflyIII\Models\Budget;
|
|
||||||
use FireflyIII\Models\BudgetLimit;
|
|
||||||
use FireflyIII\Models\Category;
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Models\Role;
|
use FireflyIII\Models\Role;
|
||||||
use FireflyIII\Models\Transaction;
|
use FireflyIII\Models\Transaction;
|
||||||
@ -55,6 +53,11 @@ class TestDataSeeder extends Seeder
|
|||||||
// create some budgets for user #1
|
// create some budgets for user #1
|
||||||
TestData::createBudgets($user);
|
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
|
// create some categories for user #1
|
||||||
$this->createCategories($user);
|
$this->createCategories($user);
|
||||||
|
|
||||||
|
@ -487,9 +487,9 @@ class VisualTestDataSeeder extends Seeder
|
|||||||
$this->createCar($current);
|
$this->createCar($current);
|
||||||
|
|
||||||
// budget limit for this month, on "Groceries".
|
// budget limit for this month, on "Groceries".
|
||||||
$this->createBudgetLimit($current, 'Groceries', 400);
|
TestData::createBudgetLimit($current, 'Groceries', 400);
|
||||||
$this->createBudgetLimit($current, 'Bills', 1000);
|
TestData::createBudgetLimit($current, 'Bills', 1000);
|
||||||
$this->createBudgetLimit($current, 'Car', 100);
|
TestData::createBudgetLimit($current, 'Car', 100);
|
||||||
|
|
||||||
echo 'Created test data for ' . $month . "\n";
|
echo 'Created test data for ' . $month . "\n";
|
||||||
$current->addMonth();
|
$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
|
* @param $date
|
||||||
*
|
*
|
||||||
@ -1085,24 +1061,6 @@ class VisualTestDataSeeder extends Seeder
|
|||||||
return null;
|
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
|
* @param $name
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user