diff --git a/app/Api/V1/Requests/RecurrenceStoreRequest.php b/app/Api/V1/Requests/RecurrenceStoreRequest.php index 50443d0af0..57cb6b73c5 100644 --- a/app/Api/V1/Requests/RecurrenceStoreRequest.php +++ b/app/Api/V1/Requests/RecurrenceStoreRequest.php @@ -210,7 +210,7 @@ class RecurrenceStoreRequest extends Request // new and updated fields: 'piggy_bank_id' => isset($transaction['piggy_bank_id']) ? (int)$transaction['piggy_bank_id'] : null, 'piggy_bank_name' => $transaction['piggy_bank_name'] ?? null, - 'tags' => $transaction['tags'], + 'tags' => $transaction['tags'] ?? [], 'budget_id' => isset($transaction['budget_id']) ? (int)$transaction['budget_id'] : null, 'budget_name' => $transaction['budget_name'] ?? null, 'category_id' => isset($transaction['category_id']) ? (int)$transaction['category_id'] : null, diff --git a/app/Console/Commands/Upgrade/BackToJournals.php b/app/Console/Commands/Upgrade/BackToJournals.php index 09a84b3113..728e78b4de 100644 --- a/app/Console/Commands/Upgrade/BackToJournals.php +++ b/app/Console/Commands/Upgrade/BackToJournals.php @@ -29,6 +29,7 @@ use FireflyIII\Models\Transaction; use FireflyIII\Models\TransactionJournal; use Illuminate\Console\Command; use Illuminate\Support\Collection; +use Log; /** * Class BackToJournals @@ -109,9 +110,11 @@ class BackToJournals extends Command $chunks = array_chunk($transactions, 500); foreach ($chunks as $chunk) { - $set = DB::table('transactions') - ->whereIn('transactions.id', $transactions) - ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); + $set = DB::table('transactions') + ->whereIn('transactions.id', $chunk) + ->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray(); + /** @noinspection SlowArrayOperationsInLoopInspection */ + $array = array_merge($array, $set); } return $array; @@ -156,6 +159,7 @@ class BackToJournals extends Command */ private function migrateAll(): void { + Log::debug('Now in migrateAll()'); $this->migrateBudgets(); $this->migrateCategories(); @@ -224,11 +228,16 @@ class BackToJournals extends Command */ private function migrateCategories(): void { + Log::debug('Now in migrateCategories()'); $journals = new Collection; $allIds = $this->getIdsForCategories(); - $chunks = array_chunk($allIds, 500); - foreach ($chunks as $journalIds) { - $collected = TransactionJournal::whereIn('id', $journalIds)->with(['transactions', 'categories', 'transactions.categories'])->get(); + + Log::debug(sprintf('Total: %d', count($allIds))); + + $chunks = array_chunk($allIds, 500); + foreach ($chunks as $chunk) { + Log::debug('Now doing a chunk.'); + $collected = TransactionJournal::whereIn('id', $chunk)->with(['transactions', 'categories', 'transactions.categories'])->get(); $journals = $journals->merge($collected); } $this->line(sprintf('Check %d transaction journal(s) for category info.', count($journals))); diff --git a/app/Exceptions/GracefulNotFoundHandler.php b/app/Exceptions/GracefulNotFoundHandler.php index fc047ee06e..0e484418f5 100644 --- a/app/Exceptions/GracefulNotFoundHandler.php +++ b/app/Exceptions/GracefulNotFoundHandler.php @@ -60,7 +60,7 @@ class GracefulNotFoundHandler extends ExceptionHandler switch ($name) { default: - Log::error(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name)); + Log::debug(sprintf('GracefulNotFoundHandler cannot handle route with name "%s"', $name)); return parent::render($request, $exception); case 'accounts.show': diff --git a/app/Factory/RecurrenceFactory.php b/app/Factory/RecurrenceFactory.php index f7cfb2f9d5..33a4f60431 100644 --- a/app/Factory/RecurrenceFactory.php +++ b/app/Factory/RecurrenceFactory.php @@ -96,7 +96,6 @@ class RecurrenceFactory ); $recurrence->save(); - //$this->updateMetaData($recurrence, $data); $this->createRepetitions($recurrence, $data['repetitions'] ?? []); try { $this->createTransactions($recurrence, $data['transactions'] ?? []); diff --git a/app/Http/Controllers/Recurring/EditController.php b/app/Http/Controllers/Recurring/EditController.php index acbc5a7a64..ee14c94334 100644 --- a/app/Http/Controllers/Recurring/EditController.php +++ b/app/Http/Controllers/Recurring/EditController.php @@ -129,7 +129,7 @@ class EditController extends Controller 'withdrawal_destination_id' => $array['transactions'][0]['destination_id'], ]; - $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags']); + $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags'] ?? []); return view( 'recurring.edit', diff --git a/app/Import/Storage/ImportArrayStorage.php b/app/Import/Storage/ImportArrayStorage.php index 211b075e2b..0c42ebf815 100644 --- a/app/Import/Storage/ImportArrayStorage.php +++ b/app/Import/Storage/ImportArrayStorage.php @@ -583,7 +583,6 @@ class ImportArrayStorage DB::table('tag_transaction_journal')->insert(['transaction_journal_id' => $journalId, 'tag_id' => $tagId]); } catch (QueryException $e) { Log::error(sprintf('Could not link journal #%d to tag #%d because: %s', $journalId, $tagId, $e->getMessage())); - Log::error($e->getTraceAsString()); } // @codeCoverageIgnoreEnd } diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.php index caf385c9f2..1fe38bf43f 100644 --- a/app/Repositories/Account/AccountRepository.php +++ b/app/Repositories/Account/AccountRepository.php @@ -518,7 +518,9 @@ class AccountRepository implements AccountRepositoryInterface */ public function searchAccount(string $query, array $types): Collection { - $dbQuery = $this->user->accounts()->with(['accountType']); + $dbQuery = $this->user->accounts() + ->where('active', 1) + ->with(['accountType']); if ('' !== $query) { $search = sprintf('%%%s%%', $query); $dbQuery->where('name', 'LIKE', $search); diff --git a/app/Services/Internal/Support/RecurringTransactionTrait.php b/app/Services/Internal/Support/RecurringTransactionTrait.php index e29a44b658..d1475c815b 100644 --- a/app/Services/Internal/Support/RecurringTransactionTrait.php +++ b/app/Services/Internal/Support/RecurringTransactionTrait.php @@ -266,7 +266,6 @@ trait RecurringTransactionTrait */ protected function updatePiggyBank(RecurrenceTransaction $transaction, int $piggyId, string $piggyName): void { - /** @var PiggyBankFactory $factory */ $factory = app(PiggyBankFactory::class); $factory->setUser($transaction->recurrence->user); diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.php index 0ca74e82f1..487bdab988 100644 --- a/app/Services/Internal/Update/AccountUpdateService.php +++ b/app/Services/Internal/Update/AccountUpdateService.php @@ -90,7 +90,7 @@ class AccountUpdateService $account->save(); // find currency, or use default currency instead. - if (null !== $data['currency_id'] || null !== $data['currency_code']) { + if (isset($data['currency_id']) && (null !== $data['currency_id'] || null !== $data['currency_code'])) { $currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null)); unset($data['currency_code']); $data['currency_id'] = $currency->id; diff --git a/app/Support/FireflyConfig.php b/app/Support/FireflyConfig.php index 11a51616d5..94a7c058ff 100644 --- a/app/Support/FireflyConfig.php +++ b/app/Support/FireflyConfig.php @@ -40,7 +40,7 @@ class FireflyConfig public function delete(string $name): void { if ('testing' === config('app.env')) { - Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__)); + Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name)); } $fullName = 'ff-config-' . $name; if (Cache::has($fullName)) { @@ -63,7 +63,7 @@ class FireflyConfig public function get(string $name, $default = null): ?Configuration { if ('testing' === config('app.env')) { - Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__)); + Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name)); } $fullName = 'ff-config-' . $name; if (Cache::has($fullName)) { diff --git a/app/Support/Http/Controllers/BasicDataSupport.php b/app/Support/Http/Controllers/BasicDataSupport.php index ea627dde8c..3e62be2e4e 100644 --- a/app/Support/Http/Controllers/BasicDataSupport.php +++ b/app/Support/Http/Controllers/BasicDataSupport.php @@ -45,7 +45,8 @@ trait BasicDataSupport */ foreach ($data as $entryId => $set) { $sum = '0'; - foreach ($set['entries'] as $amount) { + $entries = $set['entries'] ?? []; + foreach ($entries as $amount) { $sum = bcadd($amount, $sum); } $data[$entryId]['sum'] = $sum; diff --git a/app/Support/Preferences.php b/app/Support/Preferences.php index 72bd3a2f03..999f515d43 100644 --- a/app/Support/Preferences.php +++ b/app/Support/Preferences.php @@ -99,7 +99,7 @@ class Preferences public function get(string $name, $default = null): ?Preference { if ('testing' === config('app.env')) { - Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__)); + Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name)); } /** @var User $user */ $user = auth()->user(); @@ -149,7 +149,7 @@ class Preferences public function getForUser(User $user, string $name, $default = null): ?Preference { if ('testing' === config('app.env')) { - Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__)); + Log::warning(sprintf('%s("%s") should NOT be called in the TEST environment!', __METHOD__, $name)); } $fullName = sprintf('preference%s%s', $user->id, $name); if (Cache::has($fullName)) { diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.php index bbab73358f..69415cd78c 100644 --- a/app/Support/Twig/General.php +++ b/app/Support/Twig/General.php @@ -208,10 +208,6 @@ class General extends Twig_Extension return new Twig_SimpleFunction( 'accountGetMetaField', static function (Account $account, string $field): string { - if ('testing' === config('app.env')) { - Log::warning('Twig General::getMetaField should NOT be called in the TEST environment!'); - } - /** @var AccountRepositoryInterface $repository */ $repository = app(AccountRepositoryInterface::class); $result = $repository->getMetaValue($account, $field); diff --git a/app/Support/Twig/TransactionGroupTwig.php b/app/Support/Twig/TransactionGroupTwig.php index 4d1c91238e..de46620276 100644 --- a/app/Support/Twig/TransactionGroupTwig.php +++ b/app/Support/Twig/TransactionGroupTwig.php @@ -148,9 +148,6 @@ class TransactionGroupTwig extends Twig_Extension return new Twig_SimpleFunction( 'journalHasMeta', static function (int $journalId, string $metaField) { - if ('testing' === config('app.env')) { - Log::warning('Twig TransactionGroup::journalHasMeta should NOT be called in the TEST environment!'); - } $count = DB::table('journal_meta') ->where('name', $metaField) ->where('transaction_journal_id', $journalId) diff --git a/app/Transformers/CategoryTransformer.php b/app/Transformers/CategoryTransformer.php index cfe3173fd2..bc22a2f793 100644 --- a/app/Transformers/CategoryTransformer.php +++ b/app/Transformers/CategoryTransformer.php @@ -25,7 +25,6 @@ namespace FireflyIII\Transformers; use FireflyIII\Models\Category; -use FireflyIII\Repositories\Category\CategoryRepositoryInterface; use FireflyIII\Repositories\Category\OperationsRepositoryInterface; use Illuminate\Support\Collection; use Log; @@ -37,8 +36,6 @@ class CategoryTransformer extends AbstractTransformer { /** @var OperationsRepositoryInterface */ private $opsRepository; - /** @var CategoryRepositoryInterface */ - private $repository; /** * CategoryTransformer constructor. @@ -47,7 +44,6 @@ class CategoryTransformer extends AbstractTransformer */ public function __construct() { - $this->repository = app(CategoryRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); if ('testing' === config('app.env')) { Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this))); @@ -63,7 +59,6 @@ class CategoryTransformer extends AbstractTransformer */ public function transform(Category $category): array { - $this->repository->setUser($category->user); $this->opsRepository->setUser($category->user); $spent = []; @@ -101,7 +96,7 @@ class CategoryTransformer extends AbstractTransformer { $return = []; foreach ($array as $data) { - $data['sum'] = round($data['sum'], $data['currency_decimal_places']); + $data['sum'] = round($data['sum'], (int)$data['currency_decimal_places']); $return[] = $data; } diff --git a/app/Transformers/RuleTransformer.php b/app/Transformers/RuleTransformer.php index 0ca8a0f2a0..fb66aac7eb 100644 --- a/app/Transformers/RuleTransformer.php +++ b/app/Transformers/RuleTransformer.php @@ -75,7 +75,7 @@ class RuleTransformer extends AbstractTransformer 'active' => $rule->active, 'strict' => $rule->strict, 'stop_processing' => $rule->stop_processing, - 'trigger' => $this->getRuleTrigger($rule), + 'trigger' => $this->getRuleTrigger($rule), 'triggers' => $this->triggers($rule), 'actions' => $this->actions($rule), 'links' => [ diff --git a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php index c5ccefda5c..984c02dec6 100644 --- a/tests/Api/V1/Controllers/BudgetLimitControllerTest.php +++ b/tests/Api/V1/Controllers/BudgetLimitControllerTest.php @@ -120,6 +120,7 @@ class BudgetLimitControllerTest extends TestCase $repository->shouldReceive('setUser')->once(); // call API + Log::warning('The following error is part of a test.'); $response = $this->post(route('api.v1.budget_limits.store'), $data); $response->assertStatus(500); $response->assertSee('Unknown budget.'); diff --git a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php b/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php index 07418b3bb0..65d9944bc8 100644 --- a/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php +++ b/tests/Api/V1/Controllers/Chart/CategoryControllerTest.php @@ -24,8 +24,11 @@ namespace Tests\Api\V1\Controllers\Chart; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; +use FireflyIII\Repositories\Category\NoCategoryRepositoryInterface; +use FireflyIII\Repositories\Category\OperationsRepositoryInterface; use Laravel\Passport\Passport; use Log; +use Tests\Support\TestDataTrait; use Tests\TestCase; /** @@ -36,6 +39,8 @@ use Tests\TestCase; */ class CategoryControllerTest extends TestCase { + use TestDataTrait; + /** * */ @@ -52,65 +57,21 @@ class CategoryControllerTest extends TestCase public function testOverview(): void { $repository = $this->mock(CategoryRepositoryInterface::class); + $noCatRepos =$this->mock(NoCategoryRepositoryInterface::class); + $opsRepos = $this->mock(OperationsRepositoryInterface::class); - $spent = [ - 2 => [ - 'name' => 'Some other category', - 'spent' => [ - // earned in this currency. - 1 => [ - 'currency_decimal_places' => 2, - 'currency_symbol' => 'x', - 'currency_code' => 'EUR', - 'currency_id' => 1, - 'spent' => '-522', - ], - ], - ], - ]; - - $earned = [ - 1 => [ - 'name' => 'Some category', - 'earned' => [ - // earned in this currency. - 2 => [ - 'currency_decimal_places' => 2, - 'currency_id' => 1, - 'currency_symbol' => 'x', - 'currency_code' => 'EUR', - 'earned' => '123', - ], - ], - ], - ]; - - $earnedNoCategory = [ - 1 => [ - 'currency_decimal_places' => 2, - 'currency_id' => 3, - 'currency_symbol' => 'x', - 'currency_code' => 'EUR', - 'earned' => '123', - ], - ]; - $spentNoCategory = [ - 5 => [ - 'currency_decimal_places' => 2, - 'currency_symbol' => 'x', - 'currency_code' => 'EUR', - 'currency_id' => 4, - 'spent' => '-345', - ], - ]; // mock calls: $repository->shouldReceive('setUser')->atLeast()->once(); - $repository->shouldReceive('spentInPeriodPerCurrency')->atLeast()->once()->andReturn($spent); - $repository->shouldReceive('earnedInPeriodPerCurrency')->atLeast()->once()->andReturn($earned); + $noCatRepos->shouldReceive('setUser')->atLeast()->once(); + $opsRepos->shouldReceive('setUser')->atLeast()->once(); + + $opsRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->categoryListExpenses()); + $opsRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->categoryListIncome()); + + $noCatRepos->shouldReceive('listExpenses')->atLeast()->once()->andReturn($this->noCategoryListExpenses()); + $noCatRepos->shouldReceive('listIncome')->atLeast()->once()->andReturn($this->noCategoryListIncome()); - $repository->shouldReceive('earnedInPeriodPcWoCategory')->atLeast()->once()->andReturn($earnedNoCategory); - $repository->shouldReceive('spentInPeriodPcWoCategory')->atLeast()->once()->andReturn($spentNoCategory); $parameters = [ 'start' => '2019-01-01', diff --git a/tests/Api/V1/Controllers/LinkTypeControllerTest.php b/tests/Api/V1/Controllers/LinkTypeControllerTest.php index 53816a9645..51d94abba4 100644 --- a/tests/Api/V1/Controllers/LinkTypeControllerTest.php +++ b/tests/Api/V1/Controllers/LinkTypeControllerTest.php @@ -118,6 +118,7 @@ class LinkTypeControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->post(route('api.v1.link_types.store'), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('You need the \"owner\"-role to do this.'); @@ -207,6 +208,7 @@ class LinkTypeControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('You cannot edit this link type '); @@ -248,6 +250,7 @@ class LinkTypeControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->put(route('api.v1.link_types.update', [$linkType->id]), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('You need the \"owner\"-role to do this.'); diff --git a/tests/Api/V1/Controllers/PiggyBankControllerTest.php b/tests/Api/V1/Controllers/PiggyBankControllerTest.php index 6b20a2ee59..ce53a0a56d 100644 --- a/tests/Api/V1/Controllers/PiggyBankControllerTest.php +++ b/tests/Api/V1/Controllers/PiggyBankControllerTest.php @@ -112,6 +112,7 @@ class PiggyBankControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->post(route('api.v1.piggy_banks.store'), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertHeader('Content-Type', 'application/json'); diff --git a/tests/Api/V1/Controllers/RecurrenceControllerTest.php b/tests/Api/V1/Controllers/RecurrenceControllerTest.php index 8ad80b3fa2..b820ce14c4 100644 --- a/tests/Api/V1/Controllers/RecurrenceControllerTest.php +++ b/tests/Api/V1/Controllers/RecurrenceControllerTest.php @@ -1256,7 +1256,7 @@ class RecurrenceControllerTest extends TestCase [ 'message' => 'The given data was invalid.', 'errors' => [ - 'description' => [ + 'repetitions' => [ 'Need at least one repetition.', ], ], @@ -1309,7 +1309,7 @@ class RecurrenceControllerTest extends TestCase [ 'message' => 'The given data was invalid.', 'errors' => [ - 'description' => [ + 'transactions' => [ 'Need at least one transaction.', ], ], diff --git a/tests/Api/V1/Controllers/RuleGroupControllerTest.php b/tests/Api/V1/Controllers/RuleGroupControllerTest.php index 165350993c..4e58999767 100644 --- a/tests/Api/V1/Controllers/RuleGroupControllerTest.php +++ b/tests/Api/V1/Controllers/RuleGroupControllerTest.php @@ -172,6 +172,7 @@ class RuleGroupControllerTest extends TestCase // call API $group = $this->user()->ruleGroups()->first(); + Log::warning('The following error is part of a test.'); $response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('{"message":"No rules in this rule group.","exception":"FireflyIII\\\\Exceptions\\\\FireflyException"'); diff --git a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php b/tests/Api/V1/Controllers/TransactionLinkControllerTest.php index ed57e7d286..cfc21cad23 100644 --- a/tests/Api/V1/Controllers/TransactionLinkControllerTest.php +++ b/tests/Api/V1/Controllers/TransactionLinkControllerTest.php @@ -257,6 +257,7 @@ class TransactionLinkControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->post(route('api.v1.transaction_links.store'), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('Source or destination is NULL.'); // the creation moment. @@ -380,6 +381,7 @@ class TransactionLinkControllerTest extends TestCase ]; // test API + Log::warning('The following error is part of a test.'); $response = $this->put(route('api.v1.transaction_links.update', $journalLink->id), $data, ['Accept' => 'application/json']); $response->assertStatus(500); $response->assertSee('Source or destination is NULL.'); // the creation moment. diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php index 9e762d2dab..79561de704 100644 --- a/tests/Feature/Controllers/AttachmentControllerTest.php +++ b/tests/Feature/Controllers/AttachmentControllerTest.php @@ -126,6 +126,7 @@ class AttachmentControllerTest extends TestCase $repository->shouldReceive('exists')->once()->andReturn(false); + Log::warning('The following error is part of a test.'); $this->be($this->user()); $response = $this->get(route('attachments.download', [$attachment->id])); $response->assertStatus(500); diff --git a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php index 956128ca36..5b3336f269 100644 --- a/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php +++ b/tests/Feature/Controllers/Auth/TwoFactorControllerTest.php @@ -22,12 +22,13 @@ declare(strict_types=1); namespace Tests\Feature\Controllers\Auth; +use FireflyIII\Models\Configuration; use FireflyIII\Models\Preference; use Google2FA; use Log; use Preferences; use Tests\TestCase; - +use FireflyConfig; /** * Class TwoFactorControllerTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -54,6 +55,11 @@ class TwoFactorControllerTest extends TestCase $langPreference = new Preference; $langPreference->data = 'en_US'; + $falseConfig = new Configuration; + $falseConfig->data = false; + + FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->andReturn($falseConfig); + Preferences::shouldReceive('get')->withArgs(['language', 'en_US'])->andReturn($langPreference); $response = $this->get(route('two-factor.lost')); diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php index f3c0d41a90..a350194100 100644 --- a/tests/Feature/Controllers/BillControllerTest.php +++ b/tests/Feature/Controllers/BillControllerTest.php @@ -166,14 +166,17 @@ class BillControllerTest extends TestCase $userRepos = $this->mock(UserRepositoryInterface::class); $transformer = $this->mock(BillTransformer::class); $euro = $this->getEuro(); - $pref = new Preference; - $pref->data = 50; - Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); + //$pref = new Preference; + //$pref->data = 50; + //Preferences::shouldReceive('get')->withArgs(['listPageSize', 50])->atLeast()->once()->andReturn($pref); Amount::shouldReceive('formatAnything')->andReturn('-100'); $transformer->shouldReceive('setParameters')->atLeast()->once(); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn( - ['id' => 5, 'active' => true, 'name' => 'x', 'next_expected_match' => '2018-01-01', + ['id' => 5, 'active' => true, + 'name' => 'x', 'next_expected_match' => '2018-01-01', + 'amount_min' => '10', + 'amount_max' => '10', 'currency' => $this->getEuro(), 'currency_id' => $euro->id, 'currency_code' => $euro->code, @@ -185,7 +188,7 @@ class BillControllerTest extends TestCase $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once(); $collection = new Collection([$bill]); - $repository->shouldReceive('getPaginator')->andReturn(new LengthAwarePaginator($collection, 1, 50))->once(); + $repository->shouldReceive('getBills')->andReturn($collection)->once(); $repository->shouldReceive('setUser'); $repository->shouldReceive('getNoteText')->andReturn('Hi there'); $repository->shouldReceive('getRulesForBills')->andReturn([]); diff --git a/tests/Feature/Controllers/Chart/BudgetControllerTest.php b/tests/Feature/Controllers/Chart/BudgetControllerTest.php index 3125ba94bc..99dff45af0 100644 --- a/tests/Feature/Controllers/Chart/BudgetControllerTest.php +++ b/tests/Feature/Controllers/Chart/BudgetControllerTest.php @@ -121,6 +121,7 @@ class BudgetControllerTest extends TestCase // mock default session $this->mockDefaultSession(); + Log::warning('The following error is part of a test.'); $this->be($this->user()); $response = $this->get(route('chart.budget.budget-limit', [$budget->id, $limit->id])); $response->assertStatus(500); diff --git a/tests/Feature/Controllers/CurrencyControllerTest.php b/tests/Feature/Controllers/CurrencyControllerTest.php index 354353a0a9..f034fd41dc 100644 --- a/tests/Feature/Controllers/CurrencyControllerTest.php +++ b/tests/Feature/Controllers/CurrencyControllerTest.php @@ -295,6 +295,7 @@ class CurrencyControllerTest extends TestCase $repository->shouldReceive('getAll')->atLeast()->once()->andReturn(new Collection); Preferences::shouldReceive('mark')->atLeast()->once(); + Log::warning('The following error is part of a test.'); $this->be($this->user()); $response = $this->get(route('currencies.disable', [$euro->id])); $response->assertStatus(500); diff --git a/tests/Feature/Controllers/Import/JobStatusControllerTest.php b/tests/Feature/Controllers/Import/JobStatusControllerTest.php index 01544a6c85..2c92cfd2d7 100644 --- a/tests/Feature/Controllers/Import/JobStatusControllerTest.php +++ b/tests/Feature/Controllers/Import/JobStatusControllerTest.php @@ -275,6 +275,7 @@ class JobStatusControllerTest extends TestCase $routine->shouldReceive('run')->andThrow(new Exception('Unknown exception')); // call thing. + Log::warning('The following error is part of a test.'); $this->be($this->user()); $response = $this->post(route('import.job.start', [$job->key])); $response->assertStatus(200); @@ -308,6 +309,7 @@ class JobStatusControllerTest extends TestCase $routine->shouldReceive('run')->andThrow(new FireflyException('Unknown exception')); // call thing. + Log::warning('The following error is part of a test.'); $this->be($this->user()); $response = $this->post(route('import.job.start', [$job->key])); $response->assertStatus(200); diff --git a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php index 376201714a..95ab78633a 100644 --- a/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php +++ b/tests/Feature/Controllers/Json/AutoCompleteControllerTest.php @@ -25,6 +25,7 @@ namespace Tests\Feature\Controllers\Json; use FireflyIII\Models\AccountType; use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface; use Illuminate\Support\Collection; use Log; use Tests\TestCase; @@ -115,6 +116,7 @@ class AutoCompleteControllerTest extends TestCase */ public function testAllJournals(): void { + $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class); $journalRepos = $this->mockDefaultSession(); $journal = $this->getRandomWithdrawalAsArray(); @@ -134,6 +136,7 @@ class AutoCompleteControllerTest extends TestCase */ public function testAllJournalsWithId(): void { + $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class); $journalRepos = $this->mockDefaultSession(); $journal = $this->getRandomWithdrawalAsArray(); @@ -155,12 +158,13 @@ class AutoCompleteControllerTest extends TestCase */ public function testAllJournalsWithIdNumeric(): void { + $groupRepos = $this->mock(TransactionGroupRepositoryInterface::class); $journalRepos = $this->mockDefaultSession(); $journal = $this->getRandomWithdrawalAsArray(); - $journalObject = $this->getRandomWithdrawal(); + $journalObject = $this->getRandomWithdrawalGroup(); $journalRepos->shouldReceive('searchJournalDescriptions')->atLeast()->once()->andReturn(new Collection([$journal])); - $journalRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($journalObject); + $groupRepos->shouldReceive('find')->atLeast()->once()->andReturn($journalObject); $this->be($this->user()); diff --git a/tests/Feature/Controllers/Json/FrontpageControllerTest.php b/tests/Feature/Controllers/Json/FrontpageControllerTest.php index a19d33ebff..c3ecdfefa8 100644 --- a/tests/Feature/Controllers/Json/FrontpageControllerTest.php +++ b/tests/Feature/Controllers/Json/FrontpageControllerTest.php @@ -26,6 +26,7 @@ use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use Illuminate\Support\Collection; use Log; use Tests\TestCase; +use Amount; /** * Class FrontpageControllerTest @@ -57,6 +58,8 @@ class FrontpageControllerTest extends TestCase $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggy])); $repository->shouldReceive('getCurrentAmount')->andReturn('10'); + Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x'); + $this->be($this->user()); $response = $this->get(route('json.fp.piggy-banks')); $response->assertStatus(200); diff --git a/tests/Feature/Controllers/Json/ReconcileControllerTest.php b/tests/Feature/Controllers/Json/ReconcileControllerTest.php index 9491f23019..24f9b297bd 100644 --- a/tests/Feature/Controllers/Json/ReconcileControllerTest.php +++ b/tests/Feature/Controllers/Json/ReconcileControllerTest.php @@ -35,6 +35,7 @@ use Log; use Mockery; use Preferences; use Tests\TestCase; +use Steam; /** * @@ -117,9 +118,11 @@ class ReconcileControllerTest extends TestCase $euro = $this->getEuro(); $withdrawal = $this->getRandomWithdrawalAsArray(); + Steam::shouldReceive('balance')->atLeast()->once()->andReturn('20'); + $accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro); - Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); + //Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345'); Amount::shouldReceive('formatAnything')->andReturn('-100'); $fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date); diff --git a/tests/Feature/Controllers/ProfileControllerTest.php b/tests/Feature/Controllers/ProfileControllerTest.php index 02c6fa8167..d281161a44 100644 --- a/tests/Feature/Controllers/ProfileControllerTest.php +++ b/tests/Feature/Controllers/ProfileControllerTest.php @@ -116,7 +116,8 @@ class ProfileControllerTest extends TestCase $this->mock(UserRepositoryInterface::class); Preferences::shouldReceive('findByName')->withArgs(['email_change_confirm_token'])->andReturn(new Collection()); - // email_change_confirm_token + + Log::warning('The following error is part of a test.'); $response = $this->get(route('profile.confirm-email-change', ['some-fake-token'])); $response->assertStatus(500); } @@ -583,6 +584,7 @@ class ProfileControllerTest extends TestCase Preferences::shouldReceive('findByName')->once()->andReturn(new Collection([$tokenPreference])); Preferences::shouldReceive('beginsWith')->once()->andReturn(new Collection([$hashPreference])); + Log::warning('The following error is part of a test.'); $response = $this->get(route('profile.undo-email-change', ['token', $hash])); $response->assertStatus(500); } diff --git a/tests/Feature/Controllers/Recurring/IndexControllerTest.php b/tests/Feature/Controllers/Recurring/IndexControllerTest.php index d09f3fe23e..cab0b2a1a2 100644 --- a/tests/Feature/Controllers/Recurring/IndexControllerTest.php +++ b/tests/Feature/Controllers/Recurring/IndexControllerTest.php @@ -162,47 +162,5 @@ class IndexControllerTest extends TestCase } - /** - * @covers \FireflyIII\Http\Controllers\Recurring\IndexController - */ - public function testShow(): void - { - $repository = $this->mock(RecurringRepositoryInterface::class); - $budgetRepos = $this->mock(BudgetRepositoryInterface::class); - $userRepos = $this->mock(UserRepositoryInterface::class); - $categoryFactory = $this->mock(CategoryFactory::class); - $transformer = $this->mock(RecurrenceTransformer::class); - - $this->mockDefaultSession(); - - $transformer->shouldReceive('setParameters')->atLeast()->once(); - $transformer->shouldReceive('transform')->atLeast()->once()->andReturn( - [ - 'id' => 5, - 'first_date' => '2018-01-01', - 'repeat_until' => null, - 'latest_date' => null, - 'recurrence_repetitions' => [ - [ - 'occurrences' => [ - '2019-01-01', - ], - ], - ], - ] - ); - - $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); - - $recurrence = $this->user()->recurrences()->first(); - $repository->shouldReceive('setUser'); - $repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once(); - - $this->be($this->user()); - $response = $this->get(route('recurring.show', [$recurrence->id])); - $response->assertStatus(200); - $response->assertSee('