Fix final tests

This commit is contained in:
James Cole 2018-09-01 20:45:05 +02:00
parent 1e4f4907e3
commit 02370fb65d
2 changed files with 79 additions and 25 deletions

View File

@ -48,35 +48,18 @@ class TransactionMatcher
private $range = 200;
/** @var Rule The rule to apply */
private $rule;
/** @var bool */
private $strict;
/** @var array Types that can be matched using this matcher */
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
/** @var array List of triggers to match */
private $triggers = [];
/** @var bool */
private $strict;
public function __construct()
{
$this->strict = false;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* This method will search the user's transaction journal (with an upper limit of $range) for
* transaction journals matching the given rule. This is accomplished by trying to fire these
@ -92,8 +75,10 @@ class TransactionMatcher
}
// Variables used within the loop
$processor = Processor::make($this->rule, false);
$result = $this->runProcessor($processor);
/** @var Processor $processor */
$processor = app(Processor::class);
$processor->make($this->rule, false);
$result = $this->runProcessor($processor);
// If the list of matchingTransactions is larger than the maximum number of results
// (e.g. if a large percentage of the transactions match), truncate the list
@ -202,6 +187,22 @@ class TransactionMatcher
return $this;
}
/**
* @return bool
*/
public function isStrict(): bool
{
return $this->strict;
}
/**
* @param bool $strict
*/
public function setStrict(bool $strict): void
{
$this->strict = $strict;
}
/**
* Set rule
*

View File

@ -24,8 +24,10 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Recurring;
use Carbon\Carbon;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
@ -46,10 +48,13 @@ class CreateControllerTest extends TestCase
Log::debug(sprintf('Now in %s.', \get_class($this)));
}
public function testCreate() {
$recurringRepos =$this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
/**
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
*/
public function testCreate(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
@ -59,4 +64,52 @@ class CreateControllerTest extends TestCase
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
* @covers \FireflyIII\Http\Requests\RecurrenceFormRequest
*/
public function testStore(): void
{
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$tomorrow = Carbon::create()->addDays(2);
$recurrence = $this->user()->recurrences()->first();
$data = [
'title' => 'hello',
'first_date' => $tomorrow->format('Y-m-d'),
'repetition_type' => 'daily',
'skip' => 0,
'recurring_description' => 'Some descr',
'active' => '1',
'apply_rules' => '1',
// mandatory for transaction:
'transaction_description' => 'Some descr',
'transaction_type' => 'withdrawal',
'transaction_currency_id' => '1',
'amount' => '30',
// mandatory account info:
'source_id' => '1',
'source_name' => '',
'destination_id' => '',
'destination_name' => 'Some Expense',
// optional fields:
'budget_id' => '1',
'category' => 'CategoryA',
'tags' => 'A,B,C',
'repetition_end' => 'times',
'repetitions' => 3,
];
$recurringRepos->shouldReceive('store')->andReturn($recurrence)->once();
$this->be($this->user());
$response = $this->post(route('recurring.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
}
}