Improve test coverage.

This commit is contained in:
James Cole 2019-08-03 14:45:37 +02:00
parent 75c2529d3e
commit cf121fea50
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
16 changed files with 296 additions and 971 deletions

View File

@ -304,10 +304,13 @@ try {
$object = $attachment->attachable;
if ($object instanceof TransactionJournal) {
$breadcrumbs->parent('transactions.show', $object->transactionGroup);
$breadcrumbs->push(
trans('firefly.delete_attachment', ['name' => limitStringLength($attachment->filename)]), route('attachments.edit', [$attachment])
);
}
if ($object instanceof Bill) {
$breadcrumbs->parent('bills.show', $object);
}
$breadcrumbs->push(
trans('firefly.delete_attachment', ['name' => limitStringLength($attachment->filename)]), route('attachments.edit', [$attachment])
);
}
);

View File

@ -28,6 +28,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Transformers\PreferenceTransformer;
use Laravel\Passport\Passport;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
@ -59,6 +60,13 @@ class PreferencesControllerTest extends TestCase
$transformer = $this->mock(PreferenceTransformer::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
// mock calls to preferences facade.
$pref = new Preference;
$pref->data = [1, 2, 3];
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($pref);
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['frontPageAccounts', ['4', '5', '6']])->atLeast()->once()->andReturn($pref);
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
@ -67,10 +75,10 @@ class PreferencesControllerTest extends TestCase
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$accountRepos->shouldReceive('setUser')->atLeast()->once();
/** @var Preference $preference */
$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]);
$data = ['data' => '4,5,6'];
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
///** @var Preference $preference */
//$preference = Preferences::setForUser($this->user(), 'frontPageAccounts', [1, 2, 3]);
$data = ['data' => '4,5,6'];
$response = $this->put(route('api.v1.preferences.update', ['frontPageAccounts']), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
@ -83,6 +91,21 @@ class PreferencesControllerTest extends TestCase
$transformer = $this->mock(PreferenceTransformer::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
// mock calls to preferences facade.
$pref = new Preference;
$pref->data = false;
$countable = new Preference;
$countable->data = [1];
$saved = new Preference;
$saved->user_id = $this->user()->id;
$saved->name = 'twoFactorAuthEnabled';
$saved->data = false;
$saved->save();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['twoFactorAuthEnabled', '1'])->atLeast()->once()->andReturn($pref);
// mock calls to transformer:
$transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();
$transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();
@ -92,12 +115,12 @@ class PreferencesControllerTest extends TestCase
$accountRepos->shouldReceive('setUser')->atLeast()->once();
/** @var Preference $preference */
$preference = Preferences::setForUser($this->user(), 'twoFactorAuthEnabled', false);
$data = ['data' => '1'];
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
$data = ['data' => '1'];
$response = $this->put(route('api.v1.preferences.update', ['twoFactorAuthEnabled']), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
/**
@ -116,10 +139,23 @@ class PreferencesControllerTest extends TestCase
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$accountRepos->shouldReceive('setUser')->atLeast()->once();
/** @var Preference $preference */
$preference = Preferences::setForUser($this->user(), 'currencyPreference', false);
// mock calls to preferences facade.
$pref = new Preference;
$pref->data = 'EUR';
$countable = new Preference;
$countable->data = [1];
$saved = new Preference;
$saved->user_id = $this->user()->id;
$saved->name = 'twoFactorEnabled';
$saved->data = false;
$saved->save();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['currencyPreference', 'EUR'])->atLeast()->once()->andReturn($pref);
$data = ['data' => 'EUR'];
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
$response = $this->put(route('api.v1.preferences.update', ['currencyPreference']), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}
@ -140,10 +176,23 @@ class PreferencesControllerTest extends TestCase
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
$accountRepos->shouldReceive('setUser')->atLeast()->once();
/** @var Preference $preference */
$preference = Preferences::setForUser($this->user(), 'listPageSize', 13);
// mock calls to preferences facade.
$pref = new Preference;
$pref->data = 'EUR';
$countable = new Preference;
$countable->data = [1];
$saved = new Preference;
$saved->user_id = $this->user()->id;
$saved->name = 'listPageSize';
$saved->data = 200;
$saved->save();
Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'frontPageAccounts', []])->andReturn($countable);
Preferences::shouldReceive('set')->atLeast()->once()->withArgs(['listPageSize', '434'])->atLeast()->once()->andReturn($pref);
$data = ['data' => '434'];
$response = $this->put(route('api.v1.preferences.update', [$preference->name]), $data, ['Accept' => 'application/json']);
$response = $this->put(route('api.v1.preferences.update', ['listPageSize']), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
}

