Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Reset some code.
James Cole6f063a134f76
diff --git a/app/Api/V1/Controllers/AccountController.php b/app/Api/V1/Controllers/AccountController.phpindex c650a89410..7982f8c576 100644--- a/app/Api/V1/Controllers/AccountController.php+++ b/app/Api/V1/Controllers/AccountController.php@@ -23,7 +23,10 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Controllers;+use Exception;use FireflyIII\Api\V1\Requests\AccountRequest;+use FireflyIII\Api\V1\Requests\AccountStoreRequest;+use FireflyIII\Api\V1\Requests\AccountUpdateRequest;use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Models\Account;use FireflyIII\Repositories\Account\AccountRepositoryInterface;@@ -76,7 +79,7 @@ class AccountController extends Controller/*** Remove the specified resource from storage.*- * @param \FireflyIII\Models\Account $account+ * @param Account $account** @return JsonResponse*/@@ -132,7 +135,7 @@ class AccountController extends Controller/**- * List all of them.+ * List all piggies.** @param Request $request* @param Account $account@@ -177,7 +180,7 @@ class AccountController extends Controller* @param Request $request* @param Account $account*- * @return \Illuminate\Http\JsonResponse+ * @return JsonResponse*/public function show(Request $request, Account $account): JsonResponse{@@ -196,11 +199,12 @@ class AccountController extends Controller/*** Store a new instance.*- * @param AccountRequest $request+ * @param AccountStoreRequest $request*- * @return \Illuminate\Http\JsonResponse+ * @return JsonResponse+ * @throws Exception*/- public function store(AccountRequest $request): JsonResponse+ public function store(AccountStoreRequest $request): JsonResponse{$data = $request->getAll();$account = $this->repository->store($data);@@ -285,12 +289,13 @@ class AccountController extends Controller/*** Update account.*- * @param AccountRequest $request- * @param Account $account+ * @param AccountUpdateRequest $request+ * @param Account $account*- * @return \Illuminate\Http\JsonResponse+ * @return JsonResponse+ * @throws Exception*/- public function update(AccountRequest $request, Account $account): JsonResponse+ public function update(AccountUpdateRequest $request, Account $account): JsonResponse{$data = $request->getAll();$data['type'] = config('firefly.shortNamesByFullName.' . $account->accountType->type);diff --git a/app/Api/V1/Requests/AccountRequest.php b/app/Api/V1/Requests/AccountStoreRequest.phpsimilarity index 85%rename from app/Api/V1/Requests/AccountRequest.phprename to app/Api/V1/Requests/AccountStoreRequest.phpindex 3485c75eaa..8bea3fdf00 100644--- a/app/Api/V1/Requests/AccountRequest.php+++ b/app/Api/V1/Requests/AccountStoreRequest.php@@ -1,8 +1,8 @@<?php/**- * AccountRequest.php- * Copyright (c) 2018 [email protected]+ * AccountStoreRequest.php+ * Copyright (c) 2019 [email protected]** This file is part of Firefly III.*@@ -24,12 +24,13 @@ declare(strict_types=1);namespace FireflyIII\Api\V1\Requests;+use Exception;use FireflyIII\Rules\IsBoolean;/**- * Class AccountRequest+ * Class AccountStoreRequest*/-class AccountRequest extends Request+class AccountStoreRequest extends Request{/**@@ -47,6 +48,7 @@ class AccountRequest extends Request* Get all data from the request.** @return array+ * @throws Exception*/public function getAll(): array{@@ -103,7 +105,7 @@ class AccountRequest extends Request$ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));$rules = ['name' => 'required|min:1|uniqueAccountForUser',- 'type' => 'required|in:' . $types,+ 'type' => sprintf('in:%s', $types),'iban' => 'iban|nullable','bic' => 'bic|nullable','account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser',@@ -114,8 +116,8 @@ class AccountRequest extends Request'currency_code' => 'min:3|max:3|exists:transaction_currencies,code','active' => [new IsBoolean],'include_net_worth' => [new IsBoolean],- 'account_role' => 'in:' . $accountRoles . '|required_if:type,asset',- 'credit_card_type' => 'in:' . $ccPaymentTypes . '|required_if:account_role,ccAsset',+ 'account_role' => sprintf('in:%s|required_if:type,asset', $accountRoles),+ 'credit_card_type' => sprintf('in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull','liability_type' => 'required_if:type,liability|in:loan,debt,mortgage','liability_amount' => 'required_if:type,liability|min:0|numeric',@@ -124,17 +126,6 @@ class AccountRequest extends Request'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly','notes' => 'min:0|max:65536',];- switch ($this->method()) {- default:- break;- case 'PUT':- case 'PATCH':- $account = $this->route()->parameter('account');- $rules['name'] .= ':' . $account->id;- $rules['account_number'] .= ':' . $account->id;- $rules['type'] = 'in:' . $types;- break;- }return $rules;}diff --git a/app/Api/V1/Requests/AccountUpdateRequest.php b/app/Api/V1/Requests/AccountUpdateRequest.phpnew file mode 100644index 0000000000..45e1dda395--- /dev/null+++ b/app/Api/V1/Requests/AccountUpdateRequest.php@@ -0,0 +1,133 @@+<?php++/**+ * AccountUpdateRequest.php+ * Copyright (c) 2018 [email protected]+ *+ * This file is part of Firefly III.+ *+ * Firefly III is free software: you can redistribute it and/or modify+ * it under the terms of the GNU General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * Firefly III is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU General Public License for more details.+ *+ * You should have received a copy of the GNU General Public License+ * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Api\V1\Requests;++use Exception;+use FireflyIII\Rules\IsBoolean;++/**+ * Class AccountUpdateRequest+ */+class AccountUpdateRequest extends Request+{++ /**+ * Authorize logged in users.+ *+ * @return bool+ */+ public function authorize(): bool+ {+ // Only allow authenticated users+ return auth()->check();+ }++ /**+ * Get all data from the request.+ *+ * @return array+ * @throws Exception+ */+ public function getAll(): array+ {+ $active = true;+ $includeNetWorth = true;+ if (null !== $this->get('active')) {+ $active = $this->boolean('active');+ }+ if (null !== $this->get('include_net_worth')) {+ $includeNetWorth = $this->boolean('include_net_worth');+ }++ $data = [+ 'name' => $this->string('name'),+ 'active' => $active,+ 'include_net_worth' => $includeNetWorth,+ 'accountType' => $this->string('type'),+ 'account_type_id' => null,+ 'currency_id' => $this->integer('currency_id'),+ 'currency_code' => $this->string('currency_code'),+ 'virtualBalance' => $this->string('virtual_balance'),+ 'iban' => $this->string('iban'),+ 'BIC' => $this->string('bic'),+ 'accountNumber' => $this->string('account_number'),+ 'accountRole' => $this->string('account_role'),+ 'openingBalance' => $this->string('opening_balance'),+ 'openingBalanceDate' => $this->date('opening_balance_date'),+ 'ccType' => $this->string('credit_card_type'),+ 'ccMonthlyPaymentDate' => $this->string('monthly_payment_date'),+ 'notes' => $this->string('notes'),+ 'interest' => $this->string('interest'),+ 'interest_period' => $this->string('interest_period'),+ ];++ if ('liability' === $data['accountType']) {+ $data['openingBalance'] = bcmul($this->string('liability_amount'), '-1');+ $data['openingBalanceDate'] = $this->date('liability_start_date');+ $data['accountType'] = $this->string('liability_type');+ $data['account_type_id'] = null;+ }++ return $data;+ }++ /**+ * The rules that the incoming request must be matched against.+ *+ * @return array+ */+ public function rules(): array+ {+ $account = $this->route()->parameter('account');+ $accountRoles = implode(',', config('firefly.accountRoles'));+ $types = implode(',', array_keys(config('firefly.subTitlesByIdentifier')));+ $ccPaymentTypes = implode(',', array_keys(config('firefly.ccTypes')));+ $rules = [+ 'name' => sprintf('required|min:1|uniqueAccountForUser:%d', $account->id),+ 'type' => sprintf('in:%s', $types),+ 'iban' => 'iban|nullable',+ 'bic' => 'bic|nullable',+ 'account_number' => sprintf('between:1,255|nullable|uniqueAccountNumberForUser:%d', $account->id),+ 'opening_balance' => 'numeric|required_with:opening_balance_date|nullable',+ 'opening_balance_date' => 'date|required_with:opening_balance|nullable',+ 'virtual_balance' => 'numeric|nullable',+ 'currency_id' => 'numeric|exists:transaction_currencies,id',+ 'currency_code' => 'min:3|max:3|exists:transaction_currencies,code',+ 'active' => [new IsBoolean],+ 'include_net_worth' => [new IsBoolean],+ 'account_role' => sprintf('in:%s|required_if:type,asset', $accountRoles),+ 'credit_card_type' => sprintf('in:%s|required_if:account_role,ccAsset', $ccPaymentTypes),+ 'monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:credit_card_type,monthlyFull',+ 'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage',+ 'liability_amount' => 'required_if:type,liability|min:0|numeric',+ 'liability_start_date' => 'required_if:type,liability|date',+ 'interest' => 'required_if:type,liability|between:0,100|numeric',+ 'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly',+ 'notes' => 'min:0|max:65536',+ ];++ return $rules;+ }+}diff --git a/app/Http/Requests/JournalFormRequest.php b/app/Http/Requests/JournalFormRequest.phpindex aa70075cf2..5eeb5e783e 100644--- a/app/Http/Requests/JournalFormRequest.php+++ b/app/Http/Requests/JournalFormRequest.php@@ -166,7 +166,7 @@ class JournalFormRequest extends Request'notes' => 'min:1|max:50000|nullable',// and then transaction rules:'description' => 'required|between:1,255',- 'amount' => 'numeric|required|more:0|less:10000000',//+ 'amount' => 'numeric|required|more:0|less:1000000000','budget_id' => 'mustExist:budgets,id|belongsToUser:budgets,id|nullable','category' => 'between:1,255|nullable','source_id' => 'numeric|belongsToUser:accounts,id|nullable',diff --git a/app/Support/Twig/Extension/TransactionGroupTwig.php b/app/Support/Twig/Extension/TransactionGroupTwig.phpindex c6f773e4c1..ca6de28ebf 100644--- a/app/Support/Twig/Extension/TransactionGroupTwig.php+++ b/app/Support/Twig/Extension/TransactionGroupTwig.php@@ -172,7 +172,7 @@ class TransactionGroupTwig extends Twig_Extensionprivate function normalGroupAmount(array $array): string{// take cue from the first entry in the array:- $first = $array['transactions'][0];+ $first = reset($array['transactions']);$type = $first['transaction_type_type'] ?? TransactionType::WITHDRAWAL;$amount = $array['sum'] ?? '0';$colored = true;diff --git a/phpunit.coverage.xml b/phpunit.coverage.xmlindex 60bc506b70..a0300eba95 100644--- a/phpunit.coverage.xml+++ b/phpunit.coverage.xml@@ -27,7 +27,7 @@convertNoticesToExceptions="true"convertWarningsToExceptions="true"processIsolation="false"- stopOnFailure="true">+ stopOnFailure="false"><listeners><listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /></listeners>diff --git a/phpunit.xml b/phpunit.xmlindex 736d18a486..2a6b8da0cf 100644--- a/phpunit.xml+++ b/phpunit.xml@@ -27,7 +27,7 @@convertNoticesToExceptions="true"convertWarningsToExceptions="true"processIsolation="false"- stopOnFailure="true">+ stopOnFailure="false"><listeners><listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" /></listeners>diff --git a/resources/views/v1/list/groups-tiny.twig b/resources/views/v1/list/groups-tiny.twigindex 149a3669b3..23a017c2d5 100644--- a/resources/views/v1/list/groups-tiny.twig+++ b/resources/views/v1/list/groups-tiny.twig@@ -1,46 +1,19 @@<div class="list-group">{% for group in groups %}- <a class="list-group-item" href="{{ route('transactions.show', [group.id]) }}">+ <a class="list-group-item" href="{{ route('transactions.show', [group.id]) }}">{% for transaction in group.transactions %}{{ transaction.description }}<span class="pull-right small">{{ transactionAmount(transaction) }}</span>- <br />+ <br/>{% endfor %}{% if group.count > 1 %} - <span class="pull-right small">+ <span class="pull-right small">{{ groupAmount(group) }}</span>{% endif %}-- </a>--- {# if group do something with format #}- {#{% if group.count > 1 %}- (group)- {% endif %}-#}- {# loop each transaction #}- {#- <a class="list-group-item" title="{{ transaction.date.formatLocalized(trans('config.month_and_day')) }}"- {% if transaction.transaction_type_type == 'Opening balance' %}- href="#"- {% else %}- href="{{ route('transactions.show',transaction.journal_id) }}"- {% endif %}>- {{ transaction|transactionIcon }}- {{ transaction|transactionDescription }}- <span class="pull-right small">- {{ transaction|transactionAmount }}- </span>-</a>- {% endfor %}- #}-{% endfor %}-</div>\ No newline at end of filediff --git a/resources/views/v1/list/journals-tiny.twig b/resources/views/v1/list/journals-tiny.twigdeleted file mode 100644index 47715f955c..0000000000--- a/resources/views/v1/list/journals-tiny.twig+++ /dev/null@@ -1 +0,0 @@-<h1 style="color:red;">DO NOT USE ME</h1>\ No newline at end of filediff --git a/resources/views/v1/list/journals.twig b/resources/views/v1/list/journals.twigdeleted file mode 100644index 9a1d5d1837..0000000000--- a/resources/views/v1/list/journals.twig+++ /dev/null@@ -1,79 +0,0 @@-<h1 style="color:red;">DO NOT USE</h1>---{#-{{ transactions.render|raw }}--<table class="table table-hover table-condensed {% if sorting %}sortable-table{% endif %}">- <thead>- <tr class="ignore">- <th class="hidden-xs no_select_boxes" colspan="2"> </th>- <th class="hidden-xs select_boxes" colspan="2" style="display: none;"><input name="select_all" class="select_all" type="checkbox"/></th>- <th>{{ trans('list.description') }}</th>- <th>{{ trans('list.amount') }}</th>- <th class="hidden-xs hidden-sm">{{ trans('list.date') }}</th>- <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.from') }}</th>- <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.to') }}</th>- {% if not hideBudgets %}- <th class="hidden-xs"><i class="fa fa-tasks fa-fw" title="{{ trans('list.budget') }}"></i></th>- {% endif %}-- {% if not hideCategories %}- <th class="hidden-xs"><i class="fa fa-bar-chart fa-fw" title="{{ trans('list.category') }}"></i></th>- {% endif %}-- {% if not hideBills %}- <th class="hidden-xs"><i class="fa fa-fw fa-calendar-o" title="{{ trans('list.bill') }}"></i></th>- {% endif %}- </tr>- </thead>- <tbody>- {% for transaction in transactions %}- {% include 'partials.journal-row' %}- {% endfor %}- </tbody>-</table>-<div class="row mass_edit_all hidden-xs" style="display: none;padding:8px;">- <div class="col-lg-8 col-md-12 col-sm-12 col-xs-12">- <div class="btn-group dropup mass_button_options" style="display:none;">- <button type="button" class="btn btn-default">{{ 'actions'|_ }}</button>- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">- <span class="caret"></span>- <span class="sr-only">Toggle Dropdown</span>- </button>- <ul class="dropdown-menu">- <li><a href="#" class="mass_edit"><i class="fa fa-fw fa-pencil"></i> <span>{{ 'edit'|_ }}</span></a></li>- <li><a href="#" class="bulk_edit"><i class="fa fa-fw fa-pencil-square-o"></i> <span>{{ 'bulk_edit'|_ }}</span></a></li>- <li><a href="#" class="mass_delete"><i class="fa fa-fw fa-trash"></i> <span>{{ 'delete'|_ }}</span></a></li>- </ul>- </div>- </div>- <div class="col-lg-4 col-md-12 col-sm-12 col-xs-12 hidden-xs">- <div class="mass_buttons btn-group btn-group pull-right">- <a href="#" class="btn btn-default mass_select"><i class="fa fa-fw fa-check-square-o"></i> {{ 'select_transactions'|_ }}</a>- <a href="#" class="btn btn-default mass_stop_select" style="display:none;"><i class="fa faw-fw fa-square-o"- ></i> {{ 'stop_selection'|_ }}</a>-- {% if showReconcile == true %}- {% if Route.getCurrentRoute.getName =='accounts.show.all' %}- <a href="{{ route('accounts.reconcile', [account.id, start.format('Ymd')]) }}" class="btn btn-info mass_reconcile"><i- class="fa fa-fw fa-check"></i> {{ 'reconcile_this_account'|_ }}</a>- {% else %}- <a href="{{ route('accounts.reconcile', [account.id, start.format('Ymd'), end.format('Ymd')]) }}" class="btn btn-info mass_reconcile"><i- class="fa fa-fw fa-check"></i> {{ 'reconcile_this_account'|_ }}</a>- {% endif %}- {% endif %}- </div>- </div>-</div>-<div class="row" style="padding:8px;">- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">- {{ transactions.render|raw }}- </div>-</div>-<script type="text/javascript">- var edit_selected_txt = "{{ trans('firefly.edit')|escape('js') }}";- var edit_bulk_selected_txt = "{{ trans('firefly.bulk_edit')|escape('js') }}";- var delete_selected_txt = "{{ trans('firefly.delete')|escape('js') }}";-</script>-#}\ No newline at end of filediff --git a/resources/views/v1/list/transactions.twig b/resources/views/v1/list/transactions.twigdeleted file mode 100644index f122531c9c..0000000000--- a/resources/views/v1/list/transactions.twig+++ /dev/null@@ -1,80 +0,0 @@-{# render pagination #}-{{ transactions.render|raw }}--<table class="table table-hover table-condensed {% if sorting %}sortable-table{% endif %}">- <thead>- <tr class="ignore">- {# hidden row for checkboxes #}- <th class="hidden-xs select_boxes" style="display: none;"><input name="select_all" class="select_all" type="checkbox"/></th>-- {# header for icon #}- <th class="hidden-xs"></th>- <th>{{ trans('list.description') }}</th>- <th style="text-align:right;">{{ trans('list.amount') }}</th>- <th class="hidden-xs hidden-sm">{{ trans('list.date') }}</th>- <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.from') }}</th>- <th class="hidden-xs hidden-sm hidden-md">{{ trans('list.to') }}</th>-- {# Only show budgets when asked in some way #}- {% if showBudgets %}- <th class="hidden-xs"><i class="fa fa-tasks fa-fw" title="{{ trans('list.budget') }}"></i></th>- {% endif %}-- {# Only show categories when asked in some way #}- {% if showCategories %}- <th class="hidden-xs"><i class="fa fa-bar-chart fa-fw" title="{{ trans('list.category') }}"></i></th>- {% endif %}-- {# Only show bill when asked in some way #}- {% if showBill %}- <th class="hidden-xs"><i class="fa fa-fw fa-calendar-o" title="{{ trans('list.bill') }}"></i></th>- {% endif %}-- {# visible row for edit/delete buttons #}- <th class="hidden-xs no_select_boxes"> </th>- </tr>- </thead>- <tbody>- {% for transaction in transactions %}- {% include 'partials.transaction-row' %}- {% endfor %}- </tbody>-</table>-<div class="row mass_edit_all hidden-xs" style="display: none;padding:8px;">- <div class="col-lg-8 col-md-12 col-sm-12 col-xs-12">- <div class="btn-group dropup mass_button_options" style="display:none;">- <button type="button" class="btn btn-default">{{ 'actions'|_ }}</button>- <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">- <span class="caret"></span>- <span class="sr-only">Toggle Dropdown</span>- </button>- <ul class="dropdown-menu">- <li><a href="#" class="mass_edit"><i class="fa fa-fw fa-pencil"></i> <span>{{ 'edit'|_ }}</span></a></li>- <li><a href="#" class="bulk_edit"><i class="fa fa-fw fa-pencil-square-o"></i> <span>{{ 'bulk_edit'|_ }}</span></a></li>- <li><a href="#" class="mass_delete"><i class="fa fa-fw fa-trash"></i> <span>{{ 'delete'|_ }}</span></a></li>- </ul>- </div>- </div>- <div class="col-lg-4 col-md-12 col-sm-12 col-xs-12 hidden-xs">- <div class="mass_buttons btn-group btn-group pull-right">- <a href="#" class="btn btn-default mass_select"><i class="fa fa-fw fa-check-square-o"></i> {{ 'select_transactions'|_ }}</a>- <a href="#" class="btn btn-default mass_stop_select" style="display:none;"><i class="fa faw-fw fa-square-o"- ></i> {{ 'stop_selection'|_ }}</a>-- {% if showReconcile == true %}- {% if Route.getCurrentRoute.getName =='accounts.show.all' %}- <a href="{{ route('accounts.reconcile', [account.id, start.format('Ymd')]) }}" class="btn btn-info mass_reconcile"><i- class="fa fa-fw fa-check"></i> {{ 'reconcile_this_account'|_ }}</a>- {% else %}- <a href="{{ route('accounts.reconcile', [account.id, start.format('Ymd'), end.format('Ymd')]) }}" class="btn btn-info mass_reconcile"><i- class="fa fa-fw fa-check"></i> {{ 'reconcile_this_account'|_ }}</a>- {% endif %}- {% endif %}- </div>- </div>-</div>-<div class="row" style="padding:8px;">- <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">- {{ transactions.render|raw }}- </div>-</div>diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.phpindex 49e55b06aa..fbd95e50d4 100644--- a/tests/Api/V1/Controllers/AccountControllerTest.php+++ b/tests/Api/V1/Controllers/AccountControllerTest.php@@ -23,15 +23,15 @@ declare(strict_types=1);namespace Tests\Api\V1\Controllers;-use FireflyIII\Helpers\Collector\TransactionCollectorInterface;+use Exception;+use FireflyIII\Helpers\Collector\GroupCollectorInterface;use FireflyIII\Models\Account;use FireflyIII\Models\PiggyBank;use FireflyIII\Repositories\Account\AccountRepositoryInterface;-use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;use FireflyIII\Transformers\AccountTransformer;use FireflyIII\Transformers\PiggyBankTransformer;-use FireflyIII\Transformers\TransactionTransformer;+use FireflyIII\Transformers\TransactionGroupTransformer;use Illuminate\Pagination\LengthAwarePaginator;use Illuminate\Support\Collection;use Laravel\Passport\Passport;@@ -62,6 +62,8 @@ class AccountControllerTest extends TestCase{// mock stuff:$repository = $this->mock(AccountRepositoryInterface::class);+ $repository->shouldReceive();+// mock calls:$repository->shouldReceive('setUser')->atLeast()->once();$repository->shouldReceive('destroy')->atLeast()->once()->andReturn(true);@@ -189,7 +191,8 @@ class AccountControllerTest extends TestCase* Opening balance without date.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest+ * @throws Exception*/public function testStoreInvalidBalance(): void{@@ -227,7 +230,8 @@ class AccountControllerTest extends TestCase* Send correct data. Should call account repository store method.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest+ * @throws Exception*/public function testStoreLiability(): void{@@ -273,13 +277,12 @@ class AccountControllerTest extends TestCase* CC type present when account is a credit card.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest*/public function testStoreNoCreditCardData(): void{// mock repositories- $repository = $this->mock(AccountRepositoryInterface::class);-+ $repository = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(AccountTransformer::class);// mock calls:@@ -313,13 +316,13 @@ class AccountControllerTest extends TestCase* No currency information (is allowed).** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest+ * @throws Exception*/public function testStoreNoCurrencyInfo(): void{// mock repositories- $repository = $this->mock(AccountRepositoryInterface::class);-+ $repository = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(AccountTransformer::class);// mock calls to transformer:@@ -351,13 +354,12 @@ class AccountControllerTest extends TestCase* Name already in use.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest*/public function testStoreNotUnique(): void{// mock repositories- $repository = $this->mock(AccountRepositoryInterface::class);-+ $repository = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(AccountTransformer::class);// mock calls:@@ -393,13 +395,13 @@ class AccountControllerTest extends TestCase* Send correct data. Should call account repository store method.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest+ * @throws Exception*/public function testStoreValid(): void{// mock repositories- $repository = $this->mock(AccountRepositoryInterface::class);-+ $repository = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(AccountTransformer::class);$account = $this->getRandomAsset();@@ -432,13 +434,13 @@ class AccountControllerTest extends TestCase* Send correct data. Should call account repository store method.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountStoreRequest+ * @throws Exception*/public function testStoreWithCurrencyCode(): void{// mock repositories- $repository = $this->mock(AccountRepositoryInterface::class);-+ $repository = $this->mock(AccountRepositoryInterface::class);$transformer = $this->mock(AccountTransformer::class);$account = $this->getRandomAsset();@@ -470,36 +472,31 @@ class AccountControllerTest extends TestCase}/**- * Show index.+ * Show transactions.** @covers \FireflyIII\Api\V1\Controllers\AccountController*/public function testTransactionsBasic(): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;+ // default mocks$accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $transformer = $this->mock(TransactionTransformer::class);+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);- // default mocks+ // objects+ $paginator = new LengthAwarePaginator(new Collection, 0, 50);++ // calls to account repos.$accountRepos->shouldReceive('setUser')->atLeast()->once();- $accountRepos->shouldReceive('isAsset')->atLeast()->once()->andReturnTrue();// mock collector:- $paginator = new LengthAwarePaginator(new Collection, 0, 50);$collector->shouldReceive('setUser')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();$collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('removeFilter')->andReturnSelf();- $collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('withAPIInformation')->andReturnSelf();+ $collector->shouldReceive('setLimit')->withArgs([50])->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();$collector->shouldReceive('setTypes')->andReturnSelf();- $collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);+ $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);// mock calls to transformer:$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();@@ -515,45 +512,38 @@ class AccountControllerTest extends TestCase}/**- * Show index.+ * Show transactions but submit a limit.** @covers \FireflyIII\Api\V1\Controllers\AccountController*/- public function testTransactionsOpposing(): void+ public function testTransactionsLimit(): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;+ // default mocks$accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $transformer = $this->mock(TransactionTransformer::class);+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);- // default mocks+ // objects+ $paginator = new LengthAwarePaginator(new Collection, 0, 50);++ // calls to account repos.$accountRepos->shouldReceive('setUser')->atLeast()->once();- $accountRepos->shouldReceive('isAsset')->atLeast()->once()->andReturnFalse();// mock collector:- $paginator = new LengthAwarePaginator(new Collection, 0, 50);$collector->shouldReceive('setUser')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();$collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('removeFilter')->andReturnSelf();- $collector->shouldReceive('setOpposingAccounts')->atLeast()->once()->andReturnSelf();-- $collector->shouldReceive('setLimit')->andReturnSelf();+ $collector->shouldReceive('withAPIInformation')->andReturnSelf();+ $collector->shouldReceive('setLimit')->withArgs([10])->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();$collector->shouldReceive('setTypes')->andReturnSelf();- $collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);+ $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);// mock calls to transformer:$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();- $revenue = $this->getRandomAsset();+ $asset = $this->getRandomAsset();// test API- $response = $this->get(route('api.v1.accounts.transactions', [$revenue->id]));+ $response = $this->get(route('api.v1.accounts.transactions', [$asset->id]) . '?limit=10');$response->assertStatus(200);$response->assertJson(['data' => [],]);$response->assertJson(['meta' => ['pagination' => ['total' => 0, 'count' => 0, 'per_page' => 50, 'current_page' => 1, 'total_pages' => 1]],]);@@ -568,31 +558,26 @@ class AccountControllerTest extends TestCase*/public function testTransactionsRange(): void{- $this->markTestIncomplete('Needs to be rewritten for v4.8.0');-- return;+ // default mocks$accountRepos = $this->mock(AccountRepositoryInterface::class);- $journalRepos = $this->mock(JournalRepositoryInterface::class);- $collector = $this->mock(TransactionCollectorInterface::class);- $transformer = $this->mock(TransactionTransformer::class);+ $collector = $this->mock(GroupCollectorInterface::class);+ $transformer = $this->mock(TransactionGroupTransformer::class);- // default mocks+ // objects+ $paginator = new LengthAwarePaginator(new Collection, 0, 50);++ // calls to account repos.$accountRepos->shouldReceive('setUser')->atLeast()->once();- $accountRepos->shouldReceive('isAsset')->atLeast()->once()->andReturnTrue();// mock collector:- $paginator = new LengthAwarePaginator(new Collection, 0, 50);$collector->shouldReceive('setUser')->andReturnSelf();- $collector->shouldReceive('withOpposingAccount')->andReturnSelf();- $collector->shouldReceive('withCategoryInformation')->andReturnSelf();- $collector->shouldReceive('withBudgetInformation')->andReturnSelf();$collector->shouldReceive('setAccounts')->andReturnSelf();- $collector->shouldReceive('removeFilter')->andReturnSelf();+ $collector->shouldReceive('withAPIInformation')->andReturnSelf();$collector->shouldReceive('setLimit')->andReturnSelf();$collector->shouldReceive('setPage')->andReturnSelf();$collector->shouldReceive('setTypes')->andReturnSelf();+ $collector->shouldReceive('getPaginatedGroups')->andReturn($paginator);$collector->shouldReceive('setRange')->andReturnSelf();- $collector->shouldReceive('getPaginatedTransactions')->andReturn($paginator);// mock calls to transformer:$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();@@ -611,7 +596,7 @@ class AccountControllerTest extends TestCase* Update first asset account we find. Name can be the same as it was.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest*/public function testUpdate(): void{@@ -636,9 +621,11 @@ class AccountControllerTest extends TestCase$account = $this->getRandomAsset();// data to submit$data = [- 'name' => $account->name,- 'type' => 'asset',- 'account_role' => 'defaultAsset',+ 'active' => true,+ 'include_net_worth' => true,+ 'name' => $account->name,+ 'type' => 'asset',+ 'account_role' => 'defaultAsset',];// test API@@ -652,7 +639,7 @@ class AccountControllerTest extends TestCase* Update first asset account we find. Name can be the same as it was.** @covers \FireflyIII\Api\V1\Controllers\AccountController- * @covers \FireflyIII\Api\V1\Requests\AccountRequest+ * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest*/public function testUpdateCurrencyCode(): void{@@ -690,5 +677,54 @@ class AccountControllerTest extends TestCase$response->assertHeader('Content-Type', 'application/vnd.api+json');}+ /**+ * Update a liability+ *+ * @covers \FireflyIII\Api\V1\Controllers\AccountController+ * @covers \FireflyIII\Api\V1\Requests\AccountUpdateRequest+ */+ public function testUpdateLiability(): void+ {+ // mock repositories+ $repository = $this->mock(AccountRepositoryInterface::class);++ $transformer = $this->mock(AccountTransformer::class);++ // mock calls:+ $repository->shouldReceive('setUser')->atLeast()->once();++ $repository->shouldReceive('update')->atLeast()->once();++ // mock calls to transformer:+ $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();+ $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();+ $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);+ $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);+ $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);+++ $account = $this->getRandomAsset();+ // data to submit+ $data = [+ 'active' => true,+ 'include_net_worth' => true,+ 'name' => $account->name,+ 'type' => 'liability',+ 'liability_type' => 'loan',+ 'liability_amount' => '100',+ 'interest' => '1',+ 'interest_period' => 'yearly',+ 'liability_start_date' => '2019-01-01',+ 'account_role' => 'defaultAsset',+ ];++ // test API+ $response = $this->put(route('api.v1.accounts.update', [$account->id]), $data, ['Accept' => 'application/json']);+ $response->assertStatus(200);+ $response->assertJson(['data' => ['type' => 'accounts', 'links' => true],]);+ $response->assertHeader('Content-Type', 'application/vnd.api+json');++ }+}diff --git a/tests/Api/V1/Controllers/AttachmentControllerTest.php b/tests/Api/V1/Controllers/AttachmentControllerTest.phpindex 5acea829ec..42aadcd91b 100644--- a/tests/Api/V1/Controllers/AttachmentControllerTest.php+++ b/tests/Api/V1/Controllers/AttachmentControllerTest.php@@ -80,6 +80,9 @@ class AttachmentControllerTest extends TestCase*/public function testDownload(): void{+ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');++ return;// mock stuff:$repository = $this->mock(AttachmentRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);@@ -109,6 +112,9 @@ class AttachmentControllerTest extends TestCase*/public function testDownloadNotExisting(): void{+ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');++ return;// mock stuff:$repository = $this->mock(AttachmentRepositoryInterface::class);$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);diff --git a/tests/Api/V1/Controllers/TagControllerTest.php b/tests/Api/V1/Controllers/TagControllerTest.phpindex 5d47c28bb0..a52b4b4fa7 100644--- a/tests/Api/V1/Controllers/TagControllerTest.php+++ b/tests/Api/V1/Controllers/TagControllerTest.php@@ -79,6 +79,9 @@ class TagControllerTest extends TestCase*/public function testDeleteByTag(): void{+ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');++ return;// mock stuff:$tagRepos = $this->mock(TagRepositoryInterface::class);$tag = $this->user()->tags()->inRandomOrder()->first();@@ -152,6 +155,9 @@ class TagControllerTest extends TestCase*/public function testShowByTag(): void{+ $this->markTestIncomplete('Needs to be rewritten for v4.8.0');++ return;// mock stuff:$tagRepos = $this->mock(TagRepositoryInterface::class);$tag = $this->user()->tags()->inRandomOrder()->first();