Fix tests, improve coverage.

This commit is contained in:
James Cole 2018-06-02 06:11:13 +02:00
parent 790aeb3c46
commit ddc1d81665
4 changed files with 38 additions and 7 deletions

View File

@ -107,7 +107,7 @@ class LinkController extends Controller
return redirect(route('transactions.show', [$journal->id]));
}
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
$other = $this->journalRepository->findNull($linkInfo['transaction_journal_id']);
$alreadyLinked = $this->repository->findLink($journal, $other);
if ($other->id === $journal->id) {

View File

@ -104,7 +104,9 @@ class Authenticate
}
}
} catch (QueryException $e) {
// @codeCoverageIgnoreStart
throw new FireflyException('It seems the database has not yet been initialized. Did you run the correct upgrade or installation commands?');
// @codeCoverageIgnoreEnd
}
return $this->auth->authenticate();

View File

@ -156,10 +156,10 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(2);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(2);
$repository->shouldReceive('sumsOfTag')->andReturn($amounts)->once();
$collector->shouldReceive('removeFilter')->andReturnSelf()->once();
@ -225,10 +225,10 @@ class TagControllerTest extends TestCase
$collector = $this->mock(JournalCollectorInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->once();
$repository->shouldReceive('spentInPeriod')->andReturn('-1')->times(2);
$repository->shouldReceive('firstUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('lastUseDate')->andReturn(new Carbon)->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->once();
$repository->shouldReceive('earnedInPeriod')->andReturn('1')->times(2);
$collector->shouldReceive('removeFilter')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();

View File

@ -95,7 +95,7 @@ class LinkControllerTest extends TestCase
];
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('findNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('findLink')->andReturn(false);
$repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink);
@ -107,6 +107,35 @@ class LinkControllerTest extends TestCase
$response->assertRedirect(route('transactions.show', [1]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
* @covers \FireflyIII\Http\Requests\JournalLinkRequest
*/
public function testStoreSame(): void
{
$repository = $this->mock(LinkTypeRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$data = [
'link_other' => 8,
'link_type' => '1_inward',
];
$journal = $this->user()->transactionJournals()->first();
$journalRepos->shouldReceive('firstNull')->andReturn($journal);
$journalRepos->shouldReceive('findNull')->andReturn($journal);
$repository->shouldReceive('findLink')->andReturn(false);
$repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink);
$this->be($this->user());
$response = $this->post(route('transactions.link.store', [$journal->id]), $data);
$response->assertStatus(302);
$response->assertSessionHas('error');
$response->assertRedirect(route('transactions.show', [1]));
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store
* @covers \FireflyIII\Http\Requests\JournalLinkRequest
@ -121,7 +150,7 @@ class LinkControllerTest extends TestCase
];
$journalRepos->shouldReceive('firstNull')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('find')->andReturn(new TransactionJournal);
$journalRepos->shouldReceive('findNull')->andReturn(new TransactionJournal);
$repository->shouldReceive('findLink')->andReturn(true);
$this->be($this->user());