mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Create some new test code.
This commit is contained in:
37
database/factories/AccountFactory.php
Normal file
37
database/factories/AccountFactory.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
|
||||
$factory->define(Account::class, function (Faker $faker) {
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'account_type_id' => 1,
|
||||
'name' => $faker->words(3, true),
|
||||
'virtual_balance' => '0',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
'order' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(Account::class, AccountType::ASSET, function ($faker) {
|
||||
return [
|
||||
'account_type_id' => 3,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(Account::class, AccountType::INITIAL_BALANCE, function ($faker) {
|
||||
return [
|
||||
'account_type_id' => 6,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(Account::class, AccountType::EXPENSE, function ($faker) {
|
||||
return [
|
||||
'account_type_id' => 4,
|
||||
];
|
||||
});
|
66
database/factories/OBFactory.php
Normal file
66
database/factories/OBFactory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use FireflyIII\Model;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
|
||||
$factory->define(TransactionJournal::class, function (Faker $faker) {
|
||||
return [
|
||||
'user_id' => 1,
|
||||
'transaction_type_id' => 1,
|
||||
'description' => $faker->words(3, true),
|
||||
'tag_count' => 0,
|
||||
'date' => $faker->date('Y-m-d'),
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(TransactionJournal::class, TransactionType::OPENING_BALANCE, function ($faker) {
|
||||
return [
|
||||
'transaction_type_id' => 4,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(TransactionJournal::class, 'ob_broken', function ($faker) {
|
||||
return [
|
||||
'transaction_type_id' => 4,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->afterCreatingState(TransactionJournal::class, TransactionType::OPENING_BALANCE, function ($journal, $faker) {
|
||||
$obAccount = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
|
||||
$assetAccount = factory(Account::class)->state(AccountType::ASSET)->create();
|
||||
$sourceTransaction = factory(Transaction::class)->create(
|
||||
[
|
||||
'account_id' => $obAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
]);
|
||||
|
||||
$destTransaction = factory(Transaction::class)->create(
|
||||
[
|
||||
'account_id' => $assetAccount->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
]);
|
||||
});
|
||||
|
||||
$factory->afterCreatingState(TransactionJournal::class, 'ob_broken', function ($journal, $faker) {
|
||||
$ob1 = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
|
||||
$ob2 = factory(Account::class)->state(AccountType::INITIAL_BALANCE)->create();
|
||||
|
||||
$sourceTransaction = factory(Transaction::class)->create(
|
||||
[
|
||||
'account_id' => $ob1->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
]);
|
||||
|
||||
$destTransaction = factory(Transaction::class)->create(
|
||||
[
|
||||
'account_id' => $ob2->id,
|
||||
'transaction_journal_id' => $journal->id,
|
||||
]);
|
||||
});
|
14
database/factories/TransactionFactory.php
Normal file
14
database/factories/TransactionFactory.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Factory $factory */
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
use FireflyIII\Models\Transaction;
|
||||
|
||||
$factory->define(Transaction::class, function (Faker $faker) {
|
||||
return [
|
||||
'transaction_journal_id' => 0,
|
||||
'account_id' => 0,
|
||||
'amount' => 5,
|
||||
];
|
||||
});
|
Reference in New Issue
Block a user