Improve test coverage.

This commit is contained in:
James Cole 2019-08-03 10:50:43 +02:00
parent b8b59b13a7
commit 75c2529d3e
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
23 changed files with 367 additions and 539 deletions

View File

@ -52,6 +52,9 @@ class GracefulNotFoundHandler extends ExceptionHandler
public function render($request, Exception $exception)
{
$route = $request->route();
if(null === $route) {
return parent::render($request, $exception);
}
$name = $route->getName();
if (!auth()->check()) {
return parent::render($request, $exception);

View File

@ -431,31 +431,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
return $savePerMonth;
}
/**
* @param PiggyBankEvent $event
*
* @return int|null
*/
public function getTransactionWithEvent(PiggyBankEvent $event): ?int
{
$journal = $event->transactionJournal;
if (null === $journal) {
return null;
}
if ((float)$event->amount < 0) {
$transaction = $journal->transactions()->where('amount', '<', 0)->first();
return $transaction->id ?? null;
}
if ((float)$event->amount > 0) {
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
return $transaction->id ?? null;
}
return null;
}
/**
* Get for piggy account what is left to put in piggies.
*

View File

@ -199,13 +199,6 @@ interface PiggyBankRepositoryInterface
*/
public function getSuggestedMonthlyAmount(PiggyBank $piggyBank): string;
/**
* @param PiggyBankEvent $event
*
* @return int|null
*/
public function getTransactionWithEvent(PiggyBankEvent $event): ?int;
/**
* Get for piggy account what is left to put in piggies.
*

View File

@ -156,7 +156,7 @@ class ImportableConverter
'transactions' => [
[
'user' => $this->importJob->user_id,
'type' => $transactionType,
'type' => strtolower($transactionType),
'date' => $this->convertDateValue($importable->date) ?? Carbon::now()->format('Y-m-d H:i:s'),
'order' => 0,

View File

@ -81,6 +81,7 @@ class StageImportDataHandler
}
$totalSet = array_merge(...$totalSet);
Log::debug(sprintf('Found %d transactions in total.', count($totalSet)));
$this->repository->setTransactions($this->importJob, $totalSet);
}

View File

@ -82,8 +82,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
}
// get associated journal and transaction, if any:
$journalId = $event->transaction_journal_id;
$transactionId = $this->piggyRepos->getTransactionWithEvent($event);
$journalId = (int)$event->transaction_journal_id;
$data = [
'id' => (int)$event->id,
@ -94,8 +93,7 @@ class PiggyBankEventTransformer extends AbstractTransformer
'currency_code' => $currency->code,
'currency_symbol' => $currency->symbol,
'currency_decimal_places' => $currency->decimal_places,
'journal_id' => $journalId,
'transaction_id' => $transactionId,
'transaction_journal_id' => $journalId,
'links' => [
[
'rel' => 'self',

View File

@ -101,7 +101,6 @@ class TransactionGroupTransformer extends AbstractTransformer
*/
public function transformObject(TransactionGroup $group): array
{
//$first = $group->transactionJournals->first();
$result = [
'id' => (int)$group->id,
'created_at' => $group->created_at->toAtomString(),
@ -174,11 +173,13 @@ class TransactionGroupTransformer extends AbstractTransformer
// get foreign amount:
$foreignAmount = null;
// @codeCoverageIgnoreStart
if (null !== $source->foreign_amount) {
$foreignAmount = TransactionType::WITHDRAWAL !== $type
? app('steam')->negative($source->foreign_amount)
: app('steam')->positive($source->foreign_amount);
}
// @codeCoverageIgnoreEnd
$metaFieldData = $this->groupRepos->getMetaFields($journal->id, $this->metaFields);
$metaDateData = $this->groupRepos->getMetaDateFields($journal->id, $this->metaDateFields);
@ -280,7 +281,7 @@ class TransactionGroupTransformer extends AbstractTransformer
}
$foreignAmount = null;
if (null !== $row['foreign_amount']) {
$foreignAmount = TransactionType::WITHDRAWAL !== $type ? bcmul($row['foreign_amount'], '-1') : $row['foreign_amount'];
$foreignAmount = TransactionType::WITHDRAWAL !== $type ? bcmul($row['foreign_amount'], '-1') : $row['foreign_amount']; // @codeCoverageIgnore
}
$metaFieldData = $this->groupRepos->getMetaFields((int)$row['transaction_journal_id'], $this->metaFields);

View File

@ -1,214 +0,0 @@
<?php
/**
* TransactionTransformer.php
* Copyright (c) 2018 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 FireflyIII\Transformers;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Log;
/**
* Class TransactionTransformer
* @deprecated
*/
class TransactionTransformer extends AbstractTransformer
{
/** @var JournalRepositoryInterface */
protected $repository;
/**
* TransactionTransformer constructor.
*
* @codeCoverageIgnore
*/
public function __construct()
{
$this->repository = app(JournalRepositoryInterface::class);
if ('testing' === config('app.env')) {
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
}
}
/**
* Transform the journal.
*
* @param Transaction $transaction
*
* @return array
* @throws FireflyException
*/
public function transform(Transaction $transaction): array
{
$journal = $transaction->transactionJournal;
$category = $this->getCategory($transaction);
$budget = $this->getBudget($transaction);
$this->repository->setUser($journal->user);
$notes = $this->repository->getNoteText($journal);
$tags = implode(',', $this->repository->getTags($journal));
$data = [
'id' => (int)$transaction->id,
'created_at' => $transaction->created_at->toAtomString(),
'updated_at' => $transaction->updated_at->toAtomString(),
'description' => $transaction->description,
'journal_description' => $transaction->description,
'transaction_description' => $transaction->transaction_description,
'date' => $transaction->date->toAtomString(),
'type' => $transaction->transaction_type_type,
'identifier' => $transaction->identifier,
'journal_id' => (int)$transaction->journal_id,
'reconciled' => (bool)$transaction->reconciled,
'amount' => round($transaction->transaction_amount, (int)$transaction->transaction_currency_dp),
'currency_id' => $transaction->transaction_currency_id,
'currency_code' => $transaction->transaction_currency_code,
'currency_symbol' => $transaction->transaction_currency_symbol,
'currency_decimal_places' => $transaction->transaction_currency_dp,
'foreign_amount' => null,
'foreign_currency_id' => $transaction->foreign_currency_id,
'foreign_currency_code' => $transaction->foreign_currency_code,
'foreign_currency_symbol' => $transaction->foreign_currency_symbol,
'foreign_currency_decimal_places' => $transaction->foreign_currency_dp,
'bill_id' => $transaction->bill_id,
'bill_name' => $transaction->bill_name,
'category_id' => $category['category_id'],
'category_name' => $category['category_name'],
'budget_id' => $budget['budget_id'],
'budget_name' => $budget['budget_name'],
'notes' => $notes,
'sepa_cc' => $this->repository->getMetaField($journal, 'sepa_cc'),
'sepa_ct_op' => $this->repository->getMetaField($journal, 'sepa_ct_op'),
'sepa_ct_id' => $this->repository->getMetaField($journal, 'sepa_ct_ud'),
'sepa_db' => $this->repository->getMetaField($journal, 'sepa_db'),
'sepa_country' => $this->repository->getMetaField($journal, 'sepa_country'),
'sepa_ep' => $this->repository->getMetaField($journal, 'sepa_ep'),
'sepa_ci' => $this->repository->getMetaField($journal, 'sepa_ci'),
'sepa_batch_id' => $this->repository->getMetaField($journal, 'sepa_batch_id'),
'interest_date' => $this->repository->getMetaDateString($journal, 'interest_date'),
'book_date' => $this->repository->getMetaDateString($journal, 'book_date'),
'process_date' => $this->repository->getMetaDateString($journal, 'process_date'),
'due_date' => $this->repository->getMetaDateString($journal, 'due_date'),
'payment_date' => $this->repository->getMetaDateString($journal, 'payment_date'),
'invoice_date' => $this->repository->getMetaDateString($journal, 'invoice_date'),
'internal_reference' => $this->repository->getMetaField($journal, 'internal_reference'),
'bunq_payment_id' => $this->repository->getMetaField($journal, 'bunq_payment_id'),
'import_hash_v2' => $this->repository->getMetaField($journal, 'import_hash_v2'),
'recurrence_id' => (int)$this->repository->getMetaField($journal, 'recurrence_id'),
'external_id' => $this->repository->getMetaField($journal, 'external_id'),
'original_source' => $this->repository->getMetaField($journal, 'original-source'),
'tags' => '' === $tags ? null : $tags,
'links' => [
[
'rel' => 'self',
'uri' => '/transactions/' . $transaction->id,
],
],
];
// expand foreign amount:
if (null !== $transaction->transaction_foreign_amount) {
$data['foreign_amount'] = round($transaction->transaction_foreign_amount, (int)$transaction->foreign_currency_dp);
}
// switch on type for consistency
switch ($transaction->transaction_type_type) {
case TransactionType::WITHDRAWAL:
Log::debug(sprintf('%d is a withdrawal', $transaction->journal_id));
$data['source_id'] = $transaction->account_id;
$data['source_name'] = $transaction->account_name;
$data['source_iban'] = $transaction->account_iban;
$data['source_type'] = $transaction->account_type;
$data['destination_id'] = $transaction->opposing_account_id;
$data['destination_name'] = $transaction->opposing_account_name;
$data['destination_iban'] = $transaction->opposing_account_iban;
$data['destination_type'] = $transaction->opposing_account_type;
Log::debug(sprintf('source_id / account_id is %d', $transaction->account_id));
Log::debug(sprintf('source_name / account_name is "%s"', $transaction->account_name));
break;
case TransactionType::DEPOSIT:
case TransactionType::TRANSFER:
case TransactionType::OPENING_BALANCE:
case TransactionType::RECONCILIATION:
$data['source_id'] = $transaction->opposing_account_id;
$data['source_name'] = $transaction->opposing_account_name;
$data['source_iban'] = $transaction->opposing_account_iban;
$data['source_type'] = $transaction->opposing_account_type;
$data['destination_id'] = $transaction->account_id;
$data['destination_name'] = $transaction->account_name;
$data['destination_iban'] = $transaction->account_iban;
$data['destination_type'] = $transaction->account_type;
break;
default:
// @codeCoverageIgnoreStart
throw new FireflyException(
sprintf('Transaction transformer cannot handle transactions of type "%s"!', $transaction->transaction_type_type)
);
// @codeCoverageIgnoreEnd
}
// expand description.
if ('' !== (string)$transaction->transaction_description) {
$data['description'] = $transaction->transaction_description . ' (' . $transaction->description . ')';
}
return $data;
}
/**
* @param Transaction $transaction
*
* @return array
*/
private function getBudget(Transaction $transaction): array
{
if ($transaction->transaction_type_type !== TransactionType::WITHDRAWAL) {
return [
'budget_id' => null,
'budget_name' => null,
];
}
return [
'budget_id' => $transaction->transaction_budget_id ?? $transaction->transaction_journal_budget_id,
'budget_name' => $transaction->transaction_budget_name ?? $transaction->transaction_journal_budget_name,
];
}
/**
* @param Transaction $transaction
*
* @return array
*/
private function getCategory(Transaction $transaction): array
{
return [
'category_id' => $transaction->transaction_category_id ?? $transaction->transaction_journal_category_id,
'category_name' => $transaction->transaction_category_name ?? $transaction->transaction_journal_category_name,
];
}
}

View File

@ -32,40 +32,15 @@
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<testsuites>
<!-- test suites -->
<testsuite name="Api">
<directory suffix="Test.php">./tests/Api</directory>
</testsuite>
<!-- unit tests, splitted: -->
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit/Console</directory>
<directory suffix="Test.php">./tests/Unit/Factory</directory>
<directory suffix="Test.php">./tests/Unit/Generator</directory>
<directory suffix="Test.php">./tests/Unit/Handlers</directory>
<directory suffix="Test.php">./tests/Unit/Helpers</directory>
<directory suffix="Test.php">./tests/Unit/Import</directory>
<directory suffix="Test.php">./tests/Unit/Jobs</directory>
<directory suffix="Test.php">./tests/Unit/Middleware</directory>
<directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<!--
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
-->
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -32,39 +32,15 @@
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<testsuites>
<!-- test suites -->
<testsuite name="Api">
<directory suffix="Test.php">./tests/Api</directory>
</testsuite>
<!-- unit tests, splitted: -->
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit/Console</directory>
<directory suffix="Test.php">./tests/Unit/Factory</directory>
<directory suffix="Test.php">./tests/Unit/Generator</directory>
<directory suffix="Test.php">./tests/Unit/Handlers</directory>
<directory suffix="Test.php">./tests/Unit/Helpers</directory>
<directory suffix="Test.php">./tests/Unit/Import</directory>
<directory suffix="Test.php">./tests/Unit/Jobs</directory>
<directory suffix="Test.php">./tests/Unit/Middleware</directory>
<directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<!--
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
-->
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -32,38 +32,15 @@
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<testsuites>
<!-- test suites -->
<testsuite name="Api">
<directory suffix="Test.php">./tests/Api</directory>
</testsuite>
<!-- unit tests, splitted: -->
<testsuite name="Unit">
<!--
<directory suffix="Test.php">./tests/Unit/Console</directory>
<directory suffix="Test.php">./tests/Unit/Factory</directory>
<directory suffix="Test.php">./tests/Unit/Generator</directory>
<directory suffix="Test.php">./tests/Unit/Handlers</directory>
<directory suffix="Test.php">./tests/Unit/Helpers</directory>
<directory suffix="Test.php">./tests/Unit/Import</directory>
<directory suffix="Test.php">./tests/Unit/Jobs</directory>
<directory suffix="Test.php">./tests/Unit/Middleware</directory>
<directory suffix="Test.php">./tests/Unit/Rules</directory>
<directory suffix="Test.php">./tests/Unit/Services</directory>
<directory suffix="Test.php">./tests/Unit/Support</directory>
<directory suffix="Test.php">./tests/Unit/TransactionRules</directory>
-->
<directory suffix="Test.php">./tests/Unit/Transformers</directory>
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<!--
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
-->
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -509,6 +509,7 @@ class CurrencyControllerTest extends TestCase
$repository->shouldReceive('update')->andReturn(new TransactionCurrency);
$userRepos->shouldReceive('hasRole')->once()->andReturn(true);
$repository->shouldReceive('currencyInUse')->atLeast()->once()->andReturn(true);
Preferences::shouldReceive('mark')->atLeast()->once();
$this->session(['currencies.edit.uri' => 'http://localhost']);

View File

@ -55,9 +55,9 @@ class ShowControllerTest extends TestCase
$withdrawal = $this->getRandomWithdrawalGroup();
$array = $this->getRandomWithdrawalGroupAsArray();
$array[0]['transactions'][0]['foreign_amount'] = '10';
$array[0]['transactions'][0]['foreign_currency_symbol'] = 'x';
$array[0]['transactions'][0]['foreign_currency_decimal_places'] = 2;
$array['transactions'][0]['foreign_amount'] = '10';
$array['transactions'][0]['foreign_currency_symbol'] = 'x';
$array['transactions'][0]['foreign_currency_decimal_places'] = 2;
$groupRepository = $this->mock(TransactionGroupRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
@ -65,7 +65,7 @@ class ShowControllerTest extends TestCase
// mock for transformer:
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array[0]);
$transformer->shouldReceive('transformObject')->atLeast()->once()->andReturn($array);
// mock for repos
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);

View File

@ -41,6 +41,7 @@ use FireflyIII\Models\Configuration;
use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\ImportJob;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule;
@ -67,6 +68,14 @@ use RuntimeException;
abstract class TestCase extends BaseTestCase
{
/**
* @return ImportJob
*/
public function getRandomPiggyBankEvent(): PiggyBankEvent
{
return PiggyBankEvent::inRandomOrder()->first();
}
/**
* @return ImportJob
*/
@ -347,7 +356,6 @@ abstract class TestCase extends BaseTestCase
/**
* @return array
* @throws Exception
*/
public function getRandomWithdrawalGroupAsArray(): array
{
@ -360,12 +368,15 @@ abstract class TestCase extends BaseTestCase
$e->getMessage();
}
return [
return
[
'group_title' => null,
'transactions' => [
[
'updated_at' => new Carbon,
'created_at' => new Carbon,
'transaction_journal_id' => $withdrawal->id,
'transaction_type_type' => 'Withdrawal',
'currency_id' => $euro->id,
'foreign_currency_id' => null,
'date' => $date,
@ -380,8 +391,47 @@ abstract class TestCase extends BaseTestCase
'budget_id' => $budget->id,
],
],
],
];
];
}
/**
* @return array
*/
public function getRandomDepositGroupAsArray(): array
{
$deposit = $this->getRandomDeposit();
$euro = $this->getEuro();
$budget = $this->getRandomBudget();
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
}
return
[
'group_title' => null,
'transactions' => [
[
'updated_at' => new Carbon,
'created_at' => new Carbon,
'transaction_journal_id' => $deposit->id,
'transaction_type_type' => 'Deposit',
'currency_id' => $euro->id,
'foreign_currency_id' => null,
'date' => $date,
'source_id' => 1,
'destination_id' => 4,
'currency_name' => $euro->name,
'currency_code' => $euro->code,
'currency_symbol' => $euro->symbol,
'currency_decimal_places' => $euro->decimal_places,
'amount' => '-30',
'foreign_amount' => null,
'budget_id' => $budget->id,
],
],
];
}
/**

View File

@ -65,22 +65,23 @@ class MonthReportGeneratorTest extends TestCase
$dollar = $this->getDollar();
$return = [
[
'description' => 'Hello',
'amount' => '10',
'foreign_currency_id' => null,
'currency_id' => $euro->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
'description' => 'Hello',
'amount' => '10',
'foreign_currency_id' => null,
'currency_id' => $euro->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
'transaction_journal_id' => 1,
],
[
'description' => 'Hello2',
'amount' => '10',
'foreign_amount' => '10',
'foreign_currency_id' => $euro->id,
'currency_id' => $dollar->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
'description' => 'Hello2',
'amount' => '10',
'foreign_amount' => '10',
'foreign_currency_id' => $euro->id,
'currency_id' => $dollar->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
'transaction_journal_id' => 1,
],
];
@ -100,14 +101,15 @@ class MonthReportGeneratorTest extends TestCase
// mock calls
Steam::shouldReceive('balance')->times(2)->andReturn('100');
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$accountRepos->shouldReceive('getAccountCurrency')->atLeast()->once()->andReturn($euro);
// mock collector:
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($return);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
//$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
try {
$result = $generator->getAuditReport($asset, $date);

View File

@ -116,7 +116,7 @@ class BinderTest extends TestCase
public function testAccountListEmpty(): void
{
Route::middleware(Binder::class)->any(
'/_test/binder/{accountList}', function (Collection $accounts) {
'/_test/binder/{accountList}', static function (Collection $accounts) {
return 'count: ' . $accounts->count();
}
);

View File

@ -144,7 +144,8 @@ class AssetAccountMapperTest extends TestCase
// mock repository:
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByIbanNull')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);
$repository->shouldReceive('findByIbanNull')->once()
->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
$mapper = new AssetAccountMapper;
$mapper->setUser($this->user());
@ -164,7 +165,8 @@ class AssetAccountMapperTest extends TestCase
// mock repository:
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByName')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);
$repository->shouldReceive('findByName')->once()
->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
$mapper = new AssetAccountMapper;
$mapper->setUser($this->user());
@ -184,7 +186,8 @@ class AssetAccountMapperTest extends TestCase
// mock repository:
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('findByAccountNumber')->once()->withArgs([$searchValue, [AccountType::ASSET]])->andReturn($expected);
$repository->shouldReceive('findByAccountNumber')->once()
->withArgs([$searchValue, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($expected);
$mapper = new AssetAccountMapper;
$mapper->setUser($this->user());

View File

@ -90,6 +90,9 @@ class OpposingAccountMapperTest extends TestCase
$repository->shouldReceive('findNull')->andReturn($expected)->once();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();
$repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
->andReturn(new Account);
@ -127,8 +130,15 @@ class OpposingAccountMapperTest extends TestCase
$repository->shouldReceive('findNull')->andReturn($expected)->once();
$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::EXPENSE]])->andReturnNull();
$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::ASSET]])->andReturnNull();
$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::DEBT]])->andReturnNull();
$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::MORTGAGE]])->andReturnNull();
$repository->shouldReceive('findByIbanNull')->withArgs([$expected->iban, [AccountType::LOAN]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::EXPENSE]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::ASSET]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::DEBT]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::MORTGAGE]])->andReturnNull();
$repository->shouldReceive('findByName')->withArgs([$expected->name, [AccountType::LOAN]])->andReturnNull();
$repository->shouldReceive('store')->withArgs([$expectedArgs])->once()
->andReturn(new Account);

View File

@ -74,8 +74,8 @@ class StageImportDataHandlerTest extends TestCase
$today = new Carbon;
// create fake transactions:
$op1 = 'Some opposing account #' . random_int(1, 100);
$op2 = 'Some opposing revenue account #' . random_int(1, 100);
$op1 = 'Some opposing account #' . $this->randomInt();
$op2 = 'Some opposing revenue account #' . $this->randomInt();
$transactions = [
new SpectreTransaction(
[
@ -85,7 +85,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => -123.45,
'currency_code' => 'EUR',
'description' => 'Fake description #' . random_int(1, 100),
'description' => 'Fake description #' . $this->randomInt(),
'category' => 'some-category',
'duplicated' => false,
'extra' => [
@ -104,7 +104,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => 563.21,
'currency_code' => 'EUR',
'description' => 'Fake second description #' . random_int(1, 100),
'description' => 'Fake second description #' . $this->randomInt(),
'category' => 'some-other-category',
'duplicated' => false,
'extra' => [
@ -142,28 +142,26 @@ class StageImportDataHandlerTest extends TestCase
$lrRequest = $this->mock(ListTransactionsRequest::class);
$mapper = $this->mock(OpposingAccountMapper::class);
// expected result
$expected = [
0 => [
'type' => 'withdrawal',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// transaction here
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active'],
'type' => 'withdrawal',
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '-123.45',
'budget_id' => null,
'budget_name' => null,
@ -180,28 +178,26 @@ class StageImportDataHandlerTest extends TestCase
'identifier' => 0,
],
],
],
1 => [
'type' => 'deposit',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// transaction here
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active'],
'type' => 'deposit',
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '563.21',
'budget_id' => null,
'budget_name' => null,
@ -218,14 +214,13 @@ class StageImportDataHandlerTest extends TestCase
'identifier' => 0,
],
],
],
];
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
$importRepos->shouldReceive('setUser')->once();
$importRepos->shouldReceive('setTransactions')->once()
->withArgs([Mockery::any(), $expected]);
$importRepos->shouldReceive('setTransactions')->once()->withArgs([Mockery::any(), $expected]);
$lrRequest->shouldReceive('setUser')->once();
$lrRequest->shouldReceive('setAccount')->once()->withArgs([Mockery::any()]);
$lrRequest->shouldReceive('call')->once();
@ -273,9 +268,9 @@ class StageImportDataHandlerTest extends TestCase
$today = new Carbon;
// create fake transactions:
$op1 = 'Some opposing account #' . random_int(1, 100);
$op2 = 'Some opposing revenue account #' . random_int(1, 100);
$transactions = [
$op1 = 'Some opposing account #' . $this->randomInt();
$op2 = 'Some opposing revenue account #' . $this->randomInt();
$transactions = [
new SpectreTransaction(
[
'id' => 1,
@ -284,7 +279,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => -123.45,
'currency_code' => 'EUR',
'description' => 'Fake description #' . random_int(1, 100),
'description' => 'Fake description #' . $this->randomInt(),
'category' => 'some-category',
'duplicated' => true,
'extra' => [
@ -304,7 +299,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => 563.21,
'currency_code' => 'EUR',
'description' => 'Fake second description #' . random_int(1, 100),
'description' => 'Fake second description #' . $this->randomInt(),
'category' => 'some-other-category',
'duplicated' => false,
'extra' => [
@ -345,29 +340,26 @@ class StageImportDataHandlerTest extends TestCase
$lrRequest = $this->mock(ListTransactionsRequest::class);
$mapper = $this->mock(OpposingAccountMapper::class);
// expected result
$expected = [
0 => [
'type' => 'withdrawal',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active', 'possibly-duplicated'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// data here.
'date' => $today->format('Y-m-d'),
'type' => 'withdrawal',
'tags' => ['mode', 'active', 'possibly-duplicated'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '-123.45',
'budget_id' => null,
'budget_name' => null,
@ -386,26 +378,24 @@ class StageImportDataHandlerTest extends TestCase
],
],
1 => [
'type' => 'deposit',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active', 'cat-name'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// data here.
'date' => $today->format('Y-m-d'),
'type' => 'deposit',
'tags' => ['mode', 'active', 'cat-name'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '563.21',
'budget_id' => null,
'budget_name' => null,
@ -424,6 +414,7 @@ class StageImportDataHandlerTest extends TestCase
],
],
];
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
$importRepos->shouldReceive('setUser')->once();
@ -474,8 +465,8 @@ class StageImportDataHandlerTest extends TestCase
$today = new Carbon;
// create fake transactions:
$op1 = 'Some opposing account #' . random_int(1, 100);
$op2 = 'Some opposing revenue account #' . random_int(1, 100);
$op1 = 'Some opposing account #' . $this->randomInt();
$op2 = 'Some opposing revenue account #' . $this->randomInt();
$transactions = [
new SpectreTransaction(
[
@ -485,7 +476,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => -123.45,
'currency_code' => 'EUR',
'description' => 'Fake description #' . random_int(1, 100),
'description' => 'Fake description #' . $this->randomInt(),
'category' => 'some-category',
'duplicated' => true,
'extra' => [
@ -504,7 +495,7 @@ class StageImportDataHandlerTest extends TestCase
'made_on' => $today->toW3cString(),
'amount' => 563.21,
'currency_code' => 'EUR',
'description' => 'Fake second description #' . random_int(1, 100),
'description' => 'Fake second description #' . $this->randomInt(),
'category' => 'some-other-category',
'duplicated' => false,
'extra' => [
@ -543,29 +534,26 @@ class StageImportDataHandlerTest extends TestCase
$lrRequest = $this->mock(ListTransactionsRequest::class);
$mapper = $this->mock(OpposingAccountMapper::class);
// expected result
$expected = [
0 => [
'type' => 'withdrawal',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active', 'possibly-duplicated'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// data here
'date' => $today->format('Y-m-d'),
'type' => 'withdrawal',
'tags' => ['mode', 'active', 'possibly-duplicated'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op1 . " \n",
'external_id' => '1',
// journal data:
'description' => $transactions[0]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '-123.45',
'budget_id' => null,
'budget_name' => null,
@ -584,26 +572,24 @@ class StageImportDataHandlerTest extends TestCase
],
],
1 => [
'type' => 'deposit',
'date' => $today->format('Y-m-d'),
'tags' => ['mode', 'active', 'cat-name'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
// transaction data:
'transactions' => [
[
'transactions' => [
0 => [
// data here
'date' => $today->format('Y-m-d'),
'type' => 'deposit',
'tags' => ['mode', 'active', 'cat-name'],
'user' => $job->user_id,
'notes' => "Imported from \"Fake Spectre Account\" \npayee: " . $op2 . " \n",
'external_id' => '2',
// journal data:
'description' => $transactions[1]->getDescription(),
'piggy_bank_id' => null,
'piggy_bank_name' => null,
'bill_id' => null,
'bill_name' => null,
'original-source' => sprintf('spectre-v%s', config('firefly.version')),
'currency_id' => null,
'currency_code' => 'EUR',
'description' => null,
'amount' => '563.21',
'budget_id' => null,
'budget_name' => null,
@ -622,6 +608,7 @@ class StageImportDataHandlerTest extends TestCase
],
],
];
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findNull')->once()->withArgs([322])->andReturn($account);
$importRepos->shouldReceive('setUser')->once();

View File

@ -109,10 +109,7 @@ class BillTransformerTest extends TestCase
$this->assertEquals('2018-03-01', $result['next_expected_match']);
$this->assertEquals(['2018-01-01'], $result['pay_dates']);
$this->assertEquals(
['2018-01-02', '2018-01-09', '2018-01-16', '2018-01-21', '2018-01-30',]
, $result['paid_dates']
);
$this->assertEquals(['2018-01-02', '2018-01-09', '2018-01-16', '2018-01-21', '2018-01-30',], $result['paid_dates']);
}
}

View File

@ -68,16 +68,18 @@ class PiggyBankEventTransformerTest extends TestCase
// mock calls:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn($this->getEuro());
$piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);
$event = PiggyBankEvent::first();
$event = $this->getRandomPiggyBankEvent();
$transformer = app(PiggyBankEventTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($event);
$this->assertEquals($event->id, $result['id']);
$this->assertEquals(245, $result['amount']);
$this->assertEquals(123, $result['transaction_id']);
$this->assertEquals($event->amount, $result['amount']);
$this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);
}
@ -100,18 +102,17 @@ class PiggyBankEventTransformerTest extends TestCase
// mock calls:
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->atLeast()->once()->andReturn(1);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->atLeast()->once()->andReturn(null);
$piggyRepos->shouldReceive('getTransactionWithEvent')->atLeast()->once()->andReturn(123);
Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn($this->getEuro())->atLeast()->once();
$event = PiggyBankEvent::first();
$event = $this->getRandomPiggyBankEvent();
$transformer = app(PiggyBankEventTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($event);
$this->assertEquals($event->id, $result['id']);
$this->assertEquals(245, $result['amount']);
$this->assertEquals(123, $result['transaction_id']);
$this->assertEquals($event->amount, $result['amount']);
$this->assertEquals($event->transaction_journal_id, $result['transaction_journal_id']);
}
}

View File

@ -25,18 +25,15 @@ namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Log;
use Mockery;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
@ -56,7 +53,7 @@ class RecurrenceTransformerTest extends TestCase
}
/**
*
* @covers \FireflyIII\Transformers\RecurrenceTransformer
*/
public function testBasic(): void
{
@ -65,12 +62,13 @@ class RecurrenceTransformerTest extends TestCase
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
$factory = $this->mock(CategoryFactory::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$category = Category::first();
$budget = Budget::first();
$piggy = PiggyBank::first();
$bill = Bill::first();
$foreignCurrency = TransactionCurrency::find(2);
$category = $this->getRandomCategory();
$budget = $this->getRandomBudget();
$piggy = $this->getRandomPiggyBank();
$bill = $this->getRandomBill();
$foreignCurrency = $this->getDollar();
$ranges = [new Carbon];
$recurrence = $this->getRandomRecurrence();
// mock calls:
$recurrenceRepos->shouldReceive('setUser')->atLeast()->once();
$billRepos->shouldReceive('setUser')->atLeast()->once();
@ -82,47 +80,21 @@ class RecurrenceTransformerTest extends TestCase
$recurrenceRepos->shouldReceive('getNoteText')->once()->andReturn('Hi there');
$recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr');
$recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once();
$factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null, 'House'])->andReturn($category);
$factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null,Mockery::any()])->andReturn($category);
$budgetRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([2])->andReturn($budget);
$piggyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($piggy);
$billRepos->shouldReceive('find')->atLeast()->once()->withArgs([1])->andReturn($bill);
// basic transformation:
/** @var Recurrence $recurrence */
$recurrence = Recurrence::find(1);
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($recurrence);
$this->assertEquals(1, $result['id']);
$this->assertEquals($recurrence->id, $result['id']);
$this->assertEquals('withdrawal', $result['transaction_type']);
$this->assertEquals(true, $result['apply_rules']);
$this->assertEquals(
[
[
'value' => 'auto-generated',
'tags' => ['auto-generated'],
'name' => 'tags',
],
[
'name' => 'piggy_bank_id',
'piggy_bank_id' => 1,
'piggy_bank_name' => 'New camera',
'value' => '1',
],
[
'bill_id' => 1,
'bill_name' => 'Rent',
'name' => 'bill_id',
'value' => '1',
],
]
, $result['meta']
);
$this->assertEquals($foreignCurrency->code, $result['transactions'][0]['foreign_currency_code']);
$this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);

