Refactor some code for recurrences.

This commit is contained in:
James Cole
2019-06-08 06:19:21 +02:00
parent 7c2c24d330
commit 85f9c256a1
21 changed files with 369 additions and 468 deletions

View File

@@ -184,7 +184,6 @@ class AccountController extends Controller
* @param Request $request * @param Request $request
* @param Account $account * @param Account $account
* *
* @codeCoverageIgnore
* @return JsonResponse * @return JsonResponse
*/ */
public function show(Request $request, Account $account): JsonResponse public function show(Request $request, Account $account): JsonResponse

View File

@@ -162,7 +162,6 @@ class AttachmentController extends Controller
* *
* @param Request $request * @param Request $request
* @param Attachment $attachment * @param Attachment $attachment
* @codeCoverageIgnore
* @return JsonResponse * @return JsonResponse
*/ */
public function show(Request $request, Attachment $attachment): JsonResponse public function show(Request $request, Attachment $attachment): JsonResponse

View File

@@ -41,7 +41,8 @@ class Request extends FireflyIIIRequest
/** /**
* @return array * @return array
*/ */
public function getAllAccountData(): array { public function getAllAccountData(): array
{
$active = true; $active = true;
$includeNetWorth = true; $includeNetWorth = true;
if (null !== $this->get('active')) { if (null !== $this->get('active')) {
@@ -194,7 +195,8 @@ class Request extends FireflyIIIRequest
* *
* @return array * @return array
*/ */
protected function getRecurrenceTransactionData(): array { protected function getRecurrenceTransactionData(): array
{
$return = []; $return = [];
// transaction data: // transaction data:
/** @var array $transactions */ /** @var array $transactions */
@@ -217,6 +219,7 @@ class Request extends FireflyIIIRequest
'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null, 'destination_id' => isset($transaction['destination_id']) ? (int)$transaction['destination_id'] : null,
'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null, 'destination_name' => isset($transaction['destination_name']) ? (string)$transaction['destination_name'] : null,
'description' => $transaction['description'], 'description' => $transaction['description'],
'type' => $this->string('type'),
]; ];
} }

View File

@@ -112,7 +112,7 @@ class AccountFactory
$data['currency_id'] = $currency->id; $data['currency_id'] = $currency->id;
// remove virtual balance when not an asset account or a liability // remove virtual balance when not an asset account or a liability
$canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD]; $canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];
if (!\in_array($type->type, $canHaveVirtual, true)) { if (!in_array($type->type, $canHaveVirtual, true)) {
$databaseData['virtual_balance'] = '0'; $databaseData['virtual_balance'] = '0';
} }
@@ -124,7 +124,7 @@ class AccountFactory
$return = Account::create($databaseData); $return = Account::create($databaseData);
$this->updateMetaData($return, $data); $this->updateMetaData($return, $data);
if (\in_array($type->type, $canHaveVirtual, true)) { if (in_array($type->type, $canHaveVirtual, true)) {
if ($this->validIBData($data)) { if ($this->validIBData($data)) {
$this->updateIB($return, $data); $this->updateIB($return, $data);
} }

View File

@@ -93,7 +93,7 @@ class BillFactory
} }
/** /**
* @param int|null $billId * @param int|null $billId
* @param null|string $billName * @param null|string $billName
* *
* @return Bill|null * @return Bill|null
@@ -126,8 +126,10 @@ class BillFactory
public function findByName(string $name): ?Bill public function findByName(string $name): ?Bill
{ {
$query = sprintf('%%%s%%', $name); $query = sprintf('%%%s%%', $name);
/** @var Bill $first */
$first = $this->user->bills()->where('name', 'LIKE', $query)->first();
return $this->user->bills()->where('name', 'LIKE', $query)->first(); return $first;
} }
/** /**

View File

@@ -246,6 +246,10 @@ class TransactionJournalFactory
$destinationAccount = $this->getAccount($type->type, 'destination', (int)$row['destination_id'], $row['destination_name']); $destinationAccount = $this->getAccount($type->type, 'destination', (int)$row['destination_id'], $row['destination_name']);
/** double check currencies. */ /** double check currencies. */
$sourceCurrency = $currency;
$destCurrency = $currency;
$sourceForeignCurrency = $foreignCurrency;
$destForeignCurrency = $foreignCurrency;
if ($type->type === 'Withdrawal') { if ($type->type === 'Withdrawal') {
// make sure currency is correct. // make sure currency is correct.

View File

@@ -61,7 +61,7 @@ class ChartJsGenerator implements GeneratorInterface
$amounts = array_column($data, 'amount'); $amounts = array_column($data, 'amount');
$next = next($amounts); $next = next($amounts);
$sortFlag = SORT_ASC; $sortFlag = SORT_ASC;
if (!\is_bool($next) && 1 === bccomp((string)$next, '0')) { if (!is_bool($next) && 1 === bccomp((string)$next, '0')) {
$sortFlag = SORT_DESC; $sortFlag = SORT_DESC;
} }
array_multisort($amounts, $sortFlag, $data); array_multisort($amounts, $sortFlag, $data);
@@ -118,7 +118,7 @@ class ChartJsGenerator implements GeneratorInterface
{ {
reset($data); reset($data);
$first = current($data); $first = current($data);
$labels = \is_array($first['entries']) ? array_keys($first['entries']) : []; $labels = is_array($first['entries']) ? array_keys($first['entries']) : [];
$chartData = [ $chartData = [
'count' => count($data), 'count' => count($data),
@@ -173,7 +173,7 @@ class ChartJsGenerator implements GeneratorInterface
// different sort when values are positive and when they're negative. // different sort when values are positive and when they're negative.
asort($data); asort($data);
$next = next($data); $next = next($data);
if (!\is_bool($next) && 1 === bccomp((string)$next, '0')) { if (!is_bool($next) && 1 === bccomp((string)$next, '0')) {
// next is positive, sort other way around. // next is positive, sort other way around.
arsort($data); arsort($data);
} }

View File

@@ -29,7 +29,6 @@ use Carbon\Carbon;
use FireflyIII\Generator\Report\ReportGeneratorInterface; use FireflyIII\Generator\Report\ReportGeneratorInterface;
use FireflyIII\Generator\Report\Support; use FireflyIII\Generator\Report\Support;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
@@ -101,82 +100,6 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
return $result; return $result;
} }
/**
* Get expense collection for report.
*
* @return array
*/
protected function getExpenses(): array
{
if (count($this->expenses) > 0) {
Log::debug('Return previous set of expenses.');
return $this->expenses;
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setTags($this->tags)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$this->expenses = $journals;
return $journals;
}
/**
* Get the income for this report.
*
* @return array
*/
protected function getIncome(): array
{
if (count($this->income) > 0) {
return $this->income;
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setTags($this->tags)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$this->income = $journals;
return $journals;
}
/**
* Summarize by tag.
*
* @param array $array
*
* @return array
*/
protected function summarizeByTag(array $array): array
{
$tagIds = array_map('\intval', $this->tags->pluck('id')->toArray());
$result = [];
/** @var array $journal */
foreach ($array as $journal) {
/**
* @var int $id
* @var array $tag
*/
foreach ($journal['tags'] as $id => $tag) {
if (in_array($id, $tagIds, true)) {
$result[$id] = $result[$id] ?? '0';
$result[$id] = bcadd($journal['amount'], $result[$id]);
}
}
}
return $result;
}
/** /**
* Set the accounts. * Set the accounts.
* *
@@ -268,4 +191,80 @@ class MonthReportGenerator extends Support implements ReportGeneratorInterface
return $this; return $this;
} }
/**
* Get expense collection for report.
*
* @return array
*/
protected function getExpenses(): array
{
if (count($this->expenses) > 0) {
Log::debug('Return previous set of expenses.');
return $this->expenses;
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::WITHDRAWAL, TransactionType::TRANSFER])
->setTags($this->tags)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$this->expenses = $journals;
return $journals;
}
/**
* Get the income for this report.
*
* @return array
*/
protected function getIncome(): array
{
if (count($this->income) > 0) {
return $this->income;
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts($this->accounts)->setRange($this->start, $this->end)
->setTypes([TransactionType::DEPOSIT, TransactionType::TRANSFER])
->setTags($this->tags)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$this->income = $journals;
return $journals;
}
/**
* Summarize by tag.
*
* @param array $array
*
* @return array
*/
protected function summarizeByTag(array $array): array
{
$tagIds = array_map('\intval', $this->tags->pluck('id')->toArray());
$result = [];
/** @var array $journal */
foreach ($array as $journal) {
/**
* @var int $id
* @var array $tag
*/
foreach ($journal['tags'] as $id => $tag) {
if (in_array($id, $tagIds, true)) {
$result[$id] = $result[$id] ?? '0';
$result[$id] = bcadd($journal['amount'], $result[$id]);
}
}
}
return $result;
}
} }

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events; namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\StoredTransactionGroup; use FireflyIII\Events\StoredTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
@@ -39,7 +40,7 @@ class StoredGroupEventHandler
* @param StoredTransactionGroup $storedJournalEvent * @param StoredTransactionGroup $storedJournalEvent
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException * @throws FireflyException
*/ */
public function processRules(StoredTransactionGroup $storedJournalEvent): bool public function processRules(StoredTransactionGroup $storedJournalEvent): bool
{ {
@@ -47,6 +48,7 @@ class StoredGroupEventHandler
if(false === $storedJournalEvent->applyRules) { if(false === $storedJournalEvent->applyRules) {
return true; return true;
} }
// TODO fix this
die('cannot apply rules yet'); die('cannot apply rules yet');
// create objects: // create objects:
/** @var RuleGroupRepositoryInterface $ruleGroupRepos */ /** @var RuleGroupRepositoryInterface $ruleGroupRepos */

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events; namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\UpdatedTransactionGroup; use FireflyIII\Events\UpdatedTransactionGroup;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface; use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
@@ -39,13 +40,14 @@ class UpdatedGroupEventHandler
* @param UpdatedTransactionGroup $updatedJournalEvent * @param UpdatedTransactionGroup $updatedJournalEvent
* *
* @return bool * @return bool
* @throws \FireflyIII\Exceptions\FireflyException * @throws FireflyException
*/ */
public function processRules(UpdatedTransactionGroup $updatedJournalEvent): bool public function processRules(UpdatedTransactionGroup $updatedJournalEvent): bool
{ {
// get all the user's rule groups, with the rules, order by 'order'. // get all the user's rule groups, with the rules, order by 'order'.
$journals = $updatedJournalEvent->transactionGroup->transactionJournals; $journals = $updatedJournalEvent->transactionGroup->transactionJournals;
// TODO fix this
die('cannot apply rules yet');
/** @var RuleGroupRepositoryInterface $ruleGroupRepos */ /** @var RuleGroupRepositoryInterface $ruleGroupRepos */
$ruleGroupRepos = app(RuleGroupRepositoryInterface::class); $ruleGroupRepos = app(RuleGroupRepositoryInterface::class);

View File

@@ -25,7 +25,6 @@ declare(strict_types=1);
namespace FireflyIII\Handlers\Events; namespace FireflyIII\Handlers\Events;
use FireflyConfig;
use FireflyIII\Events\RequestedVersionCheckStatus; use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Helpers\Update\UpdateTrait; use FireflyIII\Helpers\Update\UpdateTrait;
use FireflyIII\Models\Configuration; use FireflyIII\Models\Configuration;
@@ -71,7 +70,7 @@ class VersionCheckEventHandler
} }
/** @var Configuration $lastCheckTime */ /** @var Configuration $lastCheckTime */
$lastCheckTime = FireflyConfig::get('last_update_check', time()); $lastCheckTime = app('fireflyconfig')->get('last_update_check', time());
$now = time(); $now = time();
$diff = $now - $lastCheckTime->data; $diff = $now - $lastCheckTime->data;
Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff)); Log::debug(sprintf('Last check time is %d, current time is %d, difference is %d', $lastCheckTime->data, $now, $diff));
@@ -90,6 +89,6 @@ class VersionCheckEventHandler
// flash info // flash info
session()->flash('info', $resultString); session()->flash('info', $resultString);
} }
FireflyConfig::set('last_update_check', time()); app('fireflyconfig')->set('last_update_check', time());
} }
} }

