Improve tests.

This commit is contained in:
James Cole
2018-12-17 07:09:44 +01:00
parent 89942ee49c
commit 454b3ebd97
19 changed files with 494 additions and 375 deletions

View File

@@ -28,6 +28,7 @@ use FireflyIII\Models\Configuration;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Transformers\RecurrenceTransformer;
use Illuminate\Support\Collection;
use Log;
use Mockery;
@@ -58,14 +59,20 @@ class IndexControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$categoryFactory->shouldReceive('setUser')->atLeast()->once();
$categoryFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn(null);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' =>null,
'latest_date' => null,
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('findNull')->withAnyArgs()->andReturn($this->user()->budgets()->first())->atLeast()->once();
$config = new Configuration;
$config->data = 0;
@@ -79,10 +86,6 @@ class IndexControllerTest extends TestCase
\FireflyConfig::shouldReceive('get')->withArgs(['is_demo_site', false])->once()->andReturn($falseConfig);
$repository->shouldReceive('get')->andReturn($collection)->once();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$this->be($this->user());
@@ -97,20 +100,24 @@ class IndexControllerTest extends TestCase
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$categoryFactory = $this->mock(CategoryFactory::class);
$transformer = $this->mock(RecurrenceTransformer::class);
$categoryFactory->shouldReceive('setUser')->atLeast()->once();
$categoryFactory->shouldReceive('findOrCreate')->atLeast()->once()->andReturn(null);
$transformer->shouldReceive('setParameters')->atLeast()->once();
$transformer->shouldReceive('transform')->atLeast()->once()->andReturn(
[
'id' => 5,
'first_date' => '2018-01-01',
'repeat_until' =>null,
'latest_date' => null,
'recurrence_repetitions' => [],
]
);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$budgetRepos->shouldReceive('findNull')->withAnyArgs()->andReturn($this->user()->budgets()->first())->atLeast()->once();
$recurrence = $this->user()->recurrences()->first();
$repository->shouldReceive('setUser');
$repository->shouldReceive('getNoteText')->andReturn('Notes');
$repository->shouldReceive('repetitionDescription')->andReturn('Bla');
$repository->shouldReceive('getXOccurrences')->andReturn([]);
$repository->shouldReceive('getTransactions')->andReturn(new Collection);
$repository->shouldReceive('getTransactions')->andReturn(new Collection)->atLeast()->once();
$this->be($this->user());
$response = $this->get(route('recurring.show', [$recurrence->id]));