Skip to content

Firefly III: a personal finances manager

Fix tests, improve coverage.

James Coleddc1d81665a3
diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php
index c238f36f01..686b73c082 100644
--- a/app/Http/Controllers/Transaction/LinkController.php
+++ b/app/Http/Controllers/Transaction/LinkController.php
@@ -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) {
diff --git a/app/Http/Middleware/Authenticate.php b/app/Http/Middleware/Authenticate.php
index 8241ca82df..9c2b7f0131 100644
--- a/app/Http/Middleware/Authenticate.php
+++ b/app/Http/Middleware/Authenticate.php
@@ -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();
diff --git a/tests/Feature/Controllers/TagControllerTest.php b/tests/Feature/Controllers/TagControllerTest.php
index 7efd4a623c..f5e53efe6b 100644
--- a/tests/Feature/Controllers/TagControllerTest.php
+++ b/tests/Feature/Controllers/TagControllerTest.php
@@ -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();
diff --git a/tests/Feature/Controllers/Transaction/LinkControllerTest.php b/tests/Feature/Controllers/Transaction/LinkControllerTest.php
index 4789f3ed8a..eb43e5e224 100644
--- a/tests/Feature/Controllers/Transaction/LinkControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/LinkControllerTest.php
@@ -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());