diff --git a/tests/Feature/Console/Commands/Correction/CorrectOpeningBalanceCurrenciesTest.php b/tests/Feature/Console/Commands/Correction/CorrectOpeningBalanceCurrenciesTest.php index 8c7f2aa4b5..f9bdb24f1a 100644 --- a/tests/Feature/Console/Commands/Correction/CorrectOpeningBalanceCurrenciesTest.php +++ b/tests/Feature/Console/Commands/Correction/CorrectOpeningBalanceCurrenciesTest.php @@ -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(); } } \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/CreateAccessTokensTest.php b/tests/Feature/Console/Commands/Correction/CreateAccessTokensTest.php index bb8de82483..f8cbb8ecd0 100644 --- a/tests/Feature/Console/Commands/Correction/CreateAccessTokensTest.php +++ b/tests/Feature/Console/Commands/Correction/CreateAccessTokensTest.php @@ -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!') diff --git a/tests/Feature/Console/Commands/Correction/CreateLinkTypesTest.php b/tests/Feature/Console/Commands/Correction/CreateLinkTypesTest.php index 3233a1b8b9..119b5dfa6b 100644 --- a/tests/Feature/Console/Commands/Correction/CreateLinkTypesTest.php +++ b/tests/Feature/Console/Commands/Correction/CreateLinkTypesTest.php @@ -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 diff --git a/tests/Feature/Console/Commands/Correction/DeleteEmptyGroupsTest.php b/tests/Feature/Console/Commands/Correction/DeleteEmptyGroupsTest.php index dba0eadc02..c188ca47fb 100644 --- a/tests/Feature/Console/Commands/Correction/DeleteEmptyGroupsTest.php +++ b/tests/Feature/Console/Commands/Correction/DeleteEmptyGroupsTest.php @@ -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 */ diff --git a/tests/Feature/Console/Commands/Correction/DeleteEmptyJournalsTest.php b/tests/Feature/Console/Commands/Correction/DeleteEmptyJournalsTest.php index ddc379ba81..3c99313209 100644 --- a/tests/Feature/Console/Commands/Correction/DeleteEmptyJournalsTest.php +++ b/tests/Feature/Console/Commands/Correction/DeleteEmptyJournalsTest.php @@ -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 */ diff --git a/tests/Feature/Console/Commands/Correction/DeleteOrphanedTransactionsTest.php b/tests/Feature/Console/Commands/Correction/DeleteOrphanedTransactionsTest.php index 6e14ee13cc..a837a2e93e 100644 --- a/tests/Feature/Console/Commands/Correction/DeleteOrphanedTransactionsTest.php +++ b/tests/Feature/Console/Commands/Correction/DeleteOrphanedTransactionsTest.php @@ -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 */ diff --git a/tests/Feature/Console/Commands/Correction/DeleteZeroAmountTest.php b/tests/Feature/Console/Commands/Correction/DeleteZeroAmountTest.php index 11dc068ed2..0642eca92b 100644 --- a/tests/Feature/Console/Commands/Correction/DeleteZeroAmountTest.php +++ b/tests/Feature/Console/Commands/Correction/DeleteZeroAmountTest.php @@ -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 */ diff --git a/tests/Feature/Console/Commands/Correction/EnableCurrenciesTest.php b/tests/Feature/Console/Commands/Correction/EnableCurrenciesTest.php index 4661988609..4ecbaca911 100644 --- a/tests/Feature/Console/Commands/Correction/EnableCurrenciesTest.php +++ b/tests/Feature/Console/Commands/Correction/EnableCurrenciesTest.php @@ -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(); } } diff --git a/tests/Feature/Console/Commands/Correction/FixAccountOrderTest.php b/tests/Feature/Console/Commands/Correction/FixAccountOrderTest.php new file mode 100644 index 0000000000..805f01ea0f --- /dev/null +++ b/tests/Feature/Console/Commands/Correction/FixAccountOrderTest.php @@ -0,0 +1,47 @@ +. + */ + +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()); + + } + +} \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/FixAccountTypesTest.php b/tests/Feature/Console/Commands/Correction/FixAccountTypesTest.php index 43f5f384fb..336264486a 100644 --- a/tests/Feature/Console/Commands/Correction/FixAccountTypesTest.php +++ b/tests/Feature/Console/Commands/Correction/FixAccountTypesTest.php @@ -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(); diff --git a/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php b/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php new file mode 100644 index 0000000000..74b98d187b --- /dev/null +++ b/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php @@ -0,0 +1,48 @@ +. + */ + +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. + } + + +} \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php b/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php new file mode 100644 index 0000000000..87498cddb6 --- /dev/null +++ b/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php @@ -0,0 +1,42 @@ +. + */ + +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); + } + +} \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/FixPiggiesTest.php b/tests/Feature/Console/Commands/Correction/FixPiggiesTest.php index 1c3874561d..7b59548792 100644 --- a/tests/Feature/Console/Commands/Correction/FixPiggiesTest.php +++ b/tests/Feature/Console/Commands/Correction/FixPiggiesTest.php @@ -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. * diff --git a/tests/Feature/Console/Commands/Correction/FixUnevenAmountTest.php b/tests/Feature/Console/Commands/Correction/FixUnevenAmountTest.php index 367dce8ec3..cab85a0cb2 100644 --- a/tests/Feature/Console/Commands/Correction/FixUnevenAmountTest.php +++ b/tests/Feature/Console/Commands/Correction/FixUnevenAmountTest.php @@ -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 diff --git a/tests/Feature/Console/Commands/Correction/RemoveBillsTest.php b/tests/Feature/Console/Commands/Correction/RemoveBillsTest.php index fe138d1214..510bda424d 100644 --- a/tests/Feature/Console/Commands/Correction/RemoveBillsTest.php +++ b/tests/Feature/Console/Commands/Correction/RemoveBillsTest.php @@ -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; diff --git a/tests/Feature/Console/Commands/Correction/RenameMetaFieldsTest.php b/tests/Feature/Console/Commands/Correction/RenameMetaFieldsTest.php index fbeba24e14..444dd506a6 100644 --- a/tests/Feature/Console/Commands/Correction/RenameMetaFieldsTest.php +++ b/tests/Feature/Console/Commands/Correction/RenameMetaFieldsTest.php @@ -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 diff --git a/tests/Feature/Console/Commands/Correction/TransferBudgetsTest.php b/tests/Feature/Console/Commands/Correction/TransferBudgetsTest.php index 7aa3d2659d..e3621b8620 100644 --- a/tests/Feature/Console/Commands/Correction/TransferBudgetsTest.php +++ b/tests/Feature/Console/Commands/Correction/TransferBudgetsTest.php @@ -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); diff --git a/tests/Traits/CollectsValues.php b/tests/Traits/CollectsValues.php index 558578037e..c2bd7f9103 100644 --- a/tests/Traits/CollectsValues.php +++ b/tests/Traits/CollectsValues.php @@ -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 *