View File

@ -0,0 +1,120 @@
<?php
/**
* TransactionGroupTransformerTest.php
* Copyright (c) 2019 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/>.
*/
namespace Tests\Unit\Transformers;
use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;
use FireflyIII\Support\NullArrayObject;
use FireflyIII\Transformers\TransactionGroupTransformer;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class TransactionGroupTransformerTest
*/
class TransactionGroupTransformerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Transformers\TransactionGroupTransformer
*/
public function testBasic(): void
{
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$group = $this->getRandomWithdrawalGroup();
$first = $group->transactionJournals()->first();
// mock calls
$repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
$repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
$transformer = new TransactionGroupTransformer;
$result = $transformer->transformObject($group);
}
/**
* @covers \FireflyIII\Transformers\TransactionGroupTransformer
*/
public function testArray(): void {
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$group = $this->getRandomWithdrawalGroupAsArray();
// mock calls
$repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
$repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
$transformer = new TransactionGroupTransformer;
$result = $transformer->transform($group);
}
/**
* @covers \FireflyIII\Transformers\TransactionGroupTransformer
*/
public function testArrayDeposit(): void {
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$group = $this->getRandomDepositGroupAsArray();
// mock calls
$repository->shouldReceive('getMetaFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getMetaDateFields')->withArgs([Mockery::any(), Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
$repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
$transformer = new TransactionGroupTransformer;
$result = $transformer->transform($group);
}
/**
* @covers \FireflyIII\Transformers\TransactionGroupTransformer
*/
public function testDeposit(): void
{
$repository = $this->mock(TransactionGroupRepositoryInterface::class);
$group = $this->getRandomDepositGroup();
$first = $group->transactionJournals()->first();
// mock calls
$repository->shouldReceive('getMetaFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getMetaDateFields')->withArgs([$first->id, Mockery::any()])->andReturn(new NullArrayObject([]))->atLeast()->once();
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('note');
$repository->shouldReceive('getTags')->atLeast()->once()->andReturn([]);
$transformer = new TransactionGroupTransformer;
$result = $transformer->transformObject($group);
}
}