New tests

This commit is contained in:
James Cole 2020-10-10 11:21:14 +02:00
parent 76cfdef27d
commit acfc976f6d
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
18 changed files with 199 additions and 237 deletions

View File

@ -81,6 +81,8 @@ class CorrectOpeningBalanceCurrenciesTest extends TestCase
->expectsOutput(sprintf('Transaction journal #%d has no valid account. Cant fix this line.', $journal->id))
//->expectsOutput('Cant fix this line.')
->assertExitCode(0);
$journal->forceDelete();
}
}

View File

@ -35,43 +35,16 @@ use Tests\TestCase;
/**
* Class CreateAccessTokensTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CreateAccessTokensTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateAccessTokens
*/
public function testHandle(): void
{
$users = new Collection([$this->user()]);
$repository = $this->mock(UserRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('all')->atLeast()->once()->andReturn($users);
// mock preferences thing:
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])
->once()->andReturn(null);
// null means user object will generate one and store it.
Preferences::shouldReceive('setForUser')->withArgs([Mockery::any(), 'access_token', Mockery::any()])
->once();
// remove preferences so token will be generated
Preference::where('name','access_token')->delete();
$this->artisan('firefly-iii:create-access-tokens')
->expectsOutput(sprintf('Generated access token for user %s', $this->user()->email))
@ -83,20 +56,11 @@ class CreateAccessTokensTest extends TestCase
*/
public function testHandlePrefExists(): void
{
$users = new Collection([$this->user()]);
$repository = $this->mock(UserRepositoryInterface::class);
// mock calls:
$repository->shouldReceive('all')->atLeast()->once()->andReturn($users);
// mock preferences thing:
$preference = new Preference;
$preference->data = '123';
Preferences::shouldReceive('getForUser')->withArgs([Mockery::any(), 'access_token', null])
->once()->andReturn($preference);
// null means user object will generate one and store it.
Preferences::shouldNotReceive('setForUser');
$preference->name = 'access_token';
$preference->user_id = $this->user()->id;
$preference->save();
$this->artisan('firefly-iii:create-access-tokens')
->expectsOutput('All access tokens OK!')

View File

@ -30,23 +30,9 @@ use Tests\TestCase;
/**
* Class CreateLinkTypesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CreateLinkTypesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\CreateLinkTypes

View File

@ -30,24 +30,9 @@ use Tests\TestCase;
/**
* Class DeleteEmptyGroupsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class DeleteEmptyGroupsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyGroups
*/

View File

@ -31,25 +31,9 @@ use Tests\TestCase;
/**
* Class DeleteEmptyJournalsTest
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class DeleteEmptyJournalsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteEmptyJournals
*/

View File

@ -32,24 +32,9 @@ use Tests\TestCase;
/**
* Class DeleteOrphanedTransactionsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class DeleteOrphanedTransactionsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteOrphanedTransactions
*/

View File

@ -31,24 +31,9 @@ use Tests\TestCase;
/**
* Class DeleteZeroAmountTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class DeleteZeroAmountTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\DeleteZeroAmount
*/

View File

@ -26,35 +26,18 @@ namespace Tests\Feature\Console\Commands\Correction;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionCurrency;
use Log;
use Tests\TestCase;
/**
* Class EnableCurrenciesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class EnableCurrenciesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\EnableCurrencies
*/
public function testHandle(): void
public function testHandleEnabled(): void
{
// assume the current database is intact.
$count = TransactionCurrency::where('enabled', 1)->count();
$this->artisan('firefly-iii:enable-currencies')
@ -71,10 +54,14 @@ class EnableCurrenciesTest extends TestCase
public function testHandleDisabled(): void
{
// find a disabled currency, update a budget limit with it.
$currency = TransactionCurrency::where('enabled', 0)->first();
/** @var BudgetLimit $budgetLimit */
$budgetLimit = BudgetLimit::inRandomOrder()->first();
$currency = TransactionCurrency::where('enabled', 0)->first();
$budget = $this->getRandomBudget();
$budgetLimit = new BudgetLimit;
$budgetLimit->transaction_currency_id = $currency->id;
$budgetLimit->budget_id = $budget->id;
$budgetLimit->start_date = '2020-01-01';
$budgetLimit->end_date = '2020-01-02';
$budgetLimit->amount = '4';
$budgetLimit->save();
// assume the current database is intact.
@ -85,6 +72,7 @@ class EnableCurrenciesTest extends TestCase
// assume its been enabled.
$this->assertCount($count + 1, TransactionCurrency::where('enabled', 1)->get());
$budgetLimit->forceDelete();
}
}

View File

@ -0,0 +1,47 @@
<?php
/*
* FixAccountOrderTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use DB;
use FireflyIII\Models\Account;
use Tests\TestCase;
class FixAccountOrderTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixAccountOrder
*/
public function testHandle(): void
{
// reset all asset accounts accounts:
Account::select()->update(['order' => 0]);
$this->artisan('firefly-iii:fix-account-order')
->assertExitCode(0);
$this->assertCount(0, Account::where('order', '=',0)->get());
}
}

View File

