Improve test coverage.

This commit is contained in:
James Cole 2017-03-21 20:46:14 +01:00
parent ab9146b7c6
commit 477acafc4c
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 66 additions and 43 deletions

View File

@ -101,11 +101,12 @@ class CategoryControllerTest extends TestCase
public function testIndex()
{
// mock stuff
$category = factory(Category::class)->make();
$repository = $this->mock(CategoryRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('getCategories')->andReturn(new Collection);
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon);
$repository->shouldReceive('getCategories')->andReturn(new Collection([$category]))->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$this->be($this->user());
$response = $this->get(route('categories.index'));
@ -220,47 +221,6 @@ class CategoryControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @covers \FireflyIII\Http\Controllers\CategoryController::getPeriodOverview
*
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowEmpty(string $range)
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// mock stuff
$repository = $this->mock(CategoryRepositoryInterface::class);
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('setCategory')->andReturnSelf()->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.show', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @covers \FireflyIII\Http\Controllers\CategoryController::getPeriodOverview
@ -379,6 +339,47 @@ class CategoryControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @covers \FireflyIII\Http\Controllers\CategoryController::getPeriodOverview
*
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowEmpty(string $range)
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
// mock stuff
$repository = $this->mock(CategoryRepositoryInterface::class);
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
$repository->shouldReceive('spentInPeriod')->andReturn('0');
$repository->shouldReceive('earnedInPeriod')->andReturn('0');
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setPage')->andReturnSelf()->times(3);
$collector->shouldReceive('setLimit')->andReturnSelf()->times(3);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->times(3);
$collector->shouldReceive('setRange')->andReturnSelf()->times(3);
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withCategoryInformation')->andReturnSelf()->times(3);
$collector->shouldReceive('withOpposingAccount')->andReturnSelf()->times(3);
$collector->shouldReceive('setCategory')->andReturnSelf()->times(3);
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->times(3);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.show', [1]));
$response->assertStatus(200);
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::store
*/

View File

@ -43,8 +43,30 @@ class NewUserControllerTest extends TestCase
$response->assertSee('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\NewUserController::index
* @covers \FireflyIII\Http\Controllers\NewUserController::__construct
*/
public function testIndexExisting()
{
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(1);
$this->be($this->user());
$response = $this->get(route('new-user.index'));
$response->assertStatus(302);
$response->assertRedirect(route('index'));
}
/**
* @covers \FireflyIII\Http\Controllers\NewUserController::submit
* @covers \FireflyIII\Http\Controllers\NewUserController::createAssetAccount
* @covers \FireflyIII\Http\Controllers\NewUserController::createSavingsAccount
* @covers \FireflyIII\Http\Controllers\NewUserController::storeCreditCard
*/
public function testSubmit()
{