Repositories will now warn if used in test environment.

This commit is contained in:
James Cole
2018-09-03 08:41:03 +02:00
parent fb61229bf3
commit bb9f763729
24 changed files with 294 additions and 33 deletions

View File

@@ -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
*

View File

@@ -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

View File

@@ -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
*

View File

@@ -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
*

View File

@@ -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.

View File

@@ -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
*

View File

@@ -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)));
}
}
/**

View File

@@ -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

View File

@@ -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
*

View File

@@ -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

View File

@@ -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
*

View File

@@ -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

View File

@@ -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.
*

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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
*/

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;
@@ -59,8 +60,13 @@ class EditControllerTest extends TestCase
$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();
@@ -100,6 +106,10 @@ class EditControllerTest extends TestCase
$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);
@@ -142,6 +152,10 @@ class EditControllerTest extends TestCase
$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);

View File

@@ -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);

View File

@@ -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;
@@ -57,6 +58,13 @@ class ReconcileControllerTest extends TestCase
public function testEdit(): void
{
$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);

View File

@@ -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));
@@ -156,7 +166,6 @@ class ShowControllerTest extends TestCase
// mock
$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);