@ -29,36 +29,19 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType;
use Log;
use Tests\TestCase;
/**
* Class FixAccountTypesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FixAccountTypesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\FixAccountTypes
*/
public function testHandleUneven(): void
{
$this->mock(AccountFactory::class);
$source = $this->user()->accounts()->where('name', 'Another DUO Student loans')->first();
$source = $this->getRandomDebt();
$type = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
@ -91,8 +74,6 @@ class FixAccountTypesTest extends TestCase
*/
public function testHandle(): void
{
$this->mock(AccountFactory::class);
// assume there's nothing to fix.
$this->artisan('firefly-iii:fix-account-types')
->expectsOutput('All account types are OK!')
@ -107,8 +88,8 @@ class FixAccountTypesTest extends TestCase
public function testHandleWithdrawalLoanLoan(): void
{
$this->mock(AccountFactory::class);
$source = $this->user()->accounts()->where('name', 'Another DUO Student loans')->first();
$destination = $this->user()->accounts()->where('name', 'DUO Student loans')->first();
$source = $this->getRandomLoan();
$destination = $this->getRandomLoan($source->id);
$type = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
[
@ -143,8 +124,6 @@ class FixAccountTypesTest extends TestCase
->assertExitCode(0);
// since system cant handle this problem, dont look for changed transactions.
$one->forceDelete();
$two->forceDelete();
$journal->forceDelete();
@ -157,7 +136,7 @@ class FixAccountTypesTest extends TestCase
{
$this->mock(AccountFactory::class);
$source = $this->getRandomAsset();
$destination = $this->user()->accounts()->where('name', 'DUO Student loans')->first();
$destination = $this->getRandomLoan();
$type = TransactionType::where('type', TransactionType::TRANSFER)->first();
$withdrawal = TransactionType::where('type', TransactionType::WITHDRAWAL)->first();
$journal = TransactionJournal::create(
@ -205,7 +184,7 @@ class FixAccountTypesTest extends TestCase
public function testHandleTransferLoanAsset(): void
{
$this->mock(AccountFactory::class);
$source = $this->user()->accounts()->where('name', 'DUO Student loans')->first();
$source = $this->getRandomLoan();
$destination = $this->getRandomAsset();
$type = TransactionType::where('type', TransactionType::TRANSFER)->first();
$deposit = TransactionType::where('type', TransactionType::DEPOSIT)->first();

View File

@ -0,0 +1,48 @@
<?php
/*
* FixGroupAccountsTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use Tests\TestCase;
/**
* Class FixGroupAccountsTest
* @package Tests\Feature\Console\Commands\Correction
*/
class FixGroupAccountsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixGroupAccounts
*/
public function testHandle(): void
{
// basic group with multiple journals, should trigger event.
$this->artisan('firefly-iii:unify-group-accounts')
->expectsOutput('Updated inconsistent transaction groups.')
->assertExitCode(0);
// This just triggers the events. No real test.
}
}

View File

@ -0,0 +1,42 @@
<?php
/*
* FixLongDescriptionsTest.php
* Copyright (c) 2020 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Tests\Feature\Console\Commands\Correction;
use Tests\TestCase;
/**
* Class FixLongDescriptionsTest
*/
class FixLongDescriptionsTest extends TestCase
{
/**
* @covers \FireflyIII\Console\Commands\Correction\FixLongDescriptions
*/
public function testHandle(): void
{
$this->artisan('firefly-iii:fix-long-descriptions')
->expectsOutput('Verified all transaction group and journal title lengths')
->assertExitCode(0);
}
}

View File

@ -31,24 +31,9 @@ use Tests\TestCase;
/**
* Class FixPiggiesTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FixPiggiesTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* Null event.
*

View File

@ -32,23 +32,9 @@ use Tests\TestCase;
/**
* Class FixUnevenAmountTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class FixUnevenAmountTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\FixUnevenAmount

View File

@ -30,24 +30,10 @@ use Tests\TestCase;
/**
* Class RemoveBillsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class RemoveBillsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\RemoveBills
@ -67,7 +53,7 @@ class RemoveBillsTest extends TestCase
*/
public function testHandleWithdrawal(): void
{
$bill = $this->user()->bills()->first();
$bill = $this->getRandomBill();
$journal = $this->getRandomDeposit();
$journal->bill_id = $bill->id;

View File

@ -30,23 +30,9 @@ use Tests\TestCase;
/**
* Class RenameMetaFieldsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class RenameMetaFieldsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\RenameMetaFields

View File

@ -29,24 +29,9 @@ use Tests\TestCase;
/**
* Class TransferBudgetsTest
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class TransferBudgetsTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
self::markTestIncomplete('Incomplete for refactor.');
return;
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Console\Commands\Correction\TransferBudgets
*/
@ -63,7 +48,7 @@ class TransferBudgetsTest extends TestCase
public function testHandleBudget(): void
{
$deposit = $this->getRandomDeposit();
$budget = $this->user()->budgets()->inRandomOrder()->first();
$budget = $this->getRandomBudget();
$deposit->budgets()->save($budget);

View File

@ -182,6 +182,45 @@ trait CollectsValues
return $this->getRandomAccount(AccountType::ASSET, $except);
}
/**
* @param int|null $except
*
* @return Account
*/
public function getRandomDebt(?int $except = null): Account
{
return $this->getRandomAccount(AccountType::DEBT, $except);
}
/**
* @param int|null $except
*
* @return Account
*/
public function getRandomLoan(?int $except = null): Account
{
return $this->getRandomAccount(AccountType::LOAN, $except);
}
/**
* @param int|null $except
*
* @return Account
*/
public function getRandomRevenue(?int $except = null): Account
{
return $this->getRandomAccount(AccountType::REVENUE, $except);
}
/**
* @param int|null $except
*
* @return Account
*/
public function getRandomExpense(?int $except = null): Account
{
return $this->getRandomAccount(AccountType::EXPENSE, $except);
}
/**
* @param string $type
*