Revamped a part of the rule test code.

- clean way of constructing triggers
- processor can be constructed in a number of ways.
- cleaner transaction matcher using collections instead of arrays
This commit is contained in:
James Cole
2016-02-17 21:03:59 +01:00
parent 1cf0125d1b
commit 6c22bad77a
5 changed files with 178 additions and 83 deletions

View File

@@ -267,13 +267,23 @@ class RuleController extends Controller
*/
public function testTriggers(TestRuleFormRequest $request)
{
$triggers = [
// build trigger array from response TODO move to function:
$triggers = [];
$data = [
'rule-triggers' => $request->get('rule-trigger'),
'rule-trigger-values' => $request->get('rule-trigger-value'),
'rule-trigger-stop' => $request->get('rule-trigger-stop'),
];
foreach ($data['rule-triggers'] as $index => $triggerType) {
$triggers[] = [
'type' => $triggerType,
'value' => $data['rule-trigger-values'][$index],
'stopProcessing' => intval($data['rule-trigger-stop'][$index]) === 1 ? true : false,
];
}
if (count($triggers['rule-triggers']) == 0) {
if (count($triggers) == 0) {
return Response::json(['html' => '', 'warning' => trans('firefly.warning_no_valid_triggers')]);
}
@@ -281,12 +291,15 @@ class RuleController extends Controller
$range = Config::get('firefly.test-triggers.range');
$matcher = new TransactionMatcher;
$matcher->setLimit($limit);
$matcher->setRange($range);
$matcher->setTriggers($triggers);
$matchingTransactions = $matcher->findMatchingTransactions();
// Dispatch the actual work to a matched object
$matchingTransactions
= (new TransactionMatcher($triggers))
->setTransactionLimit($range)
->findMatchingTransactions($limit);
// $matchingTransactions
// = (new TransactionMatcher($triggers))
// ->setTransactionLimit($range)
// ->findMatchingTransactions($limit);
// Warn the user if only a subset of transactions is returned
if (count($matchingTransactions) == $limit) {