mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-22 17:06:39 -06:00
Fix final tests
This commit is contained in:
parent
1e4f4907e3
commit
02370fb65d
@ -48,35 +48,18 @@ class TransactionMatcher
|
|||||||
private $range = 200;
|
private $range = 200;
|
||||||
/** @var Rule The rule to apply */
|
/** @var Rule The rule to apply */
|
||||||
private $rule;
|
private $rule;
|
||||||
|
/** @var bool */
|
||||||
|
private $strict;
|
||||||
/** @var array Types that can be matched using this matcher */
|
/** @var array Types that can be matched using this matcher */
|
||||||
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
private $transactionTypes = [TransactionType::DEPOSIT, TransactionType::WITHDRAWAL, TransactionType::TRANSFER];
|
||||||
/** @var array List of triggers to match */
|
/** @var array List of triggers to match */
|
||||||
private $triggers = [];
|
private $triggers = [];
|
||||||
/** @var bool */
|
|
||||||
private $strict;
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->strict = false;
|
$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
|
* 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
|
* 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
|
// Variables used within the loop
|
||||||
$processor = Processor::make($this->rule, false);
|
/** @var Processor $processor */
|
||||||
$result = $this->runProcessor($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
|
// 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
|
// (e.g. if a large percentage of the transactions match), truncate the list
|
||||||
@ -202,6 +187,22 @@ class TransactionMatcher
|
|||||||
return $this;
|
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
|
* Set rule
|
||||||
*
|
*
|
||||||
|
@ -24,8 +24,10 @@ declare(strict_types=1);
|
|||||||
namespace Tests\Feature\Controllers\Recurring;
|
namespace Tests\Feature\Controllers\Recurring;
|
||||||
|
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Models\TransactionCurrency;
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Log;
|
use Log;
|
||||||
@ -46,10 +48,13 @@ class CreateControllerTest extends TestCase
|
|||||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreate() {
|
/**
|
||||||
$recurringRepos =$this->mock(RecurringRepositoryInterface::class);
|
* @covers \FireflyIII\Http\Controllers\Recurring\CreateController
|
||||||
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
*/
|
||||||
|
public function testCreate(): void
|
||||||
|
{
|
||||||
|
$recurringRepos = $this->mock(RecurringRepositoryInterface::class);
|
||||||
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
$budgetRepos->shouldReceive('getActiveBudgets')->andReturn(new Collection)->once();
|
||||||
\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
|
\Amount::shouldReceive('getDefaultCurrency')->andReturn(TransactionCurrency::find(1));
|
||||||
|
|
||||||
@ -59,4 +64,52 @@ class CreateControllerTest extends TestCase
|
|||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertSee('<ol class="breadcrumb">');
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user