View File

@@ -66,7 +66,6 @@ trait BillServiceTrait
* @param string $note * @param string $note
* *
* @return bool * @return bool
* @throws \Exception
*/ */
public function updateNote(Bill $bill, string $note): bool public function updateNote(Bill $bill, string $note): bool
{ {

View File

@@ -57,7 +57,7 @@ trait RecurringTransactionTrait
[ [
'recurrence_id' => $recurrence->id, 'recurrence_id' => $recurrence->id,
'repetition_type' => $array['type'], 'repetition_type' => $array['type'],
'repetition_moment' => $array['moment'], 'repetition_moment' => $array['moment'] ?? '',
'repetition_skip' => $array['skip'], 'repetition_skip' => $array['skip'],
'weekend' => $array['weekend'] ?? 1, 'weekend' => $array['weekend'] ?? 1,
] ]

View File

@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Support; namespace FireflyIII\Services\Internal\Support;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory; use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\TransactionCurrencyFactory; use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
@@ -75,11 +76,12 @@ trait TransactionServiceTrait
/** /**
* @param string|null $expectedType * @param string|null $expectedType
* @param int|null $accountId * @param Account|null $account
* @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return Account|null * @return Account|null
* @throws \FireflyIII\Exceptions\FireflyException * @throws FireflyException
* @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
public function findAccount(?string $expectedType, ?Account $account, ?int $accountId, ?string $accountName): ?Account public function findAccount(?string $expectedType, ?Account $account, ?int $accountId, ?string $accountName): ?Account

View File

@@ -130,7 +130,7 @@ class AccountValidator
} }
/** /**
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return bool * @return bool
@@ -195,19 +195,23 @@ class AccountValidator
*/ */
private function canCreateTypes(array $accountTypes): bool private function canCreateTypes(array $accountTypes): bool
{ {
Log::debug('Can we create any of these types?', $accountTypes);
/** @var string $accountType */ /** @var string $accountType */
foreach ($accountTypes as $accountType) { foreach ($accountTypes as $accountType) {
if ($this->canCreateType($accountType)) { if ($this->canCreateType($accountType)) {
Log::debug(sprintf('YES, we can create a %s', $accountType));
return true; return true;
} }
} }
Log::debug('NO, we cant create any of those.');
return false; return false;
} }
/** /**
* @param array $validTypes * @param array $validTypes
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return Account|null * @return Account|null
@@ -282,7 +286,7 @@ class AccountValidator
} }
/** /**
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return bool * @return bool
@@ -360,7 +364,7 @@ class AccountValidator
} }
/** /**
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return bool * @return bool
@@ -391,7 +395,7 @@ class AccountValidator
} }
/** /**
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return bool * @return bool
@@ -409,6 +413,20 @@ class AccountValidator
return false; return false;
} }
// if there's an ID it must be of the "validTypes".
if (null !== $accountId && 0 !== $accountId) {
$found = $this->accountRepository->findNull($accountId);
if (null !== $found) {
$type = $found->accountType->type;
if (in_array($type, $validTypes)) {
return true;
}
$this->destError = (string)trans('validation.withdrawal_dest_bad_data', ['id' => $accountId, 'name' => $accountName]);
return false;
}
}
// if the account can be created anyway don't need to search. // if the account can be created anyway don't need to search.
if (true === $this->canCreateTypes($validTypes)) { if (true === $this->canCreateTypes($validTypes)) {
@@ -420,7 +438,7 @@ class AccountValidator
} }
/** /**
* @param int|null $accountId * @param int|null $accountId
* @param string|null $accountName * @param string|null $accountName
* *
* @return bool * @return bool

View File

@@ -26,8 +26,8 @@ namespace FireflyIII\Validation;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Illuminate\Validation\Validator; use Illuminate\Validation\Validator;
use Log;
/** /**
* Trait TransactionValidation * Trait TransactionValidation
@@ -41,15 +41,16 @@ trait TransactionValidation
*/ */
public function validateAccountInformation(Validator $validator): void public function validateAccountInformation(Validator $validator): void
{ {
$data = $validator->getData(); Log::debug('Now in validateAccountInformation()');
$transactions = $data['transactions'] ?? []; $data = $validator->getData();
$transactionType = $data['type'] ?? 'invalid';
$transactions = $data['transactions'] ?? [];
/** @var AccountValidator $accountValidator */ /** @var AccountValidator $accountValidator */
$accountValidator = app(AccountValidator::class); $accountValidator = app(AccountValidator::class);
Log::debug(sprintf('Going to loop %d transaction(s)', count($transactions)));
foreach ($transactions as $index => $transaction) { foreach ($transactions as $index => $transaction) {
$transactionType = $transaction['type'] ?? 'invalid';
$accountValidator->setTransactionType($transactionType); $accountValidator->setTransactionType($transactionType);
// validate source account. // validate source account.
@@ -224,7 +225,7 @@ trait TransactionValidation
foreach ($transactions as $index => $transaction) { foreach ($transactions as $index => $transaction) {
$originalType = $this->getOriginalType($transaction['transaction_journal_id'] ?? 0); $originalType = $this->getOriginalType($transaction['transaction_journal_id'] ?? 0);
$originalData = $this->getOriginalData($transaction['transaction_journal_id'] ?? 0); $originalData = $this->getOriginalData($transaction['transaction_journal_id'] ?? 0);
$transactionType = $transaction['type'] ?? $originalType; $transactionType = $transaction['type'] ?? $originalType;
$accountValidator->setTransactionType($transactionType); $accountValidator->setTransactionType($transactionType);

View File

@@ -87,7 +87,6 @@ return [
FireflyIII\Providers\BudgetServiceProvider::class, FireflyIII\Providers\BudgetServiceProvider::class,
FireflyIII\Providers\CategoryServiceProvider::class, FireflyIII\Providers\CategoryServiceProvider::class,
FireflyIII\Providers\CurrencyServiceProvider::class, FireflyIII\Providers\CurrencyServiceProvider::class,
FireflyIII\Providers\ExportJobServiceProvider::class,
FireflyIII\Providers\FireflyServiceProvider::class, FireflyIII\Providers\FireflyServiceProvider::class,
FireflyIII\Providers\JournalServiceProvider::class, FireflyIII\Providers\JournalServiceProvider::class,
FireflyIII\Providers\PiggyBankServiceProvider::class, FireflyIII\Providers\PiggyBankServiceProvider::class,

View File

@@ -173,6 +173,7 @@ return [
'withdrawal_source_need_data' => 'Need to get a valid source account ID and/or valid source account name to continue.', 'withdrawal_source_need_data' => 'Need to get a valid source account ID and/or valid source account name to continue.',
'withdrawal_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".', 'withdrawal_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".',
'withdrawal_dest_need_data' => 'Need to get a valid destination account ID and/or valid destination account name to continue.', 'withdrawal_dest_need_data' => 'Need to get a valid destination account ID and/or valid destination account name to continue.',
'withdrawal_dest_bad_data' => 'Could not find a valid destination account when searching for ID ":id" or name ":name".',
'deposit_source_need_data' => 'Need to get a valid source account ID and/or valid source account name to continue.', 'deposit_source_need_data' => 'Need to get a valid source account ID and/or valid source account name to continue.',
'deposit_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".', 'deposit_source_bad_data' => 'Could not find a valid source account when searching for ID ":id" or name ":name".',

View File

@@ -57,11 +57,9 @@ class AccountControllerTest extends TestCase
// mock repositories // mock repositories
$repository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(AccountRepositoryInterface::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser')->atLeast()->once(); $repository->shouldReceive('setUser')->atLeast()->once();
// data to submit // data to submit
$data = [ $data = [
'name' => 'Some new asset account #' . random_int(1, 10000), 'name' => 'Some new asset account #' . random_int(1, 10000),
@@ -84,6 +82,36 @@ class AccountControllerTest extends TestCase
$response->assertHeader('Content-Type', 'application/json'); $response->assertHeader('Content-Type', 'application/json');
} }
/**
* @covers \FireflyIII\Api\V1\Controllers\AccountController
*/
public function testShow(): void
{
// mock repositories
$repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class);
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 1,
'attributes' => [
'name' => 'Account'
]
]);
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
$transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
// getAccountType
$account = $this->getRandomAsset();
$response = $this->get(route('api.v1.accounts.show', [$account->id]));
$response->assertStatus(200);
}
/** /**
* Send correct data. Should call account repository store method. * Send correct data. Should call account repository store method.
* *
@@ -214,7 +242,7 @@ class AccountControllerTest extends TestCase
public function testStoreNotUnique(): void public function testStoreNotUnique(): void
{ {
// mock repositories // mock repositories
$repository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(AccountRepositoryInterface::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser')->atLeast()->once(); $repository->shouldReceive('setUser')->atLeast()->once();
@@ -331,7 +359,7 @@ class AccountControllerTest extends TestCase
public function testUpdate(): void public function testUpdate(): void
{ {
// mock repositories // mock repositories
$repository = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(AccountRepositoryInterface::class);
$transformer = $this->mock(AccountTransformer::class); $transformer = $this->mock(AccountTransformer::class);
// mock calls: // mock calls:

View File

@@ -48,6 +48,35 @@ class AttachmentControllerTest extends TestCase
Log::info(sprintf('Now in %s.', get_class($this))); Log::info(sprintf('Now in %s.', get_class($this)));
} }
/**
* Test show attachment.
* @covers \FireflyIII\Api\V1\Controllers\AttachmentController
*/
public function testShow(): void
{
$transformer = $this->mock(AttachmentTransformer::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('setUser')->atLeast()->once();
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 1,
'attributes' => [
'file' => 'Test.pdf',
],
]);
$transformer->shouldReceive('setCurrentScope')->atLeast()->once();
$transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);
$attachment = $this->user()->attachments()->inRandomOrder()->first();
// test API
$response = $this->get(route('api.v1.attachments.show', [$attachment->id]));
$response->assertStatus(200);
}
/** /**
* Store a new attachment. * Store a new attachment.
* *

View File

@@ -24,20 +24,15 @@ declare(strict_types=1);
namespace Tests\Api\V1\Controllers; namespace Tests\Api\V1\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\CategoryFactory; use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface; use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use FireflyIII\Transformers\RecurrenceTransformer; use FireflyIII\Transformers\RecurrenceTransformer;
use FireflyIII\Transformers\TransactionTransformer; use FireflyIII\Validation\AccountValidator;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Laravel\Passport\Passport; use Laravel\Passport\Passport;
use Log; use Log;
@@ -68,20 +63,12 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreAssetId(): void public function testStoreAssetId(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0'); // get a recurrence:
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
$repository = $this->mock(RecurringRepositoryInterface::class);
// mock stuff: $transformer = $this->mock(RecurrenceTransformer::class);
$repository = $this->mock(RecurringRepositoryInterface::class); $validator = $this->mock(AccountValidator::class);
$factory = $this->mock(CategoryFactory::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -90,28 +77,15 @@ class RecurrenceControllerTest extends TestCase
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]); $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
// mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
->andReturn(new Collection([$assetAccount]));
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
$firstDate->addDays(2); $firstDate->addDays(2);
@@ -142,8 +116,8 @@ class RecurrenceControllerTest extends TestCase
// test API // test API
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']); $response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
$response->assertStatus(200); $response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/vnd.api+json');
} }
/** /**
@@ -154,19 +128,13 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreAssetName(): void public function testStoreAssetName(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $transformer = $this->mock(RecurrenceTransformer::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $validator = $this->mock(AccountValidator::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -175,30 +143,15 @@ class RecurrenceControllerTest extends TestCase
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]); $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); // mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, 'Checking Account'])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[0]])->once()->andReturn(new Collection);
// used by the validator to find the source_name:
$accountRepos->shouldReceive('findByName')->withArgs(['Checking Account', [AccountType::ASSET]])->once()->andReturn($assetAccount);
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
$firstDate->addDays(2); $firstDate->addDays(2);
@@ -230,7 +183,6 @@ class RecurrenceControllerTest extends TestCase
// test API // test API
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']); $response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
$response->assertStatus(200); $response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/vnd.api+json'); $response->assertHeader('Content-Type', 'application/vnd.api+json');
} }
@@ -242,20 +194,13 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreDeposit(): void public function testStoreDeposit(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $transformer = $this->mock(RecurrenceTransformer::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $validator = $this->mock(AccountValidator::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -265,27 +210,13 @@ class RecurrenceControllerTest extends TestCase
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
// mock calls to validator:
// used by the validator to find the source_id: $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Some expense account'])->andReturn(true);
->andReturn(new Collection([$assetAccount])); $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([1, null])->andReturn(true);
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -331,19 +262,14 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreDestinationId(): void public function testStoreDestinationId(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $transformer = $this->mock(RecurrenceTransformer::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $validator = $this->mock(AccountValidator::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $expenseAccount = $this->getRandomExpense();
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -352,33 +278,14 @@ class RecurrenceControllerTest extends TestCase
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]); $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
$expenseAccount = $this->user()->accounts()->where('account_type_id', 4)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
// used by the validator to find the source_id: // mock calls to validator:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
->andReturn(new Collection([$assetAccount])); $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$expenseAccount->id]])->once() $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$expenseAccount->id, null])->andReturn(true);
->andReturn(new Collection([$expenseAccount]));
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -424,19 +331,13 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreDestinationName(): void public function testStoreDestinationName(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $transformer = $this->mock(RecurrenceTransformer::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $validator = $this->mock(AccountValidator::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -445,31 +346,17 @@ class RecurrenceControllerTest extends TestCase
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]); $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]); $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $expenseAccount = $this->getRandomExpense();
$expenseAccount = $this->user()->accounts()->where('account_type_id', 4)->first();
// mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, $expenseAccount->name])->andReturn(true);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
->andReturn(new Collection([$assetAccount]));
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
$firstDate->addDays(2); $firstDate->addDays(2);
@@ -501,9 +388,7 @@ class RecurrenceControllerTest extends TestCase
// test API // test API
$response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']); $response = $this->post('/api/v1/recurrences', $data, ['Accept' => 'application/json']);
$response->assertStatus(200); $response->assertStatus(200);
$response->assertHeader('Content-Type', 'application/vnd.api+json'); $response->assertHeader('Content-Type', 'application/vnd.api+json');
} }
@@ -515,42 +400,18 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailBothRepetitions(): void public function testStoreFailBothRepetitions(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $validator = $this->mock(AccountValidator::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); // mock calls to validator:
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$transformer = $this->mock(RecurrenceTransformer::class); $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
->andReturn(new Collection([$assetAccount]));
// entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text');
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
// entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null);
$budgetRepos->shouldReceive('findNull')->andReturn(null);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -611,32 +472,17 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailForeignCurrency(): void public function testStoreFailForeignCurrency(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $validator = $this->mock(AccountValidator::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); // mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Checking Account'])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[0]])->once()->andReturn(new Collection);
// used by the validator to find the source_name:
$accountRepos->shouldReceive('findByName')->withArgs(['Checking Account', [AccountType::ASSET]])->once()->andReturn($assetAccount);
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -691,32 +537,18 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidDaily(): void public function testStoreFailInvalidDaily(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $validator = $this->mock(AccountValidator::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class);
// mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser');
$budgetRepos->shouldReceive('setUser');
$accountRepos->shouldReceive('setUser');
// used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
->andReturn(new Collection([$assetAccount]));
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -770,43 +602,44 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidDestinationId(): void public function testStoreFailInvalidDestinationId(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first();
// mock stuff: // mock stuff:
$repository = $this->mock(RecurringRepositoryInterface::class); $repository = $this->mock(RecurringRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class); $factory = $this->mock(CategoryFactory::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class); $budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->getRandomAsset();
// mock calls to validator:
$validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);
$validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$assetAccount->id, null])->andReturn(true);
$validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$assetAccount->id, null])->andReturn(false);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); //$factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); //$budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); //$accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() // $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
->andReturn(new Collection([$assetAccount])); // ->andReturn(new Collection([$assetAccount]));
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once() // $accountRepos->shouldReceive('getAccountsById')->withArgs([[$assetAccount->id]])->once()
->andReturn(new Collection([$assetAccount])); // ->andReturn(new Collection([$assetAccount]));
//
//
// entries used by the transformer // // entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text'); // $repository->shouldReceive('getNoteText')->andReturn('Note text')->atLeast()->once();
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.'); // $repository->shouldReceive('repetitionDescription')->andReturn('Some description.')->atLeast()->once();
$repository->shouldReceive('getXOccurrences')->andReturn([]); // $repository->shouldReceive('getXOccurrences')->andReturn([])->atLeast()->once();
//
// entries used by the transformer (the fake entry has a category + a budget): // // entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null); // $factory->shouldReceive('findOrCreate')->andReturn(null)->atLeast()->once();
$budgetRepos->shouldReceive('findNull')->andReturn(null); // $budgetRepos->shouldReceive('findNull')->andReturn(null)->atLeast()->once();
// data to submit // data to submit
@@ -823,7 +656,7 @@ class RecurrenceControllerTest extends TestCase
'amount' => '100', 'amount' => '100',
'currency_id' => '1', 'currency_id' => '1',
'description' => 'Test description', 'description' => 'Test description',
'source_id' => '1', 'source_id' => $assetAccount->id,
'destination_id' => $assetAccount->id, 'destination_id' => $assetAccount->id,
], ],
], ],
@@ -844,8 +677,11 @@ class RecurrenceControllerTest extends TestCase
[ [
'message' => 'The given data was invalid.', 'message' => 'The given data was invalid.',
'errors' => [ 'errors' => [
'transactions.0.destination_id' => [ 'transactions.0.destination_id' => [
'This value is invalid for this field.', null
],
'transactions.0.destination_name' => [
null
], ],
], ],
] ]
@@ -862,9 +698,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidMonthly(): void public function testStoreFailInvalidMonthly(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -875,14 +708,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -940,9 +774,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidNdom(): void public function testStoreFailInvalidNdom(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -953,14 +784,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -1018,9 +850,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidNdomCount(): void public function testStoreFailInvalidNdomCount(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1031,15 +860,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -1097,9 +926,7 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidNdomHigh(): void public function testStoreFailInvalidNdomHigh(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1110,14 +937,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -1175,9 +1003,7 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailInvalidWeekly(): void public function testStoreFailInvalidWeekly(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1188,14 +1014,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -1253,9 +1080,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailNoAsset(): void public function testStoreFailNoAsset(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1266,10 +1090,11 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -1325,9 +1150,7 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailNotAsset(): void public function testStoreFailNotAsset(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1341,10 +1164,11 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used to find the source_id: // used to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[$expenseAccount->id]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[$expenseAccount->id]])->once()
@@ -1403,9 +1227,7 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailNotAssetName(): void public function testStoreFailNotAssetName(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1419,10 +1241,11 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used to find the source_id: // used to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[0]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[0]])->once()
@@ -1488,9 +1311,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailRepetitions(): void public function testStoreFailRepetitions(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1501,14 +1321,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// used by the validator to find the source_id: // used by the validator to find the source_id:
$accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once() $accountRepos->shouldReceive('getAccountsById')->withArgs([[1]])->once()
@@ -1558,9 +1379,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreFailTransactions(): void public function testStoreFailTransactions(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1571,14 +1389,15 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
// data to submit // data to submit
$firstDate = new Carbon; $firstDate = new Carbon;
@@ -1626,9 +1445,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testStoreTransfer(): void public function testStoreTransfer(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1639,6 +1455,7 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -1651,10 +1468,10 @@ class RecurrenceControllerTest extends TestCase
$otherAssetAccount = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $assetAccount->id)->first(); $otherAssetAccount = $this->user()->accounts()->where('account_type_id', 3)->where('id', '!=', $assetAccount->id)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('store')->once()->andReturn($recurrence); $repository->shouldReceive('store')->once()->andReturn($recurrence);
@@ -1664,13 +1481,13 @@ class RecurrenceControllerTest extends TestCase
// entries used by the transformer // entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text'); $repository->shouldReceive('getNoteText')->andReturn('Note text')->atLeast()->once();
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.'); $repository->shouldReceive('repetitionDescription')->andReturn('Some description.')->atLeast()->once();
$repository->shouldReceive('getXOccurrences')->andReturn([]); $repository->shouldReceive('getXOccurrences')->andReturn([])->atLeast()->once();
// entries used by the transformer (the fake entry has a category + a budget): // entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null); $factory->shouldReceive('findOrCreate')->andReturn(null)->atLeast()->once();
$budgetRepos->shouldReceive('findNull')->andReturn(null); $budgetRepos->shouldReceive('findNull')->andReturn(null)->atLeast()->once();
// data to submit // data to submit
@@ -1717,9 +1534,6 @@ class RecurrenceControllerTest extends TestCase
*/ */
public function testUpdate(): void public function testUpdate(): void
{ {
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Recurrence $recurrence */ /** @var Recurrence $recurrence */
$recurrence = $this->user()->recurrences()->first(); $recurrence = $this->user()->recurrences()->first();
@@ -1730,6 +1544,7 @@ class RecurrenceControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class); $accountRepos = $this->mock(AccountRepositoryInterface::class);
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class); $piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$transformer = $this->mock(RecurrenceTransformer::class); $transformer = $this->mock(RecurrenceTransformer::class);
$validator = $this->mock(AccountValidator::class);
// mock calls to transformer: // mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once(); $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
@@ -1741,10 +1556,10 @@ class RecurrenceControllerTest extends TestCase
$assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first(); $assetAccount = $this->user()->accounts()->where('account_type_id', 3)->first();
// mock calls: // mock calls:
$repository->shouldReceive('setUser'); $repository->shouldReceive('setUser')->atLeast()->once();
$factory->shouldReceive('setUser'); $factory->shouldReceive('setUser')->atLeast()->once();
$budgetRepos->shouldReceive('setUser'); $budgetRepos->shouldReceive('setUser')->atLeast()->once();
$accountRepos->shouldReceive('setUser'); $accountRepos->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('update')->once()->andReturn($recurrence); $repository->shouldReceive('update')->once()->andReturn($recurrence);
@@ -1753,13 +1568,13 @@ class RecurrenceControllerTest extends TestCase
// entries used by the transformer // entries used by the transformer
$repository->shouldReceive('getNoteText')->andReturn('Note text'); $repository->shouldReceive('getNoteText')->andReturn('Note text')->atLeast()->once();
$repository->shouldReceive('repetitionDescription')->andReturn('Some description.'); $repository->shouldReceive('repetitionDescription')->andReturn('Some description.')->atLeast()->once();
$repository->shouldReceive('getXOccurrences')->andReturn([]); $repository->shouldReceive('getXOccurrences')->andReturn([])->atLeast()->once();
// entries used by the transformer (the fake entry has a category + a budget): // entries used by the transformer (the fake entry has a category + a budget):
$factory->shouldReceive('findOrCreate')->andReturn(null); $factory->shouldReceive('findOrCreate')->andReturn(null)->atLeast()->once();
$budgetRepos->shouldReceive('findNull')->andReturn(null); $budgetRepos->shouldReceive('findNull')->andReturn(null)->atLeast()->once();
// data to submit // data to submit