Esempio n. 1
0
 /**
  * @covers FireflyIII\Models\Account::firstOrNullEncrypted
  */
 public function testFirstOrNullEncryptedNew()
 {
     // create account:
     $account = FactoryMuffin::create('FireflyIII\\Models\\Account');
     FactoryMuffin::create('FireflyIII\\User');
     // search for account with the same properties:
     $search = ['name' => 'Some new account', 'account_type_id' => $account->account_type_id, 'user_id' => $account->user_id, 'active' => 1];
     $result = Account::firstOrNullEncrypted($search);
     // should not be the same account:
     $this->assertNull($result);
 }
Esempio n. 2
0
 /**
  * @param array $data
  *
  * @return Account
  */
 protected function storeAccount(array $data)
 {
     $type = Config::get('firefly.accountTypeByIdentifier.' . $data['accountType']);
     $accountType = AccountType::whereType($type)->first();
     $newAccount = new Account(['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'name' => $data['name'], 'virtual_balance' => $data['virtualBalance'], 'active' => $data['active'] === true ? true : false, 'iban' => $data['iban']]);
     if (!$newAccount->isValid()) {
         // does the account already exist?
         $searchData = ['user_id' => $data['user'], 'account_type_id' => $accountType->id, 'virtual_balance' => $data['virtualBalance'], 'name' => $data['name'], 'iban' => $data['iban']];
         $existingAccount = Account::firstOrNullEncrypted($searchData);
         if (!$existingAccount) {
             Log::error('Account create error: ' . $newAccount->getErrors()->toJson());
             abort(500);
             // @codeCoverageIgnoreStart
         }
         // @codeCoverageIgnoreEnd
         $newAccount = $existingAccount;
     }
     $newAccount->save();
     return $newAccount;
 }