Refactor journal repository and fix tests.

This commit is contained in:
James Cole 2019-08-10 13:42:33 +02:00
parent b7f3c53688
commit 93f1854be0
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
14 changed files with 286 additions and 130 deletions

View File

@ -32,6 +32,7 @@ use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Support\Http\Api\TransactionFilter;
@ -61,6 +62,9 @@ class TransactionController extends Controller
/** @var JournalRepositoryInterface The journal repository */
private $repository;
/** @var JournalAPIRepositoryInterface Journal API repos */
private $journalAPIRepository;
/**
* TransactionController constructor.
*
@ -74,10 +78,12 @@ class TransactionController extends Controller
/** @var User $admin */
$admin = auth()->user();
$this->repository = app(JournalRepositoryInterface::class);
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
$this->repository = app(JournalRepositoryInterface::class);
$this->groupRepository = app(TransactionGroupRepositoryInterface::class);
$this->journalAPIRepository = app(JournalAPIRepositoryInterface::class);
$this->repository->setUser($admin);
$this->groupRepository->setUser($admin);
$this->journalAPIRepository->setUser($admin);
return $next($request);
}
@ -97,7 +103,7 @@ class TransactionController extends Controller
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$attachments = $this->repository->getAttachments($transactionJournal);
$attachments = $this->journalAPIRepository->getAttachments($transactionJournal);
/** @var AttachmentTransformer $transformer */
$transformer = app(AttachmentTransformer::class);
@ -206,7 +212,7 @@ class TransactionController extends Controller
$baseUrl = $request->getSchemeAndHttpHost() . '/api/v1';
$manager->setSerializer(new JsonApiSerializer($baseUrl));
$events = $this->repository->getPiggyBankEvents($transactionJournal);
$events = $this->journalAPIRepository->getPiggyBankEvents($transactionJournal);
/** @var PiggyBankEventTransformer $transformer */
$transformer = app(PiggyBankEventTransformer::class);

View File

@ -90,7 +90,7 @@ class PiggyBankFactory
*/
public function findByName(string $name): ?PiggyBank
{
return $this->user->piggyBanks()->where('name', $name)->first();
return $this->user->piggyBanks()->where('piggy_banks.name', $name)->first();
}
/**

View File

@ -24,6 +24,8 @@ namespace FireflyIII\Providers;
use FireflyIII\Helpers\Collector\GroupCollector;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Repositories\Journal\JournalAPIRepository;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepository;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepository;
@ -109,5 +111,19 @@ class JournalServiceProvider extends ServiceProvider
return $repository;
}
);
// also bind new API repository
$this->app->bind(
JournalAPIRepositoryInterface::class,
function (Application $app) {
/** @var JournalAPIRepositoryInterface $repository */
$repository = app(JournalAPIRepository::class);
if ($app->auth->check()) {
$repository->setUser(auth()->user());
}
return $repository;
}
);
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* JournalAPIRepository.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Log;
/**
* Class JournalAPIRepository
*/
class JournalAPIRepository implements JournalAPIRepositoryInterface
{
/** @var User */
private $user;
/**
* Constructor.
*/
public function __construct()
{
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/**
* Returns transaction by ID. Used to validate attachments.
*
* @param int $transactionId
*
* @return Transaction|null
*/
public function findTransaction(int $transactionId): ?Transaction
{
$transaction = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id)
->where('transactions.id', $transactionId)
->first(['transactions.*']);
return $transaction;
}
/**
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection
{
return $journal->attachments;
}
/**
* Get all piggy bank events for a journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getPiggyBankEvents(TransactionJournal $journal): Collection
{
/** @var Collection $set */
$events = $journal->piggyBankEvents()->get();
$events->each(
function (PiggyBankEvent $event) {
$event->piggyBank = $event->piggyBank()->withTrashed()->first();
}
);
return $events;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
}

View File

@ -0,0 +1,65 @@
<?php
/**
* JournalAPIRepositoryInterface.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Repositories\Journal;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\User;
use Illuminate\Support\Collection;
/**
* Interface JournalAPIRepositoryInterface
*/
interface JournalAPIRepositoryInterface
{
/**
* Returns transaction by ID. Used to validate attachments.
*
* @param int $transactionId
*
* @return Transaction|null
*/
public function findTransaction(int $transactionId): ?Transaction;
/**
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection;
/**
* Get all piggy bank events for a journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getPiggyBankEvents(TransactionJournal $journal): Collection;
/**
* @param User $user
*/
public function setUser(User $user);
}

