Expand test coverage and improve transaction management code.

This commit is contained in:
James Cole
2019-07-01 20:22:35 +02:00
parent 94acb50a6f
commit 5bbe1eab7c
63 changed files with 1251 additions and 812 deletions

View File

@@ -36,7 +36,7 @@ class AccountList implements BinderInterface
/**
* @param string $value
* @param Route $route
* @param Route $route
*
* @return Collection
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@@ -44,25 +44,29 @@ class AccountList implements BinderInterface
*/
public static function routeBinder(string $value, Route $route): Collection
{
Log::debug(sprintf('Now in AccountList::routeBinder("%s")', $value));
if (auth()->check()) {
Log::debug('User is logged in.');
$collection = new Collection;
if ('allAssetAccounts' === $value) {
/** @var \Illuminate\Support\Collection $collection */
/** @var Collection $collection */
$collection = auth()->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->where('account_types.type', AccountType::ASSET)
->orderBy('accounts.name', 'ASC')
->get(['accounts.*']);
Log::debug(sprintf('Collection length is %d', $collection->count()));
}
if ('allAssetAccounts' !== $value) {
$incoming = array_map('\intval', explode(',', $value));
$list = array_merge(array_unique($incoming), [0]);
/** @var \Illuminate\Support\Collection $collection */
/** @var Collection $collection */
$collection = auth()->user()->accounts()
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->whereIn('accounts.id', $list)
->orderBy('accounts.name', 'ASC')
->get(['accounts.*']);
Log::debug(sprintf('Collection length is %d', $collection->count()));
}
if ($collection->count() > 0) {

View File

@@ -25,6 +25,7 @@ namespace FireflyIII\Support\Binder;
use FireflyIII\Models\Budget;
use Illuminate\Routing\Route;
use Illuminate\Support\Collection;
use Log;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@@ -34,7 +35,7 @@ class BudgetList implements BinderInterface
{
/**
* @param string $value
* @param Route $route
* @param Route $route
*
* @return Collection
* @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@@ -42,27 +43,36 @@ class BudgetList implements BinderInterface
*/
public static function routeBinder(string $value, Route $route): Collection
{
Log::debug(sprintf('Now in BudgetList::routeBinder("%s")', $value));
if (auth()->check()) {
$list = array_unique(array_map('\intval', explode(',', $value)));
Log::debug('List is now', $list);
if (0 === count($list)) {
Log::warning('List count is zero, return 404.');
throw new NotFoundHttpException; // @codeCoverageIgnore
}
/** @var \Illuminate\Support\Collection $collection */
/** @var Collection $collection */
$collection = auth()->user()->budgets()
->where('active', 1)
->whereIn('id', $list)
->get();
Log::debug(sprintf('Found %d active budgets', $collection->count()), $list);
// add empty budget if applicable.
if (in_array(0, $list, true)) {
Log::debug('Add empty budget because $list contains 0.');
$collection->push(new Budget);
}
if ($collection->count() > 0) {
Log::debug(sprintf('List length is > 0 (%d), so return it.', $collection->count()));
return $collection;
}
Log::debug('List length is zero, fall back to 404.');
}
Log::debug('Final fallback to 404.');
throw new NotFoundHttpException;
}
}