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

@@ -92,24 +92,6 @@ class ApplyRules extends Command
/** @var RuleGroupRepositoryInterface */
private $ruleGroupRepository;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->allRules = false;
$this->accounts = new Collection;
$this->ruleSelection = [];
$this->ruleGroupSelection = [];
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->acceptedAccounts = [AccountType::DEFAULT, AccountType::DEBT, AccountType::ASSET, AccountType::LOAN, AccountType::MORTGAGE];
$this->groups = new Collection;
}
/**
* Execute the console command.
*
@@ -118,6 +100,7 @@ class ApplyRules extends Command
*/
public function handle(): int
{
$this->stupidLaravel();
// @codeCoverageIgnoreStart
if (!$this->verifyAccessToken()) {
$this->error('Invalid access token.');
@@ -183,6 +166,25 @@ class ApplyRules 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->allRules = false;
$this->accounts = new Collection;
$this->ruleSelection = [];
$this->ruleGroupSelection = [];
$this->ruleRepository = app(RuleRepositoryInterface::class);
$this->ruleGroupRepository = app(RuleGroupRepositoryInterface::class);
$this->acceptedAccounts = [AccountType::DEFAULT, AccountType::DEBT, AccountType::ASSET, AccountType::LOAN, AccountType::MORTGAGE];
$this->groups = new Collection;
}
/**
* @return bool
* @throws FireflyException