diff --git a/app/Helpers/Report/PopupReport.php b/app/Helpers/Report/PopupReport.php index 23c8d50d18..a50b248377 100644 --- a/app/Helpers/Report/PopupReport.php +++ b/app/Helpers/Report/PopupReport.php @@ -33,6 +33,8 @@ use Illuminate\Support\Collection; /** * Class PopupReport. + * + * @codeCoverageIgnore */ class PopupReport implements PopupReportInterface { diff --git a/app/Helpers/Report/ReportHelper.php b/app/Helpers/Report/ReportHelper.php index 1ae2577ae5..bd8c5af15a 100644 --- a/app/Helpers/Report/ReportHelper.php +++ b/app/Helpers/Report/ReportHelper.php @@ -35,6 +35,8 @@ use Illuminate\Support\Collection; /** * Class ReportHelper. + * + * @codeCoverageIgnore */ class ReportHelper implements ReportHelperInterface { diff --git a/app/Http/Controllers/Budget/AmountController.php b/app/Http/Controllers/Budget/AmountController.php index cccc4682cc..f6d7a52ba0 100644 --- a/app/Http/Controllers/Budget/AmountController.php +++ b/app/Http/Controllers/Budget/AmountController.php @@ -36,6 +36,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Support\Collection; +use Log; /** * Class AmountController @@ -160,6 +161,8 @@ class AmountController extends Controller $average = $this->repository->getAverageAvailable($start, $end); $available = bcmul($average, (string)$daysInPeriod); + Log::debug(sprintf('Average is %s, so total available is %s because days is %d.', $average, $available, $daysInPeriod)); + // amount earned in this period: /** @var TransactionCollectorInterface $collector */ $collector = app(TransactionCollectorInterface::class); @@ -169,6 +172,8 @@ class AmountController extends Controller // This is multiplied by the number of days in the current period, showing you the average. $earnedAverage = bcmul(bcdiv($earned, (string)$daysInSearchPeriod), (string)$daysInPeriod); + Log::debug(sprintf('Earned is %s, earned average is %s', $earned, $earnedAverage)); + // amount spent in period /** @var TransactionCollectorInterface $collector */ $collector = app(TransactionCollectorInterface::class); @@ -176,11 +181,16 @@ class AmountController extends Controller $spent = (string)$collector->getTransactions()->sum('transaction_amount'); $spentAverage = app('steam')->positive(bcmul(bcdiv($spent, (string)$daysInSearchPeriod), (string)$daysInPeriod)); + Log::debug(sprintf('Spent is %s, spent average is %s', $earned, $earnedAverage)); + // the default suggestion is the money the user has spent, on average, over this period. $suggested = $spentAverage; + Log::debug(sprintf('Suggested is now %s (spent average)',$suggested)); + // if the user makes less per period, suggest that amount instead. if (1 === bccomp($spentAverage, $earnedAverage)) { + Log::debug(sprintf('Because earned average (%s) is less than spent average (%s) will suggest earned average instead.', $earnedAverage, $spentAverage)); $suggested = $earnedAverage; } diff --git a/app/Http/Controllers/Import/CallbackController.php b/app/Http/Controllers/Import/CallbackController.php index 2fb1e0b612..f85915ac19 100644 --- a/app/Http/Controllers/Import/CallbackController.php +++ b/app/Http/Controllers/Import/CallbackController.php @@ -48,10 +48,13 @@ class CallbackController extends Controller { $code = (string)$request->get('code'); $jobKey = (string)$request->get('state'); - $importJob = $repository->findByKey($jobKey); + if ('' === $code) { return view('error')->with('message', 'You Need A Budget did not reply with a valid authorization code. Firefly III cannot continue.'); } + + $importJob = $repository->findByKey($jobKey); + if ('' === $jobKey || null === $importJob) { return view('error')->with('message', 'You Need A Budget did not reply with the correct state identifier. Firefly III cannot continue.'); } diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.php index a270d98a8b..a3f36b4ad0 100644 --- a/app/Http/Controllers/JsonController.php +++ b/app/Http/Controllers/JsonController.php @@ -49,10 +49,12 @@ class JsonController extends Controller } try { $view = view('rules.partials.action', compact('actions', 'count'))->render(); + // @codeCoverageIgnoreStart } catch (Throwable $e) { Log::error(sprintf('Cannot render rules.partials.action: %s', $e->getMessage())); $view = 'Could not render view.'; } + // @codeCoverageIgnoreEnd return response()->json(['html' => $view]); } @@ -78,10 +80,12 @@ class JsonController extends Controller try { $view = view('rules.partials.trigger', compact('triggers', 'count'))->render(); + // @codeCoverageIgnoreStart } catch (Throwable $e) { Log::error(sprintf('Cannot render rules.partials.trigger: %s', $e->getMessage())); $view = 'Could not render view.'; } + // @codeCoverageIgnoreEnd return response()->json(['html' => $view]); } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index 74d6c134e2..a22196b051 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -190,17 +190,10 @@ class ProfileController extends Controller /** * Enable 2FA screen. * - * @param UserRepositoryInterface $repository - * * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector */ - public function enable2FA(UserRepositoryInterface $repository) + public function enable2FA() { - /** @var User $user */ - $user = auth()->user(); - if ($repository->hasRole($user, 'demo')) { - return redirect(route('profile.index')); - } $hasSecret = (null !== app('preferences')->get('twoFactorAuthSecret')); // if we don't have a valid secret yet, redirect to the code page to get one. diff --git a/app/Http/Controllers/SearchController.php b/app/Http/Controllers/SearchController.php index 57e1b9e949..3799299e90 100644 --- a/app/Http/Controllers/SearchController.php +++ b/app/Http/Controllers/SearchController.php @@ -102,10 +102,12 @@ class SearchController extends Controller } try { $html = view('search.search', compact('transactions'))->render(); + // @codeCoverageIgnoreStart } catch (Throwable $e) { Log::error(sprintf('Cannot render search.search: %s', $e->getMessage())); $html = 'Could not render view.'; } + // @codeCoverageIgnoreEnd return response()->json(['count' => $transactions->count(), 'html' => $html]); } diff --git a/tests/Feature/Controllers/Account/EditControllerTest.php b/tests/Feature/Controllers/Account/EditControllerTest.php index ed2ea90af1..d05f92e21c 100644 --- a/tests/Feature/Controllers/Account/EditControllerTest.php +++ b/tests/Feature/Controllers/Account/EditControllerTest.php @@ -92,6 +92,47 @@ class EditControllerTest extends TestCase $response->assertSee('Some text'); } + /** + * @covers \FireflyIII\Http\Controllers\Account\EditController + */ + public function testEditLiability(): void + { + $journalRepos = $this->mock(JournalRepositoryInterface::class); + $repository = $this->mock(CurrencyRepositoryInterface::class); + $accountRepos = $this->mock(AccountRepositoryInterface::class); + + $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(); + $accountRepos->shouldReceive('getOpeningBalanceAmount')->andReturnNull(); + $accountRepos->shouldReceive('getOpeningBalanceDate')->andReturnNull(); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountRole'])->andReturn('defaultAsset'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccType'])->andReturn(''); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'ccMonthlyPaymentDate'])->andReturn(''); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('BIC'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('1'); + $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly'); + + // get all types: + $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Debt'])->andReturn(AccountType::find(11))->once(); + $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Loan'])->andReturn(AccountType::find(9))->once(); + $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Mortgage'])->andReturn(AccountType::find(12))->once(); + $accountRepos->shouldReceive('getAccountTypeByType')->withArgs(['Credit card'])->andReturn(AccountType::find(13))->once(); + + + $this->be($this->user()); + $account = $this->user()->accounts()->where('account_type_id', 12)->whereNull('deleted_at')->first(); + $response = $this->get(route('accounts.edit', [$account->id])); + $response->assertStatus(200); + // has bread crumb + $response->assertSee('