Skip to content

Firefly III: a personal finances manager

Repositories will now warn if used in test environment.

James Colebb9f76372933
diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php
index d70c7d665a..2e50399817 100644
--- a/app/Repositories/Account/AccountRepository.php
+++ b/app/Repositories/Account/AccountRepository.php
@@ -46,6 +46,16 @@ class AccountRepository implements AccountRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param array $types
*
diff --git a/app/Repositories/Account/AccountTasker.php b/app/Repositories/Account/AccountTasker.php
index 679369d7d7..3939baf11b 100644
--- a/app/Repositories/Account/AccountTasker.php
+++ b/app/Repositories/Account/AccountTasker.php
@@ -38,6 +38,16 @@ class AccountTasker implements AccountTaskerInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param Collection $accounts
* @param Carbon $start
diff --git a/app/Repositories/Attachment/AttachmentRepository.php b/app/Repositories/Attachment/AttachmentRepository.php
index 1d5d55d7bc..501c846a0c 100644
--- a/app/Repositories/Attachment/AttachmentRepository.php
+++ b/app/Repositories/Attachment/AttachmentRepository.php
@@ -45,6 +45,16 @@ class AttachmentRepository implements AttachmentRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param Attachment $attachment
*
diff --git a/app/Repositories/Bill/BillRepository.php b/app/Repositories/Bill/BillRepository.php
index 9ede87e449..b651b885b7 100644
--- a/app/Repositories/Bill/BillRepository.php
+++ b/app/Repositories/Bill/BillRepository.php
@@ -48,6 +48,16 @@ class BillRepository implements BillRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param Bill $bill
*
diff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.php
index 4b3da1a5b4..483128389e 100644
--- a/app/Repositories/Budget/BudgetRepository.php
+++ b/app/Repositories/Budget/BudgetRepository.php
@@ -54,6 +54,16 @@ class BudgetRepository implements BudgetRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* A method that returns the amount of money budgeted per day for this budget,
* on average.
diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.php
index 2a78a7b8ca..da7dee7d10 100644
--- a/app/Repositories/Category/CategoryRepository.php
+++ b/app/Repositories/Category/CategoryRepository.php
@@ -47,6 +47,16 @@ class CategoryRepository implements CategoryRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param Category $category
*
diff --git a/app/Repositories/Currency/CurrencyRepository.php b/app/Repositories/Currency/CurrencyRepository.php
index 8698ae74a8..de448a62ac 100644
--- a/app/Repositories/Currency/CurrencyRepository.php
+++ b/app/Repositories/Currency/CurrencyRepository.php
@@ -43,10 +43,13 @@ class CurrencyRepository implements CurrencyRepositoryInterface
private $user;
/**
- * CurrencyRepository constructor.
+ * Constructor.
*/
public function __construct()
{
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
}
/**
diff --git a/app/Repositories/ExportJob/ExportJobRepository.php b/app/Repositories/ExportJob/ExportJobRepository.php
index 756af68450..9ffd1b11b7 100644
--- a/app/Repositories/ExportJob/ExportJobRepository.php
+++ b/app/Repositories/ExportJob/ExportJobRepository.php
@@ -39,6 +39,16 @@ class ExportJobRepository implements ExportJobRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param ExportJob $job
* @param string $status
diff --git a/app/Repositories/ImportJob/ImportJobRepository.php b/app/Repositories/ImportJob/ImportJobRepository.php
index f325f85166..b3bac14750 100644
--- a/app/Repositories/ImportJob/ImportJobRepository.php
+++ b/app/Repositories/ImportJob/ImportJobRepository.php
@@ -53,6 +53,10 @@ class ImportJobRepository implements ImportJobRepositoryInterface
{
$this->maxUploadSize = (int)config('firefly.maxUploadSize');
$this->uploadDisk = Storage::disk('upload');
+
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
}
/**
@@ -380,7 +384,6 @@ class ImportJobRepository implements ImportJobRepositoryInterface
}
-
/**
* @codeCoverageIgnore
*
diff --git a/app/Repositories/Journal/JournalRepository.php b/app/Repositories/Journal/JournalRepository.php
index c89d31e2fd..4250739b81 100644
--- a/app/Repositories/Journal/JournalRepository.php
+++ b/app/Repositories/Journal/JournalRepository.php
@@ -54,6 +54,16 @@ class JournalRepository implements JournalRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/** @noinspection MoreThanThreeArgumentsInspection */
/**
* @param TransactionJournal $journal
diff --git a/app/Repositories/LinkType/LinkTypeRepository.php b/app/Repositories/LinkType/LinkTypeRepository.php
index 9006f4c459..f7e8c7fcee 100644
--- a/app/Repositories/LinkType/LinkTypeRepository.php
+++ b/app/Repositories/LinkType/LinkTypeRepository.php
@@ -40,6 +40,16 @@ class LinkTypeRepository implements LinkTypeRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param LinkType $linkType
*
diff --git a/app/Repositories/PiggyBank/PiggyBankRepository.php b/app/Repositories/PiggyBank/PiggyBankRepository.php
index a06aabe5c6..7e45411a99 100644
--- a/app/Repositories/PiggyBank/PiggyBankRepository.php
+++ b/app/Repositories/PiggyBank/PiggyBankRepository.php
@@ -44,6 +44,16 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param PiggyBank $piggyBank
* @param string $amount
diff --git a/app/Repositories/Recurring/RecurringRepository.php b/app/Repositories/Recurring/RecurringRepository.php
index 86157afce5..de9bad9bed 100644
--- a/app/Repositories/Recurring/RecurringRepository.php
+++ b/app/Repositories/Recurring/RecurringRepository.php
@@ -56,6 +56,16 @@ class RecurringRepository implements RecurringRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* Destroy a recurring transaction.
*
diff --git a/app/Repositories/Rule/RuleRepository.php b/app/Repositories/Rule/RuleRepository.php
index a17f1ff9c9..7b9049eb58 100644
--- a/app/Repositories/Rule/RuleRepository.php
+++ b/app/Repositories/Rule/RuleRepository.php
@@ -29,6 +29,7 @@ use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\User;
use Illuminate\Support\Collection;
+use Log;
/**
* Class RuleRepository.
@@ -40,6 +41,16 @@ class RuleRepository implements RuleRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @return int
*/
diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.php
index 54cbf8ef31..68dccf9faf 100644
--- a/app/Repositories/RuleGroup/RuleGroupRepository.php
+++ b/app/Repositories/RuleGroup/RuleGroupRepository.php
@@ -27,6 +27,7 @@ use FireflyIII\Models\RuleGroup;
use FireflyIII\User;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Collection;
+use Log;
/**
* Class RuleGroupRepository.
@@ -36,6 +37,16 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @return int
*/
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index d6a5d7076d..928bd97b0f 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -43,6 +43,16 @@ class TagRepository implements TagRepositoryInterface
/** @var User */
private $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @return int
*/
diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php
index 35fe26d618..987ec400e9 100644
--- a/app/Repositories/User/UserRepository.php
+++ b/app/Repositories/User/UserRepository.php
@@ -36,6 +36,16 @@ use Log;
*/
class UserRepository implements UserRepositoryInterface
{
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @return Collection
*/
@@ -55,6 +65,7 @@ class UserRepository implements UserRepositoryInterface
$roleObject = Role::where('name', $role)->first();
if (null === $roleObject) {
Log::error(sprintf('Could not find role "%s" in attachRole()', $role));
+
return false;
}
diff --git a/app/Services/Currency/FixerIOv2.php b/app/Services/Currency/FixerIOv2.php
index 0bbfbc556d..3c33c8e547 100644
--- a/app/Services/Currency/FixerIOv2.php
+++ b/app/Services/Currency/FixerIOv2.php
@@ -39,6 +39,16 @@ class FixerIOv2 implements ExchangeRateInterface
/** @var User */
protected $user;
+ /**
+ * Constructor.
+ */
+ public function __construct()
+ {
+ if ('testing' === env('APP_ENV')) {
+ Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
+ }
+ }
+
/**
* @param TransactionCurrency $fromCurrency
* @param TransactionCurrency $toCurrency
diff --git a/tests/Feature/Controllers/Account/CreateControllerTest.php b/tests/Feature/Controllers/Account/CreateControllerTest.php
index a378f1bf6a..37576b188b 100644
--- a/tests/Feature/Controllers/Account/CreateControllerTest.php
+++ b/tests/Feature/Controllers/Account/CreateControllerTest.php
@@ -30,11 +30,12 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Preferences;
use Tests\TestCase;
-
+use Mockery;
/**
*
* Class CreateControllerTest
@@ -60,9 +61,13 @@ class CreateControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
+
// get all types:
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once();
$accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once();
@@ -87,7 +92,7 @@ class CreateControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -116,7 +121,7 @@ class CreateControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
diff --git a/tests/Feature/Controllers/Account/DeleteControllerTest.php b/tests/Feature/Controllers/Account/DeleteControllerTest.php
index 482df158d7..01a8d1c2fb 100644
--- a/tests/Feature/Controllers/Account/DeleteControllerTest.php
+++ b/tests/Feature/Controllers/Account/DeleteControllerTest.php
@@ -29,8 +29,10 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
+use Mockery;
use Tests\TestCase;
/**
@@ -57,10 +59,13 @@ class DeleteControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
+
$this->be($this->user());
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
$response = $this->get(route('accounts.delete', [$account->id]));
@@ -78,7 +83,6 @@ class DeleteControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('findNull')->withArgs([0])->once()->andReturn(null);
$repository->shouldReceive('destroy')->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php
index d05f92e21c..1d2a0b9f90 100644
--- a/tests/Feature/Controllers/Account/EditControllerTest.php
+++ b/tests/Feature/Controllers/Account/EditControllerTest.php
@@ -31,6 +31,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@@ -56,11 +57,16 @@ class EditControllerTest extends TestCase
*/
public function testEdit(): void
{
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ $repository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->atLeast()->once();
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
- $repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
$repository->shouldReceive('get')->andReturn(new Collection);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('getNoteText')->andReturn('Some text')->once();
@@ -97,9 +103,13 @@ class EditControllerTest extends TestCase
*/
public function testEditLiability(): void
{
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
$repository->shouldReceive('get')->andReturn(new Collection);
@@ -139,9 +149,13 @@ class EditControllerTest extends TestCase
public function testEditNull(): void
{
// mock stuff
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(2));
$repository->shouldReceive('findNull')->once()->andReturn(null);
@@ -187,6 +201,7 @@ class EditControllerTest extends TestCase
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
diff --git a/tests/Feature/Controllers/Account/IndexControllerTest.php b/tests/Feature/Controllers/Account/IndexControllerTest.php
index 7dfc39e66f..c8000218e9 100644
--- a/tests/Feature/Controllers/Account/IndexControllerTest.php
+++ b/tests/Feature/Controllers/Account/IndexControllerTest.php
@@ -28,6 +28,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@@ -67,6 +68,11 @@ class IndexControllerTest extends TestCase
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
+
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
diff --git a/tests/Feature/Controllers/Account/ReconcileControllerTest.php b/tests/Feature/Controllers/Account/ReconcileControllerTest.php
index 289e9233cb..cb7569c612 100644
--- a/tests/Feature/Controllers/Account/ReconcileControllerTest.php
+++ b/tests/Feature/Controllers/Account/ReconcileControllerTest.php
@@ -30,6 +30,7 @@ use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@@ -56,7 +57,14 @@ class ReconcileControllerTest extends TestCase
*/
public function testEdit(): void
{
- $repository = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(JournalRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
+
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
$repository->shouldReceive('firstNull')->andReturn($journal);
@@ -80,6 +88,9 @@ class ReconcileControllerTest extends TestCase
*/
public function testEditRedirect(): void
{
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.edit', [$journal->id]));
@@ -95,7 +106,13 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcile(): void
{
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
+
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [1, '20170101', '20170131']));
@@ -126,7 +143,13 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileNoDates(): void
{
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
+
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
@@ -144,7 +167,13 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileNoEndDate(): void
{
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(CurrencyRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
+
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
$this->be($this->user());
@@ -162,6 +191,9 @@ class ReconcileControllerTest extends TestCase
*/
public function testReconcileNotAsset(): void
{
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$account = $this->user()->accounts()->where('account_type_id', '!=', 6)->where('account_type_id', '!=', 3)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile', [$account->id, '20170101', '20170131']));
@@ -175,8 +207,16 @@ class ReconcileControllerTest extends TestCase
*/
public function testShow(): void
{
- $journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
+ $userRepos = $this->mock(UserRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
+
+ $journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
+
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('getAssetTransaction')->once()->andReturn($journal->transactions()->first());
@@ -196,8 +236,12 @@ class ReconcileControllerTest extends TestCase
*/
public function testShowError(): void
{
- $journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$repository = $this->mock(JournalRepositoryInterface::class);
+
+ $journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
+
$repository->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('getAssetTransaction')->once()->andReturnNull();
@@ -217,6 +261,9 @@ class ReconcileControllerTest extends TestCase
*/
public function testShowSomethingElse(): void
{
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
$this->be($this->user());
$response = $this->get(route('accounts.reconcile.show', [$journal->id]));
@@ -234,6 +281,8 @@ class ReconcileControllerTest extends TestCase
{
$repository = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('reconcileById')->andReturn(true);
$journalRepos->shouldReceive('store')->andReturn(new TransactionJournal);
@@ -262,6 +311,9 @@ class ReconcileControllerTest extends TestCase
public function testUpdate(): void
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('getJournalSourceAccounts')->andReturn(new Collection([new Account]));
$journalRepos->shouldReceive('getJournalDestinationAccounts')->andReturn(new Collection([new Account]));
@@ -285,9 +337,7 @@ class ReconcileControllerTest extends TestCase
public function testUpdateNotReconcile(): void
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', '!=', 5)->first();
- $data = [
- 'amount' => '5',
- ];
+ $data = ['amount' => '5',];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.update', [$journal->id]), $data);
@@ -302,9 +352,7 @@ class ReconcileControllerTest extends TestCase
public function testUpdateZero(): void
{
$journal = $this->user()->transactionJournals()->where('transaction_type_id', 5)->first();
- $data = [
- 'amount' => '0',
- ];
+ $data = ['amount' => '0',];
$this->be($this->user());
$response = $this->post(route('accounts.reconcile.update', [$journal->id]), $data);
diff --git a/tests/Feature/Controllers/Account/ShowControllerTest.php b/tests/Feature/Controllers/Account/ShowControllerTest.php
index 238d030730..0e2eb30b7e 100644
--- a/tests/Feature/Controllers/Account/ShowControllerTest.php
+++ b/tests/Feature/Controllers/Account/ShowControllerTest.php
@@ -32,9 +32,11 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Log;
+use Mockery;
use Tests\TestCase;
/**
@@ -68,6 +70,10 @@ class ShowControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@@ -115,6 +121,10 @@ class ShowControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@@ -154,9 +164,8 @@ class ShowControllerTest extends TestCase
public function testShowBrokenBadDates(): void
{
// mock
- $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->session(['start' => '2018-01-01', 'end' => '2017-12-01']);
$this->be($this->user());
@@ -172,7 +181,6 @@ class ShowControllerTest extends TestCase
{
// mock
$journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
@@ -197,6 +205,12 @@ class ShowControllerTest extends TestCase
$collector = $this->mock(TransactionCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $userRepos = $this->mock(UserRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
+
+ // mock hasRole for user repository:
+ $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(),'owner'])->andReturn(true)->atLeast()->once();
+
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
@@ -204,7 +218,7 @@ class ShowControllerTest extends TestCase
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getPaginatedTransactions')->andReturn(new LengthAwarePaginator([], 0, 10));
- $repository = $this->mock(AccountRepositoryInterface::class);
+
$repository->shouldReceive('oldestJournalDate')->andReturn(new Carbon);
$repository->shouldReceive('getMetaValue')->andReturn('');
$repository->shouldReceive('isLiability')->andReturn(false);
@@ -230,8 +244,7 @@ class ShowControllerTest extends TestCase
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
- $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
- $accountRepos = $this->mock(AccountRepositoryInterface::class);
+
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
@@ -258,6 +271,7 @@ class ShowControllerTest extends TestCase
$tasker = $this->mock(AccountTaskerInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
$currencyRepos->shouldReceive('findNull')->andReturn(TransactionCurrency::find(1));
@@ -265,7 +279,7 @@ class ShowControllerTest extends TestCase
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
- $repository = $this->mock(AccountRepositoryInterface::class);
+
$repository->shouldReceive('getMetaValue')->andReturn('');
$repository->shouldReceive('isLiability')->andReturn(true);