View File

@ -0,0 +1,36 @@
<?php
/**
* JournalCLIRepositoryInterface.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Repositories\Journal;
use FireflyIII\User;
/**
* Interface JournalCLIRepositoryInterface
*/
interface JournalCLIRepositoryInterface
{
/**
* @param User $user
*/
public function setUser(User $user);
}

View File

@ -47,10 +47,6 @@ use stdClass;
/**
* Class JournalRepository.
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class JournalRepository implements JournalRepositoryInterface
{
@ -146,21 +142,6 @@ class JournalRepository implements JournalRepositoryInterface
return $this->user->transactionJournals()->where('id', $journalId)->first();
}
/**
* @param int $transactionid
*
* @return Transaction|null
*/
public function findTransaction(int $transactionid): ?Transaction
{
$transaction = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
->where('transaction_journals.user_id', $this->user->id)
->where('transactions.id', $transactionid)
->first(['transactions.*']);
return $transaction;
}
/**
* Get users first transaction journal or NULL.
*
@ -178,31 +159,6 @@ class JournalRepository implements JournalRepositoryInterface
return $result;
}
/**
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection
{
return $journal->attachments;
}
/**
* Get all attachments connected to the transaction group.
*
* @param TransactionJournal $transactionJournal
*
* @return Collection
*/
public function getAttachmentsByJournal(TransactionJournal $transactionJournal): Collection
{
// TODO: Implement getAttachmentsByJournal() method.
throw new NotImplementedException;
}
/**
* Return the ID of the budget linked to the journal (if any) or the transactions (if any).
*
@ -447,23 +403,7 @@ class JournalRepository implements JournalRepositoryInterface
return $note->text;
}
/**
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getPiggyBankEvents(TransactionJournal $journal): Collection
{
/** @var Collection $set */
$events = $journal->piggyBankEvents()->get();
$events->each(
function (PiggyBankEvent $event) {
$event->piggyBank = $event->piggyBank()->withTrashed()->first();
}
);
return $events;
}
/**
* Returns all journals with more than 2 transactions. Should only return empty collections

View File

@ -23,16 +23,13 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Models\TransactionJournalMeta;
use FireflyIII\Models\TransactionType;
use FireflyIII\User;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
/**
* Interface JournalRepositoryInterface.
@ -97,15 +94,6 @@ interface JournalRepositoryInterface
*/
public function findNull(int $journalId): ?TransactionJournal;
/**
* TODO maybe create API repository?
*
* @param int $transactionid
*
* @return Transaction|null
*/
public function findTransaction(int $transactionid): ?Transaction;
/**
* Get users very first transaction journal.
*
@ -113,17 +101,6 @@ interface JournalRepositoryInterface
*/
public function firstNull(): ?TransactionJournal;
/**
* TODO maybe create API repository?
*
* Return all attachments for journal.
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getAttachments(TransactionJournal $journal): Collection;
/**
* TODO console repository?
*
@ -235,15 +212,6 @@ interface JournalRepositoryInterface
*/
public function getNoteText(TransactionJournal $journal): ?string;
/**
* TODO used only in the API
*
* @param TransactionJournal $journal
*
* @return Collection
*/
public function getPiggyBankEvents(TransactionJournal $journal): Collection;
/**
* TODO used only on the console.
*

View File

@ -30,6 +30,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\User;
use Illuminate\Contracts\Validation\Rule;
@ -106,8 +107,9 @@ class IsValidAttachmentModel implements Rule
}
if (Transaction::class === $this->model) {
/** @var JournalRepositoryInterface $repository */
$repository = app(JournalRepositoryInterface::class);
/** @var JournalAPIRepositoryInterface $repository */
$repository = app(JournalAPIRepositoryInterface::class);
/** @var User $user */
$user = auth()->user();
$repository->setUser($user);

View File

