Skip to content

Firefly III: a personal finances manager

Test improv

James Cole4c10f2b96011
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(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('Verified all transaction group and journal title lengths')
+ ->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 @@
+<?php
+/*
+ * FixRecurringTransactionsTest.php
+ * Copyright (c) 2020 [email protected]
+ *
+ * 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 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 @@
+<?php
+/*
+ * FixTransactionTypesTest.php
+ * Copyright (c) 2020 [email protected]
+ *
+ * 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 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);