mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-22 08:56:39 -06:00
Refactor account code and tests.
This commit is contained in:
parent
a95fdb903b
commit
9116796d90
@ -27,7 +27,6 @@ namespace FireflyIII\Http\Controllers\Account;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
@ -70,6 +69,9 @@ class EditController extends Controller
|
||||
* @param AccountRepositoryInterface $repository
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
public function edit(Request $request, Account $account, AccountRepositoryInterface $repository)
|
||||
{
|
||||
@ -87,9 +89,6 @@ class EditController extends Controller
|
||||
}
|
||||
$request->session()->forget('accounts.edit.fromUpdate');
|
||||
|
||||
// pre fill some useful values.
|
||||
|
||||
// the opening balance is tricky:
|
||||
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account);
|
||||
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
|
||||
$default = app('amount')->getDefaultCurrency();
|
||||
@ -110,14 +109,9 @@ class EditController extends Controller
|
||||
'openingBalance' => $openingBalanceAmount,
|
||||
'virtualBalance' => $account->virtual_balance,
|
||||
'currency_id' => $currency->id,
|
||||
'notes' => '',
|
||||
'notes' => $this->repository->getNoteText($account),
|
||||
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active,
|
||||
];
|
||||
/** @var Note $note */
|
||||
$note = $this->repository->getNote($account);
|
||||
if (null !== $note) {
|
||||
$preFilled['notes'] = $note->text;
|
||||
}
|
||||
|
||||
$request->session()->flash('preFilled', $preFilled);
|
||||
|
||||
|
126
app/Http/Controllers/Account/IndexController.php
Normal file
126
app/Http/Controllers/Account/IndexController.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexController.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Preferences;
|
||||
|
||||
/**
|
||||
*
|
||||
* Class IndexController
|
||||
*/
|
||||
class IndexController extends Controller
|
||||
{
|
||||
/** @var AccountRepositoryInterface */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// translations:
|
||||
$this->middleware(
|
||||
function ($request, $next) {
|
||||
app('view')->share('mainTitleIcon', 'fa-credit-card');
|
||||
app('view')->share('title', trans('firefly.accounts'));
|
||||
|
||||
$this->repository = app(AccountRepositoryInterface::class);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(Request $request, string $what)
|
||||
{
|
||||
$what = $what ?? 'asset';
|
||||
$subTitle = trans('firefly.' . $what . '_accounts');
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = config('firefly.accountTypesByIdentifier.' . $what);
|
||||
$collection = $this->repository->getAccountsByType($types);
|
||||
$total = $collection->count();
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
|
||||
unset($collection);
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$startBalances = app('steam')->balancesByAccounts($accounts, $start);
|
||||
$endBalances = app('steam')->balancesByAccounts($accounts, $end);
|
||||
$activities = app('steam')->getLastActivities($ids);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||
}
|
||||
);
|
||||
|
||||
// make paginator:
|
||||
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
|
||||
$accounts->setPath(route('accounts.index', [$what]));
|
||||
|
||||
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, int $entryId)
|
||||
{
|
||||
$result = '0';
|
||||
if (isset($array[$entryId])) {
|
||||
$result = $array[$entryId];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountController.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* ShowController.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
@ -18,16 +18,15 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers;
|
||||
namespace FireflyIII\Http\Controllers\Account;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use ExpandedForm;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Http\Requests\AccountFormRequest;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Transaction;
|
||||
@ -36,16 +35,15 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\CacheProperties;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use View;
|
||||
|
||||
/**
|
||||
* Class AccountController.
|
||||
*
|
||||
* Class ShowController
|
||||
*/
|
||||
class AccountController extends Controller
|
||||
class ShowController extends Controller
|
||||
{
|
||||
/** @var CurrencyRepositoryInterface */
|
||||
private $currencyRepos;
|
||||
@ -73,53 +71,6 @@ class AccountController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @param string $what
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function index(Request $request, string $what)
|
||||
{
|
||||
$what = $what ?? 'asset';
|
||||
$subTitle = trans('firefly.' . $what . '_accounts');
|
||||
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
|
||||
$types = config('firefly.accountTypesByIdentifier.' . $what);
|
||||
$collection = $this->repository->getAccountsByType($types);
|
||||
$total = $collection->count();
|
||||
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
|
||||
$pageSize = (int)Preferences::get('listPageSize', 50)->data;
|
||||
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
|
||||
unset($collection);
|
||||
/** @var Carbon $start */
|
||||
$start = clone session('start', Carbon::now()->startOfMonth());
|
||||
/** @var Carbon $end */
|
||||
$end = clone session('end', Carbon::now()->endOfMonth());
|
||||
$start->subDay();
|
||||
|
||||
$ids = $accounts->pluck('id')->toArray();
|
||||
$startBalances = app('steam')->balancesByAccounts($accounts, $start);
|
||||
$endBalances = app('steam')->balancesByAccounts($accounts, $end);
|
||||
$activities = app('steam')->getLastActivities($ids);
|
||||
|
||||
$accounts->each(
|
||||
function (Account $account) use ($activities, $startBalances, $endBalances) {
|
||||
$account->lastActivityDate = $this->isInArray($activities, $account->id);
|
||||
$account->startBalance = $this->isInArray($startBalances, $account->id);
|
||||
$account->endBalance = $this->isInArray($endBalances, $account->id);
|
||||
$account->difference = bcsub($account->endBalance, $account->startBalance);
|
||||
}
|
||||
);
|
||||
|
||||
// make paginator:
|
||||
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
|
||||
$accounts->setPath(route('accounts.index', [$what]));
|
||||
|
||||
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
|
||||
}
|
||||
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
/**
|
||||
* Show an account.
|
||||
*
|
||||
@ -138,17 +89,12 @@ class AccountController extends Controller
|
||||
if (AccountType::INITIAL_BALANCE === $account->accountType->type) {
|
||||
return $this->redirectToOriginalAccount($account);
|
||||
}
|
||||
if (null === $start) {
|
||||
$start = session('start');
|
||||
}
|
||||
if (null === $end) {
|
||||
$end = session('end');
|
||||
}
|
||||
$start = $start ?? session('start');
|
||||
$end = $end ?? session('end');
|
||||
if ($end < $start) {
|
||||
throw new FireflyException('End is after start!'); // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
|
||||
$what = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); // used for menu
|
||||
$today = new Carbon;
|
||||
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
|
||||
@ -178,7 +124,6 @@ class AccountController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show an account.
|
||||
*
|
||||
@ -222,22 +167,9 @@ class AccountController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $array
|
||||
* @param int $entryId
|
||||
*
|
||||
* @return null|mixed
|
||||
*/
|
||||
protected function isInArray(array $array, int $entryId)
|
||||
{
|
||||
$result = '0';
|
||||
if (isset($array[$entryId])) {
|
||||
$result = $array[$entryId];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/** @noinspection MoreThanThreeArgumentsInspection */
|
||||
|
||||
/**
|
||||
* This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range)
|
||||
@ -250,6 +182,7 @@ class AccountController extends Controller
|
||||
*
|
||||
* @return Collection
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
private function getPeriodOverview(Account $account, ?Carbon $date): Collection
|
||||
{
|
||||
@ -332,4 +265,4 @@ class AccountController extends Controller
|
||||
|
||||
return redirect(route('accounts.show', [$opposingTransaction->account_id]));
|
||||
}
|
||||
}
|
||||
}
|
@ -42,7 +42,7 @@ class TwoFactorController extends Controller
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Illuminate\View\View
|
||||
*
|
||||
* @throws FireflyException
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
@ -108,8 +108,9 @@ Route::group(
|
||||
*/
|
||||
Route::group(
|
||||
['middleware' => 'user-full-auth', 'namespace' => 'FireflyIII\Http\Controllers', 'prefix' => 'accounts', 'as' => 'accounts.'], function () {
|
||||
Route::get('{what}', ['uses' => 'AccountController@index', 'as' => 'index'])->where('what', 'revenue|asset|expense');
|
||||
|
||||
// show:
|
||||
Route::get('{what}', ['uses' => 'Account\IndexController@index', 'as' => 'index'])->where('what', 'revenue|asset|expense');
|
||||
|
||||
// create
|
||||
Route::get('create/{what}', ['uses' => 'Account\CreateController@create', 'as' => 'create'])->where('what', 'revenue|asset|expense');
|
||||
@ -125,8 +126,8 @@ Route::group(
|
||||
Route::post('destroy/{account}', ['uses' => 'Account\DeleteController@destroy', 'as' => 'destroy']);
|
||||
|
||||
// show
|
||||
Route::get('show/{account}/all', ['uses' => 'AccountController@showAll', 'as' => 'show.all']);
|
||||
Route::get('show/{account}/{start_date?}/{end_date?}', ['uses' => 'AccountController@show', 'as' => 'show']);
|
||||
Route::get('show/{account}/all', ['uses' => 'Account\ShowController@showAll', 'as' => 'show.all']);
|
||||
Route::get('show/{account}/{start_date?}/{end_date?}', ['uses' => 'Account\ShowController@show', 'as' => 'show']);
|
||||
|
||||
// reconcile routes:
|
||||
Route::get('reconcile/{account}/index/{start_date?}/{end_date?}', ['uses' => 'Account\ReconcileController@reconcile', 'as' => 'reconcile']);
|
||||
|
@ -31,13 +31,21 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
use Log;
|
||||
/**
|
||||
*
|
||||
* Class DeleteControllerTest
|
||||
*/
|
||||
class DeleteControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\DeleteController
|
||||
* @covers \FireflyIII\Http\Controllers\Controller
|
||||
|
@ -34,22 +34,26 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Mockery;
|
||||
use Tests\TestCase;
|
||||
|
||||
use Log;
|
||||
/**
|
||||
*
|
||||
* Class EditControllerTest
|
||||
*/
|
||||
class EditControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\EditController
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
@ -57,7 +61,7 @@ class EditControllerTest extends TestCase
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(TransactionCurrency::find(1));
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$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');
|
||||
@ -73,7 +77,7 @@ class EditControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
$response->assertSee('Some text');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,8 +85,6 @@ class EditControllerTest extends TestCase
|
||||
*/
|
||||
public function testEditNull(): void
|
||||
{
|
||||
$note = new Note();
|
||||
$note->text = 'This is a test';
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
@ -92,7 +94,7 @@ class EditControllerTest extends TestCase
|
||||
$repository->shouldReceive('findNull')->once()->andReturn(null);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getNote')->andReturn($note)->once();
|
||||
$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');
|
||||
@ -108,7 +110,7 @@ class EditControllerTest extends TestCase
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
$response->assertSee($note->text);
|
||||
$response->assertSee('Some text');
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +159,7 @@ class EditControllerTest extends TestCase
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
'name' => 'updated account ' . random_int(1000, 9999),
|
||||
'active' => 1,ss
|
||||
'active' => 1,
|
||||
'what' => 'asset',
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
|
86
tests/Feature/Controllers/Account/IndexControllerTest.php
Normal file
86
tests/Feature/Controllers/Account/IndexControllerTest.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* IndexControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* 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 Tests\Feature\Controllers\Account;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Steam;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IndexControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class IndexControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Account\IndexController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
*/
|
||||
public function testIndex(string $range): void
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
|
||||
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
|
||||
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
||||
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('accounts.index', ['asset']));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ class ReconcileControllerTest extends TestCase
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/**
|
||||
* AccountControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
* ShowControllerTest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
@ -18,16 +18,13 @@
|
||||
* 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 Tests\Feature\Controllers;
|
||||
namespace Tests\Feature\Controllers\Account;
|
||||
|
||||
use Amount;
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@ -38,67 +35,26 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Steam;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AccountControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* Class ShowControllerTest
|
||||
*/
|
||||
class AccountControllerTest extends TestCase
|
||||
class ShowControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::index
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::isInArray
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
*
|
||||
*/
|
||||
public function testIndex(string $range): void
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
|
||||
Steam::shouldReceive('balancesByAccounts')->andReturn([$account->id => '100']);
|
||||
Steam::shouldReceive('getLastActivities')->andReturn([]);
|
||||
|
||||
$repository->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'accountNumber'])->andReturn('123');
|
||||
|
||||
$this->be($this->user());
|
||||
$this->changeDateRange($this->user(), $range);
|
||||
$response = $this->get(route('accounts.index', ['asset']));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::getPeriodOverview
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
@ -145,8 +101,7 @@ class AccountControllerTest extends TestCase
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
@ -192,7 +147,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
* @expectedExceptionMessage End is after start!
|
||||
*/
|
||||
public function testShowBrokenBadDates(): void
|
||||
@ -210,8 +165,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::redirectToOriginalAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
* @expectedExceptionMessage Expected a transaction
|
||||
*/
|
||||
public function testShowBrokenInitial(): void
|
||||
@ -230,7 +184,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
* @dataProvider dateRangeProvider
|
||||
*
|
||||
* @param string $range
|
||||
@ -267,8 +221,7 @@ class AccountControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::show
|
||||
* @covers \FireflyIII\Http\Controllers\AccountController::redirectToOriginalAccount
|
||||
* @covers \FireflyIII\Http\Controllers\Account\ShowController
|
||||
*/
|
||||
public function testShowInitial(): void
|
||||
{
|
||||
@ -286,4 +239,4 @@ class AccountControllerTest extends TestCase
|
||||
$response->assertStatus(302);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user