From 4c10f2b9601190d45c4fe31a6223c865862a1cfb Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 18 Oct 2020 08:01:22 +0200 Subject: [PATCH] Test improv --- .../Correction/FixLongDescriptions.php | 3 +- .../Correction/FixRecurringTransactions.php | 2 +- .../Correction/FixGroupAccountsTest.php | 1 - .../Correction/FixLongDescriptionsTest.php | 33 ++++++++++++- .../FixRecurringTransactionsTest.php | 48 +++++++++++++++++++ .../Correction/FixTransactionTypesTest.php | 45 +++++++++++++++++ tests/Traits/CollectsValues.php | 2 +- 7 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 tests/Feature/Console/Commands/Correction/FixRecurringTransactionsTest.php create mode 100644 tests/Feature/Console/Commands/Correction/FixTransactionTypesTest.php diff --git a/app/Console/Commands/Correction/FixLongDescriptions.php b/app/Console/Commands/Correction/FixLongDescriptions.php index e05e957ccc..bcc5288ff1 100644 --- a/app/Console/Commands/Correction/FixLongDescriptions.php +++ b/app/Console/Commands/Correction/FixLongDescriptions.php @@ -76,7 +76,8 @@ class FixLongDescriptions extends Command } } $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Verified all transaction group and journal title lengths in %s seconds.', $end)); + $this->info('Verified all transaction group and journal title lengths.'); + $this->info(sprintf('Took %s seconds.', $end)); return 0; } diff --git a/app/Console/Commands/Correction/FixRecurringTransactions.php b/app/Console/Commands/Correction/FixRecurringTransactions.php index 01b5f9cdb6..6d3b9b0452 100644 --- a/app/Console/Commands/Correction/FixRecurringTransactions.php +++ b/app/Console/Commands/Correction/FixRecurringTransactions.php @@ -68,7 +68,7 @@ class FixRecurringTransactions extends Command $end = round(microtime(true) - $start, 2); - $this->info(sprintf('Corrected recurring transactions %s seconds.', $end)); + $this->info(sprintf('Corrected recurring transactions in %s seconds.', $end)); return 0; } diff --git a/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php b/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php index 74b98d187b..3f99bcc1ae 100644 --- a/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php +++ b/tests/Feature/Console/Commands/Correction/FixGroupAccountsTest.php @@ -26,7 +26,6 @@ use Tests\TestCase; /** * Class FixGroupAccountsTest - * @package Tests\Feature\Console\Commands\Correction */ class FixGroupAccountsTest extends TestCase { diff --git a/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php b/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php index 87498cddb6..bb11bc03d9 100644 --- a/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php +++ b/tests/Feature/Console/Commands/Correction/FixLongDescriptionsTest.php @@ -34,9 +34,40 @@ class FixLongDescriptionsTest extends TestCase */ public function testHandle(): void { + $journal = $this->getRandomWithdrawal(); + $original = $journal->description; + $journal->description = str_repeat('ABCDEF123456x', 200); + $journal->save(); + + $this->artisan('firefly-iii:fix-long-descriptions') - ->expectsOutput('Verified all transaction group and journal title lengths') + ->expectsOutput(sprintf('Truncated description of transaction journal #%d', $journal->id)) + ->expectsOutput('Verified all transaction group and journal title lengths.') ->assertExitCode(0); + + $journal->description = $original; + $journal->save(); + } + + /** + * @covers \FireflyIII\Console\Commands\Correction\FixLongDescriptions + */ + public function testHandleGroup(): void + { + $journal = $this->getRandomWithdrawal(); + $group = $journal->transactionGroup; + $original = $group->title; + $group->title = str_repeat('ABCDEF123456x', 200); + $group->save(); + + + $this->artisan('firefly-iii:fix-long-descriptions') + ->expectsOutput(sprintf('Truncated description of transaction group #%d', $group->id)) + ->expectsOutput('Verified all transaction group and journal title lengths.') + ->assertExitCode(0); + + $group->title = $original; + $group->save(); } } \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/FixRecurringTransactionsTest.php b/tests/Feature/Console/Commands/Correction/FixRecurringTransactionsTest.php new file mode 100644 index 0000000000..e1d296dfbd --- /dev/null +++ b/tests/Feature/Console/Commands/Correction/FixRecurringTransactionsTest.php @@ -0,0 +1,48 @@ +. + */ + +namespace Tests\Feature\Console\Commands\Correction; + + +use FireflyIII\Models\Recurrence; +use Tests\TestCase; + +/** + * Class FixRecurringTransactionsTest + */ +class FixRecurringTransactionsTest extends TestCase +{ + /** + * @covers \FireflyIII\Console\Commands\Correction\FixRecurringTransactions + */ + public function testHandle(): void + { + // test DB contains a broken recurring transaction. + $recurring = Recurrence::whereTitle('broken_recurrence')->first(); + + + $this->artisan('firefly-iii:fix-recurring-transactions') + ->expectsOutput(sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.', + $recurring->id, 'Withdrawal','Transfer', + )) + ->assertExitCode(0); + } +} \ No newline at end of file diff --git a/tests/Feature/Console/Commands/Correction/FixTransactionTypesTest.php b/tests/Feature/Console/Commands/Correction/FixTransactionTypesTest.php new file mode 100644 index 0000000000..c9fd055109 --- /dev/null +++ b/tests/Feature/Console/Commands/Correction/FixTransactionTypesTest.php @@ -0,0 +1,45 @@ +. + */ + +namespace Tests\Feature\Console\Commands\Correction; + + +use Tests\TestCase; + +/** + * Class FixTransactionTypesTest + */ +class FixTransactionTypesTest extends TestCase +{ + /** + * @covers \FireflyIII\Console\Commands\Correction\FixTransactionTypes + */ + public function testHandle(): void + { + $this->artisan('firefly-iii:fix-transaction-types') + ->expectsOutput(sprintf('Recurring transaction #%d should be a "%s" but is a "%s" and will be corrected.', + $recurring->id, 'Withdrawal','Transfer', + )) + ->assertExitCode(0); + } + + +} \ No newline at end of file diff --git a/tests/Traits/CollectsValues.php b/tests/Traits/CollectsValues.php index c2bd7f9103..88673c3f6d 100644 --- a/tests/Traits/CollectsValues.php +++ b/tests/Traits/CollectsValues.php @@ -149,7 +149,7 @@ trait CollectsValues ] )->first(); if (null === $result) { - throw new FireflyException(sprintf('Cannot find suitable %s to use.', $type)); + throw new FireflyException(sprintf('Cannot find suitable journal "%s" to use.', $type)); } return TransactionJournal::find((int) $result->transaction_journal_id);