@ -28,6 +28,7 @@ use Exception;
use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Transformers\TransactionGroupTransformer;
@ -69,11 +70,13 @@ class TransactionControllerTest extends TestCase
// mock repository
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -120,10 +123,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -173,10 +178,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -224,10 +231,13 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -275,10 +285,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -327,10 +339,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -381,11 +395,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
$data = [
'transactions' => [
],
@ -420,10 +435,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -480,10 +497,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -542,10 +561,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['transfer'])->atLeast()->once();
@ -609,11 +630,13 @@ class TransactionControllerTest extends TestCase
$transformer = $this->mock(TransactionGroupTransformer::class);
$validator = $this->mock(AccountValidator::class);
$collector = $this->mock(GroupCollectorInterface::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// validator:
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
@ -689,10 +712,12 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
@ -750,6 +775,7 @@ class TransactionControllerTest extends TestCase
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$validator = $this->mock(AccountValidator::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
$validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();
$validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();
@ -759,6 +785,7 @@ class TransactionControllerTest extends TestCase
// some mock calls:
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
$data = [
'group_title' => 'Empty',
@ -815,6 +842,7 @@ class TransactionControllerTest extends TestCase
$transformer = $this->mock(TransactionGroupTransformer::class);
$validator = $this->mock(AccountValidator::class);
$collector = $this->mock(GroupCollectorInterface::class);
$apiRepos = $this->mock(JournalAPIRepositoryInterface::class);
$validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();
$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);
@ -824,6 +852,7 @@ class TransactionControllerTest extends TestCase
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();
$repository->shouldReceive('setUser')->atLeast()->once();
$apiRepos->shouldReceive('setUser')->atLeast()->once();
// call stuff:
$repository->shouldReceive('update')->atLeast()->once()->andReturn($group);

View File

@ -410,7 +410,7 @@ class AccountFactoryTest extends TestCase
{
// mock repositories:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
@ -429,8 +429,6 @@ class AccountFactoryTest extends TestCase
// mock calls to the repository:
$accountRepos->shouldReceive('getOpeningBalanceGroup')->atLeast()->once()->andReturn(null);
$groupFactory->shouldReceive('setUser')->atLeast()->once();
$groupFactory->shouldReceive('create')->atLeast()->once();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_role', 'defaultAsset'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();

View File

@ -82,7 +82,8 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -156,7 +157,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -250,7 +251,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -358,7 +359,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -469,7 +470,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -582,7 +583,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -700,7 +701,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -788,7 +789,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -867,7 +868,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
$meta = new TransactionJournalMeta;
$meta->transaction_journal_id = 1;
@ -954,7 +955,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job
@ -1047,7 +1048,7 @@ class ImportArrayStorageTest extends TestCase
$language = new Preference;
$language->data = 'en_US';
Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($language)->atLeast()->once();
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'language', 'en_US'])->andReturn($language)->atLeast()->once();
// make fake job

View File

@ -28,6 +28,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalAPIRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Rules\IsValidAttachmentModel;
use Log;
@ -88,11 +89,11 @@ class IsValidAttachmentModelTest extends TestCase
*/
public function testTransaction(): void
{
$transaction = $this->getRandomWithdrawal()->transactions()->first();
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$transaction = $this->getRandomWithdrawal()->transactions()->first();
$apiJournalRepos = $this->mock(JournalAPIRepositoryInterface::class);
$journalRepos->shouldReceive('setUser')->atLeast()->once();
$journalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
$apiJournalRepos->shouldReceive('setUser')->atLeast()->once();
$apiJournalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
$value = $transaction->id;
$attribute = 'not-important';

View File

@ -23,7 +23,6 @@ declare(strict_types=1);
namespace Tests\Unit\TransactionRules\Actions;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\Transaction;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\TransactionRules\Actions\SetBudget;
use Illuminate\Support\Collection;
@ -42,9 +41,6 @@ class SetBudgetTest extends TestCase
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
@ -65,17 +61,13 @@ class SetBudgetTest extends TestCase
{
// get journal, remove all budgets
$journal = $this->getRandomWithdrawal();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$journal->budgets()->sync([]);
$this->assertEquals(0, $journal->budgets()->count());
// fire the action:
$ruleAction = new RuleAction;
$ruleAction->action_value = $budget->name;
$ruleAction->action_value = 'non-existing budget #' . $this->randomInt();
$action = new SetBudget($ruleAction);
$result = $action->act($journal);
$this->assertFalse($result);
@ -91,9 +83,6 @@ class SetBudgetTest extends TestCase
// get journal, remove all budgets
$journal = $this->getRandomDeposit();
$budget = $this->getRandomBudget();
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('setUser');
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection([$budget]));
$journal->budgets()->detach();
$this->assertEquals(0, $journal->budgets()->count());