Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Added unicity to AccountType model. Fixed some tests because of this.
James Cole2e342e47a7a2
diff --git a/app/database/migrations/2014_06_27_163145_create_account_types_table.php b/app/database/migrations/2014_06_27_163145_create_account_types_table.phpindex a20432e87d..b900c47bed 100644--- a/app/database/migrations/2014_06_27_163145_create_account_types_table.php+++ b/app/database/migrations/2014_06_27_163145_create_account_types_table.php@@ -12,30 +12,32 @@ class CreateAccountTypesTable extends Migration{/**- * Run the migrations.+ * Reverse the migrations.** @return void*/- public function up()+ public function down(){- Schema::create(- 'account_types', function (Blueprint $table) {- $table->increments('id');- $table->timestamps();- $table->string('type', 50);- $table->boolean('editable');- }- );+ Schema::drop('account_types');}/**- * Reverse the migrations.+ * Run the migrations.** @return void*/- public function down()+ public function up(){- Schema::drop('account_types');+ Schema::create(+ 'account_types', function (Blueprint $table) {+ $table->increments('id');+ $table->timestamps();+ $table->string('type', 50);+ $table->boolean('editable');++ $table->unique('type');+ }+ );}}diff --git a/app/tests/controllers/AccountTest.php b/app/tests/controllers/AccountTest.phpindex a753c2c3a8..c58213581f 100644--- a/app/tests/controllers/AccountTest.php+++ b/app/tests/controllers/AccountTest.php@@ -68,21 +68,21 @@ class AccountTest extends TestCase// user should equal test user:$this->assertEquals($user->id, $account->user()->first()->id);- // whatever the account type of this account, searching for it using the- // scope method should return one account:- $accountTypeType = $account->accounttype->type;- $this->assertCount(1, \Account::AccountTypeIn([$accountTypeType])->get());-- // lame test$this->assertEquals('testing',\App::environment());- // count the number of accounts the account type has. Should be one:- $accountType = $account->accounttype()->first();- $this->assertCount(1,$accountType->accounts()->get());--+ \Log::debug('Hello from test!');+ \Log::debug('Number of accounts: ' . \Account::count());+ \Log::debug('Number of account types: ' . \AccountType::count());+ foreach(\AccountType::get() as $t) {+ \Log::debug('AccountType: #'.$t->id.', ' . $t->type);+ }+ // whatever the account type of this account, searching for it using the+ // scope method should return one account:+ $accountType = $account->accounttype()->first();+ $accounts = $accountType->accounts()->count();+ $this->assertCount($accounts, \Account::AccountTypeIn([$accountType->type])->get());}@@ -111,9 +111,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -142,9 +140,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -173,9 +169,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -204,12 +198,8 @@ class AccountTest extends TestCasepublic function testIndex(){// two account types:- $personalType = f::create('AccountType');- $personalType->type = 'Default account';- $personalType->save();- $benType = f::create('AccountType');- $benType->type = 'Beneficiary account';- $benType->save();+ $personalType = \AccountType::whereType('Default account')->first();+ $benType = \AccountType::whereType('Beneficiary account')->first();// create two accounts:/** @var \Account $account */@@ -251,9 +241,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -285,9 +273,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -306,9 +292,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -325,9 +309,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -343,9 +325,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();@@ -370,9 +350,7 @@ class AccountTest extends TestCase$account = f::create('Account');/** @var \AccountType $accountType */- $accountType = f::create('AccountType');- $accountType->type = 'Default account';- $accountType->save();+ $accountType = \AccountType::whereType('Default account')->first();$account->accountType()->associate($accountType);$account->save();diff --git a/app/tests/controllers/ChartControllerTest.php b/app/tests/controllers/ChartControllerTest.phpindex 2ea84e322d..3016ef1202 100644--- a/app/tests/controllers/ChartControllerTest.php+++ b/app/tests/controllers/ChartControllerTest.php@@ -77,10 +77,8 @@ class ChartControllerTest extends TestCasepublic function testHomeAccountInfo(){$account = f::create('Account');- $type = f::create('AccountType');- $type->type = 'Default account';- $type->save();- $account->accounttype()->associate($type);+ $accountType = \AccountType::whereType('Default account')->first();+ $account->accounttype()->associate($accountType);$account->save();// for successful binding:Auth::shouldReceive('user')->andReturn($account->user()->first());diff --git a/app/tests/factories/AccountType.php b/app/tests/factories/AccountType.phpindex 0ab4f7e630..d361058bcb 100644--- a/app/tests/factories/AccountType.php+++ b/app/tests/factories/AccountType.php@@ -2,18 +2,9 @@use League\FactoryMuffin\Facade;Facade::define(- 'AccountType',- [- 'type' => function () {- $types = [- 'Default account',- 'Cash account',- 'Initial balance account',- 'Beneficiary account'- ];-- return $types[rand(0, 3)];- },- 'editable' => 1- ]+ 'AccountType',+ [+ 'type' => 'unique:word',+ 'editable' => 1+ ]);\ No newline at end of file