View File

@ -25,7 +25,7 @@ namespace Tests\Api\V1\Controllers;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Models\Preference;
use FireflyIII\Models\Rule;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
@ -37,6 +37,7 @@ use Laravel\Passport\Passport;
use Log;
use Preferences;
use Tests\TestCase;
use Mockery;
/**
*
@ -238,6 +239,12 @@ class RuleControllerTest extends TestCase
$transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
$response = $this->get(route('api.v1.rules.test', [$rule->id]) . '?accounts=1,2,3');
$response->assertStatus(200);

View File

@ -27,6 +27,7 @@ namespace Tests\Api\V1\Controllers;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions;
use FireflyIII\Jobs\Job;
use FireflyIII\Models\Preference;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
@ -38,6 +39,8 @@ use FireflyIII\Transformers\TransactionGroupTransformer;
use Illuminate\Support\Collection;
use Laravel\Passport\Passport;
use Log;
use Mockery;
use Preferences;
use Queue;
use Tests\TestCase;
@ -89,6 +92,8 @@ class RuleGroupControllerTest extends TestCase
$ruleGroupRepos->shouldReceive('store')->once()->andReturn($ruleGroup);
// test API
$response = $this->post(route('api.v1.rule_groups.store'), $data, ['Accept' => 'application/json']);
$response->assertStatus(200);
@ -133,6 +138,13 @@ class RuleGroupControllerTest extends TestCase
$matcher->shouldReceive('setAccounts')->once();
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn([]);
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
// call API
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]) . '?accounts=1,2,3');
$response->assertStatus(200);
@ -151,6 +163,13 @@ class RuleGroupControllerTest extends TestCase
$ruleGroupRepos->shouldReceive('setUser')->once();
$ruleGroupRepos->shouldReceive('getActiveRules')->once()->andReturn(new Collection);
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 50;
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'listPageSize', 50])->atLeast()->once()->andReturn($pref);
// call API
$group = $this->user()->ruleGroups()->first();
$response = $this->get(route('api.v1.rule_groups.test', [$group->id]), ['Accept' => 'application/json']);
@ -198,6 +217,8 @@ class RuleGroupControllerTest extends TestCase
$repository->shouldReceive('isAsset')->withArgs([1])->andReturn(true);
$repository->shouldReceive('isAsset')->withArgs([2])->andReturn(false);
$response = $this->post(route('api.v1.rule_groups.trigger', [$group->id]) . '?accounts=1,2,3&start_date=2019-01-01&end_date=2019-01-02');
$response->assertStatus(204);

View File

@ -639,6 +639,8 @@ class TransactionControllerTest extends TestCase
try {
$this->expectsEvents(StoredTransactionGroup::class);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
@ -856,6 +858,8 @@ class TransactionControllerTest extends TestCase
try {
$this->expectsEvents(UpdatedTransactionGroup::class);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}

View File

@ -243,7 +243,8 @@ abstract class TestCase extends BaseTestCase
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
return [
@ -286,7 +287,8 @@ abstract class TestCase extends BaseTestCase
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
return [
@ -327,7 +329,8 @@ abstract class TestCase extends BaseTestCase
try {
$date = new Carbon;
} catch (Exception $e) {
$e->getMessage();
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
return [

View File

@ -23,6 +23,7 @@ namespace Tests\Unit\Console\Commands\Tools;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
@ -31,6 +32,8 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\TransactionRules\Engine\RuleEngine;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Tests\TestCase;
/**
@ -100,6 +103,11 @@ class ApplyRulesTest extends TestCase
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
@ -159,6 +167,11 @@ class ApplyRulesTest extends TestCase
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('No rules or rule groups have been included.')
->expectsOutput('Done!')
@ -218,6 +231,11 @@ class ApplyRulesTest extends TestCase
'--end_date=2019-01-01',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
@ -281,6 +299,11 @@ class ApplyRulesTest extends TestCase
sprintf('--rules=%d,%d', $activeRule->id, $inactiveRule->id),
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Will apply 1 rule(s) to 3 transaction(s).')
->expectsOutput('Done!')
@ -343,6 +366,11 @@ class ApplyRulesTest extends TestCase
sprintf('--rule_groups=%d,%d', $activeGroup->id, $inactiveGroup->id),
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput(sprintf('Will ignore inactive rule group #%d ("%s")', $inactiveGroup->id, $inactiveGroup->title))
// one rule out of 2 groups:
@ -379,6 +407,11 @@ class ApplyRulesTest extends TestCase
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Please use the --accounts option to indicate the accounts to apply rules to.')
->assertExitCode(1);
@ -417,6 +450,11 @@ class ApplyRulesTest extends TestCase
'--all_rules',
];
// mock Preferences Facade:
$pref = new Preference;
$pref->data = 'token';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token',null])->atLeast()->once()->andReturn($pref);
$this->artisan('firefly-iii:apply-rules ' . implode(' ', $parameters))
->expectsOutput('Please make sure all accounts in --accounts are asset accounts or liabilities.')
->assertExitCode(1);

View File

@ -22,6 +22,7 @@
namespace Tests\Unit\Console\Commands\Upgrade;
use Amount;
use FireflyConfig;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\Configuration;
@ -49,6 +50,11 @@ class BudgetLimitCurrencyTest extends TestCase
{
BudgetLimit::whereNull('transaction_currency_id')->forceDelete();
$false = new Configuration;
$false->data = false;
FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]);
$this->artisan('firefly-iii:bl-currency')
->expectsOutput('All budget limits are correct.')
->assertExitCode(0);
@ -74,6 +80,9 @@ class BudgetLimitCurrencyTest extends TestCase
FireflyConfig::shouldReceive('get')->withArgs(['4780_bl_currency', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['4780_bl_currency', true]);
$currency = $this->getEuro();
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($currency);
$this->artisan('firefly-iii:bl-currency')
->expectsOutput(
sprintf('Budget limit #%d (part of budget "%s") now has a currency setting (%s).',

View File

@ -49,6 +49,12 @@ class RenameAccountMetaTest extends TestCase
*/
public function testHandle(): void
{
$false = new Configuration;
$false->data = false;
// check config
FireflyConfig::shouldReceive('get')->withArgs(['4780_rename_account_meta', false])->andReturn($false);
FireflyConfig::shouldReceive('set')->withArgs(['4780_rename_account_meta', true]);
// assume all is well.
$this->artisan('firefly-iii:rename-account-meta')
->expectsOutput('All account meta is OK.')

View File

@ -24,10 +24,12 @@ declare(strict_types=1);
namespace Tests\Unit\Factory;
use Amount;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
use FireflyIII\Factory\AccountMetaFactory;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Factory\TransactionGroupFactory;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
@ -60,9 +62,11 @@ class AccountFactoryTest extends TestCase
*/
public function testCreate(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$euro = $this->getEuro();
$data = [
'account_type_id' => null,
'account_type' => 'asset',
@ -80,6 +84,8 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($euro);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -87,6 +93,8 @@ class AccountFactoryTest extends TestCase
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
return;
@ -110,9 +118,12 @@ class AccountFactoryTest extends TestCase
*/
public function testCreateCC(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$data = [
'account_type_id' => null,
'account_type' => 'asset',
@ -133,6 +144,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'cc_monthly_payment_date', '2018-01-01'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'cc_type', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -140,6 +152,8 @@ class AccountFactoryTest extends TestCase
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
return;
@ -163,8 +177,10 @@ class AccountFactoryTest extends TestCase
*/
public function testCreateEmptyVb(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$data = [
'account_type_id' => null,
@ -183,6 +199,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -190,6 +207,8 @@ class AccountFactoryTest extends TestCase
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
return;
@ -216,6 +235,8 @@ class AccountFactoryTest extends TestCase
{
$this->mock(AccountRepositoryInterface::class);
$this->mock(TransactionGroupFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$data = [
'account_type_id' => null,
@ -233,6 +254,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -240,6 +262,8 @@ class AccountFactoryTest extends TestCase
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
return;
@ -270,8 +294,9 @@ class AccountFactoryTest extends TestCase
{
$this->mock(AccountRepositoryInterface::class);
$this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$data = [
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$data = [
'account_type_id' => null,
'account_type' => 'Expense account',
'iban' => null,
@ -291,10 +316,13 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
return;
@ -322,10 +350,12 @@ class AccountFactoryTest extends TestCase
*/
public function testCreateOB(): void
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$data = [
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
$data = [
'account_type_id' => null,
'account_type' => 'asset',
'iban' => null,
@ -348,6 +378,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -378,10 +409,12 @@ class AccountFactoryTest extends TestCase
public function testCreateOBZero(): void
{
// mock repositories:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$data = [
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
$data = [
'account_type_id' => null,
'account_type' => 'asset',
'iban' => null,
@ -404,6 +437,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -438,6 +472,7 @@ class AccountFactoryTest extends TestCase
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$data = [
'account_type_id' => null,
@ -457,6 +492,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -490,6 +526,7 @@ class AccountFactoryTest extends TestCase
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$data = [
'account_type_id' => null,
@ -509,7 +546,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -543,6 +580,8 @@ class AccountFactoryTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$groupFactory = $this->mock(TransactionGroupFactory::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$euro = $this->getEuro();
$data = [
'account_type_id' => null,
'account_type' => 'asset',
@ -566,6 +605,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([1, ''])->atLeast()->once()->andReturn($euro);
/** @var AccountFactory $factory */
@ -600,6 +640,7 @@ class AccountFactoryTest extends TestCase
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$data = [
'account_type_id' => null,
@ -624,7 +665,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
try {
$account = $factory->create($data);
@ -656,6 +697,8 @@ class AccountFactoryTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$this->mock(TransactionGroupFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$currency = $this->getDollar();
$data = [
'account_type_id' => null,
@ -676,7 +719,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', $currency->id])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, 'USD'])->atLeast()->once()->andReturn($currency);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -710,6 +753,7 @@ class AccountFactoryTest extends TestCase
{
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$metaFactory = $this->mock(AccountMetaFactory::class);
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$this->mock(TransactionGroupFactory::class);
$currency = $this->getDollar();
$data = [
@ -731,7 +775,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', $currency->id])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'BIC', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([7, ''])->atLeast()->once()->andReturn($currency);
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
@ -858,6 +902,7 @@ class AccountFactoryTest extends TestCase
$metaFactory = $this->mock(AccountMetaFactory::class);
/** @var Account $account */
$account = $this->getRandomRevenue();
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'account_number', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'currency_id', '1'])->atLeast()->once()->andReturnNull();
@ -865,6 +910,7 @@ class AccountFactoryTest extends TestCase
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'include_net_worth', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest', ''])->atLeast()->once()->andReturnNull();
$metaFactory->shouldReceive('crud')->withArgs([Mockery::any(), 'interest_period', ''])->atLeast()->once()->andReturnNull();
$currencyFactory->shouldReceive('find')->withArgs([0, ''])->atLeast()->once()->andReturnNull();
$name = sprintf('New %s', $account->name);

File diff suppressed because it is too large Load Diff

View File

@ -68,6 +68,8 @@ class ClearNotesTest extends TestCase
try {
$result = $action->act($journal);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);

View File

@ -75,6 +75,8 @@ class ConvertToDepositTest extends TestCase
try {
$result = $action->act($journal);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);
@ -111,6 +113,8 @@ class ConvertToDepositTest extends TestCase
try {
$result = $action->act($journal);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);

View File

@ -64,7 +64,10 @@ class ConvertToTransferTest extends TestCase
// mock used stuff:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('findByName')->withArgs([$asset->name, [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]])->andReturn($asset);
$accountRepos->shouldReceive('findByName')->withArgs(
[$asset->name,
[AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]]
)->andReturn($asset);
// fire the action:
$rule = new Rule;
@ -77,6 +80,8 @@ class ConvertToTransferTest extends TestCase
try {
$result = $action->act($deposit);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);
@ -94,8 +99,10 @@ class ConvertToTransferTest extends TestCase
public function testActWithdrawal(): void
{
$withdrawal = $this->getRandomWithdrawal();
/** @var Account $asset */
$asset = $this->getRandomAsset();
// make sure that $asset is not the source account of $withdrawal:
$forbiddenId = (int)$withdrawal->transactions()->where('amount', '<', 0)->first()->account_id;
$asset = $this->getRandomAsset($forbiddenId);
// mock used stuff:
$accountRepos = $this->mock(AccountRepositoryInterface::class);
@ -113,6 +120,8 @@ class ConvertToTransferTest extends TestCase
try {
$result = $action->act($withdrawal);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);

View File

@ -75,6 +75,8 @@ class ConvertToWithdrawalTest extends TestCase
try {
$result = $action->act($deposit);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);
@ -108,6 +110,8 @@ class ConvertToWithdrawalTest extends TestCase
try {
$result = $action->act($transfer);
} catch (Exception $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result);

View File

@ -25,8 +25,6 @@ namespace Tests\Unit\Transformers;
use Carbon\Carbon;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
@ -81,9 +79,9 @@ class RecurrenceTransformerTest extends TestCase
$recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr');
$recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once();
$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);
$budgetRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($budget);
$piggyRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($piggy);
$billRepos->shouldReceive('find')->andReturn($bill);
// basic transformation: