Finish command tests

This commit is contained in:
James Cole
2019-06-13 15:48:35 +02:00
parent 6bcb2ec144
commit 6964424bdc
29 changed files with 783 additions and 531 deletions

View File

@@ -69,7 +69,7 @@ class CorrectDatabase extends Command
'firefly-iii:delete-empty-journals',
'firefly-iii:delete-empty-groups',
'firefly-iii:fix-account-types',
'firefly-iii:rename-meta-fields'
'firefly-iii:rename-meta-fields',
];
foreach ($commands as $command) {
$this->line(sprintf('Now executing %s', $command));

View File

@@ -58,7 +58,7 @@ class CreateAccessTokens extends Command
$start = microtime(true);
$count = 0;
$users= $repository->all();
$users = $repository->all();
/** @var User $user */
foreach ($users as $user) {
$pref = app('preferences')->getForUser($user, 'access_token', null);

View File

@@ -47,12 +47,12 @@ class DeleteEmptyGroups extends Command
/**
* Execute the console command.
*
* @throws Exception;
* @return mixed
* @throws Exception;
*/
public function handle(): int
{
$start = microtime(true);
$start = microtime(true);
$groups = array_unique(TransactionJournal::get(['transaction_group_id'])->pluck('transaction_group_id')->toArray());
$count = TransactionGroup::whereNull('deleted_at')->whereNotIn('id', $groups)->count();
if (0 === $count) {

View File

@@ -22,10 +22,10 @@
namespace FireflyIII\Console\Commands\Correction;
use DB;
use Exception;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Exception;
use Log;
/**
@@ -105,7 +105,7 @@ class DeleteEmptyJournals extends Command
try {
TransactionJournal::find((int)$row->transaction_journal_id)->delete();
// @codeCoverageIgnoreStart
} catch(Exception $e) {
} catch (Exception $e) {
Log::info(sprintf('Could not delete journal: %s', $e->getMessage()));
}
// @codeCoverageIgnoreEnd

View File

@@ -21,11 +21,11 @@
namespace FireflyIII\Console\Commands\Correction;
use FireflyIII\Models\TransactionJournal;
use Exception;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Exception;
/**
* Class DeleteZeroAmount
@@ -52,8 +52,8 @@ class DeleteZeroAmount extends Command
public function handle(): int
{
$start = microtime(true);
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$set = array_unique($set);
$set = Transaction::where('amount', 0)->get(['transaction_journal_id'])->pluck('transaction_journal_id')->toArray();
$set = array_unique($set);
/** @var Collection $journals */
$journals = TransactionJournal::whereIn('id', $set)->get();
/** @var TransactionJournal $journal */
@@ -74,6 +74,7 @@ class DeleteZeroAmount extends Command
$end = round(microtime(true) - $start, 2);
$this->info(sprintf('Verified zero-amount integrity in %s seconds', $end));
return 0;
}
}

View File

@@ -55,15 +55,6 @@ class FixAccountTypes extends Command
/** @var int */
private $count;
/**
* FixAccountTypes constructor.
*/
public function __construct()
{
parent::__construct();
$this->count = 0;
}
/**
* Execute the console command.
*
@@ -72,6 +63,7 @@ class FixAccountTypes extends Command
*/
public function handle(): int
{
$this->stupidLaravel();
$start = microtime(true);
$this->factory = app(AccountFactory::class);
// some combinations can be fixed by this script:
@@ -110,6 +102,18 @@ class FixAccountTypes extends Command
return 0;
}
/**
* Laravel will execute ALL __construct() methods for ALL commands whenever a SINGLE command is
* executed. This leads to noticeable slow-downs and class calls. To prevent this, this method should
* be called from the handle method instead of using the constructor to initialize the command.
*
* @codeCoverageIgnore
*/
private function stupidLaravel(): void
{
$this->count = 0;
}
/**
* @param TransactionJournal $journal
* @param string $type

View File

@@ -22,7 +22,6 @@
namespace FireflyIII\Console\Commands\Correction;
use DB;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Console\Command;
@@ -93,7 +92,7 @@ class FixUnevenAmount extends Command
// fix amount of destination:
/** @var Transaction $destination */
$destination = $journal->transactions()->where('amount', '>', 0)->first();
$destination = $journal->transactions()->where('amount', '>', 0)->first();
$destination->amount = $amount;
$destination->save();

View File

@@ -66,7 +66,7 @@ class TransferBudgets extends Command
if (0 === $count) {
$this->info('No invalid budget/journal entries.');
}
if(0 !== $count) {
if (0 !== $count) {
$this->line(sprintf('Corrected %d invalid budget/journal entries (entry).', $count));
}
$end = round(microtime(true) - $start, 2);