diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php
index 49f52942af..520d3b8516 100644
--- a/app/Http/Controllers/AccountController.php
+++ b/app/Http/Controllers/AccountController.php
@@ -409,8 +409,6 @@ class AccountController extends Controller
$cache->addProperty($account->id);
if ($cache->has()) {
- Log::debug('Entries are cached, return cache.');
-
return $cache->get(); // @codeCoverageIgnore
}
diff --git a/app/Http/breadcrumbs.php b/app/Http/breadcrumbs.php
index 356188163f..c39ad146e1 100644
--- a/app/Http/breadcrumbs.php
+++ b/app/Http/breadcrumbs.php
@@ -792,10 +792,15 @@ Breadcrumbs::register(
Breadcrumbs::register(
'transactions.mass.edit', function (BreadCrumbGenerator $breadcrumbs, Collection $journals) {
- $journalIds = $journals->pluck('id')->toArray();
- $what = strtolower($journals->first()->transactionType->type);
- $breadcrumbs->parent('transactions.index', $what);
- $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
+ if($journals->count() > 0) {
+ $journalIds = $journals->pluck('id')->toArray();
+ $what = strtolower($journals->first()->transactionType->type);
+ $breadcrumbs->parent('transactions.index', $what);
+ $breadcrumbs->push(trans('firefly.mass_edit_journals'), route('transactions.mass.edit', $journalIds));
+ return;
+ }
+
+ $breadcrumbs->parent('index');
}
);
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
index b238ad4bf8..c32a34ff00 100644
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -33,6 +33,15 @@ $factory->define(
}
);
+$factory->define(
+ FireflyIII\Models\Budget::class, function (Faker\Generator $faker) {
+ return [
+ 'id' => $faker->numberBetween(1, 10),
+ 'name' => $faker->words(3, true),
+ ];
+}
+);
+
$factory->define(
FireflyIII\Models\Account::class, function (Faker\Generator $faker) {
return [
diff --git a/tests/Feature/Controllers/AccountControllerTest.php b/tests/Feature/Controllers/AccountControllerTest.php
index e15ca29237..cdae7253b2 100644
--- a/tests/Feature/Controllers/AccountControllerTest.php
+++ b/tests/Feature/Controllers/AccountControllerTest.php
@@ -16,14 +16,21 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Steam;
use Tests\TestCase;
+/**
+ * Class AccountControllerTest
+ *
+ * @package Tests\Feature\Controllers
+ */
class AccountControllerTest extends TestCase
{
/**
@@ -32,9 +39,10 @@ class AccountControllerTest extends TestCase
public function testCreate()
{
// mock stuff
- $collector = $this->mock(JournalCollectorInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn(new Collection);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('accounts.create', ['asset']));
@@ -49,9 +57,10 @@ class AccountControllerTest extends TestCase
public function testDelete()
{
// mock stuff
- $collector = $this->mock(JournalCollectorInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->withArgs([[AccountType::ASSET]])->andReturn(new Collection);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@@ -68,10 +77,11 @@ class AccountControllerTest extends TestCase
public function testDestroy()
{
// mock stuff
- $collector = $this->mock(JournalCollectorInterface::class);
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account);
$repository->shouldReceive('destroy')->andReturn(true);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['accounts.delete.url' => 'http://localhost/accounts/show/1']);
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
@@ -88,9 +98,10 @@ class AccountControllerTest extends TestCase
public function testEdit()
{
// mock stuff
- $collector = $this->mock(JournalCollectorInterface::class);
- $repository = $this->mock(CurrencyRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CurrencyRepositoryInterface::class);
$repository->shouldReceive('get')->andReturn(new Collection);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$account = $this->user()->accounts()->where('account_type_id', 3)->whereNull('deleted_at')->first();
@@ -111,9 +122,11 @@ class AccountControllerTest extends TestCase
public function testIndex(string $range)
{
// mock stuff
- $account = factory(Account::class)->make();
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $account = factory(Account::class)->make();
+ $repository = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
Steam::shouldReceive('balancesById')->andReturn([]);
Steam::shouldReceive('getLastActivities')->andReturn([]);
@@ -138,7 +151,9 @@ class AccountControllerTest extends TestCase
$this->session(['start' => $date, 'end' => clone $date]);
// mock stuff:
- $tasker = $this->mock(AccountTaskerInterface::class);
+ $tasker = $this->mock(AccountTaskerInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
@@ -172,8 +187,10 @@ class AccountControllerTest extends TestCase
public function testShowAll(string $range)
{
// mock stuff
- $transaction = factory(Transaction::class)->make();
- $collector = $this->mock(JournalCollectorInterface::class);
+ $transaction = factory(Transaction::class)->make();
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -204,7 +221,9 @@ class AccountControllerTest extends TestCase
*/
public function testShowBrokenInitial()
{
- $date = new Carbon;
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
@@ -222,8 +241,10 @@ class AccountControllerTest extends TestCase
public function testShowByDate(string $range)
{
// mock stuff
- $transaction = factory(Transaction::class)->make();
- $collector = $this->mock(JournalCollectorInterface::class);
+ $transaction = factory(Transaction::class)->make();
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -254,7 +275,9 @@ class AccountControllerTest extends TestCase
public function testShowByDateEmpty(string $range)
{
// mock stuff
- $collector = $this->mock(JournalCollectorInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -282,7 +305,9 @@ class AccountControllerTest extends TestCase
*/
public function testShowInitial()
{
- $date = new Carbon;
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $date = new Carbon;
$this->session(['start' => $date, 'end' => clone $date]);
$this->be($this->user());
@@ -296,9 +321,11 @@ class AccountControllerTest extends TestCase
*/
public function testStore()
{
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['accounts.create.url' => 'http://localhost']);
$this->be($this->user());
@@ -317,9 +344,11 @@ class AccountControllerTest extends TestCase
*/
public function testUpdate()
{
- $repository = $this->mock(AccountRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('find')->andReturn(new Account)->once();
$repository->shouldReceive('update')->once();
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['accounts.edit.url' => 'http://localhost']);
$this->be($this->user());
diff --git a/tests/Feature/Controllers/AttachmentControllerTest.php b/tests/Feature/Controllers/AttachmentControllerTest.php
index 4608209dbc..49dad45c41 100644
--- a/tests/Feature/Controllers/AttachmentControllerTest.php
+++ b/tests/Feature/Controllers/AttachmentControllerTest.php
@@ -12,7 +12,9 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Tests\TestCase;
class AttachmentControllerTest extends TestCase
@@ -22,6 +24,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testDelete()
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.delete', [1]));
$response->assertStatus(200);
@@ -34,10 +38,13 @@ class AttachmentControllerTest extends TestCase
*/
public function testDestroy()
{
- $this->session(['attachments.delete.url' => 'http://localhost']);
-
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $this->session(['attachments.delete.url' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('attachments.destroy', [1]));
$response->assertStatus(302);
@@ -49,9 +56,12 @@ class AttachmentControllerTest extends TestCase
*/
public function testDownload()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.download', [1]));
@@ -65,6 +75,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testEdit()
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.edit', [1]));
$response->assertStatus(200);
@@ -78,6 +90,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testPreview()
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.preview', [1]));
$response->assertStatus(200);
@@ -88,6 +102,12 @@ class AttachmentControllerTest extends TestCase
*/
public function testUpdate()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(AttachmentRepositoryInterface::class);
+ $repository->shouldReceive('update')->once();
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->session(['attachments.edit.url' => 'http://localhost']);
$data = [
'title' => 'Some updated title ' . rand(1000, 9999),
@@ -99,14 +119,6 @@ class AttachmentControllerTest extends TestCase
$response = $this->post(route('attachments.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
-
- // view should be updated
- $this->be($this->user());
- $response = $this->get(route('attachments.edit', [1]));
- $response->assertStatus(200);
- // has bread crumb
- $response->assertSee('
');
- $response->assertSee($data['title']);
}
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
index f8d3c20d32..227392532b 100644
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ b/tests/Feature/Controllers/BillControllerTest.php
@@ -12,7 +12,13 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers;
+use Carbon\Carbon;
+use FireflyIII\Helpers\Collector\JournalCollectorInterface;
+use FireflyIII\Models\Bill;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
+use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -23,6 +29,10 @@ class BillControllerTest extends TestCase
*/
public function testCreate()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('bills.create'));
$response->assertStatus(200);
@@ -35,6 +45,10 @@ class BillControllerTest extends TestCase
*/
public function testDelete()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('bills.delete', [1]));
$response->assertStatus(200);
@@ -47,8 +61,11 @@ class BillControllerTest extends TestCase
*/
public function testDestroy()
{
- $repository = $this->mock(BillRepositoryInterface::class);
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['bills.delete.url' => 'http://localhost']);
$this->be($this->user());
@@ -62,6 +79,10 @@ class BillControllerTest extends TestCase
*/
public function testEdit()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('bills.edit', [1]));
$response->assertStatus(200);
@@ -75,6 +96,12 @@ class BillControllerTest extends TestCase
*/
public function testIndex()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $repository->shouldReceive('getBills')->andReturn(new Collection);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('bills.index'));
$response->assertStatus(200);
@@ -87,8 +114,12 @@ class BillControllerTest extends TestCase
*/
public function testRescan()
{
- $repository = $this->mock(BillRepositoryInterface::class);
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
$repository->shouldReceive('getPossiblyRelatedJournals')->once()->andReturn(new Collection);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('bills.rescan', [1]));
$response->assertStatus(302);
@@ -100,6 +131,23 @@ class BillControllerTest extends TestCase
*/
public function testShow()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $repository->shouldReceive('getYearAverage')->andReturn('0');
+ $repository->shouldReceive('getOverallAverage')->andReturn('0');
+ $repository->shouldReceive('nextExpectedMatch')->andReturn(new Carbon);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
+ $collector->shouldReceive('setBills')->andReturnSelf();
+ $collector->shouldReceive('setLimit')->andReturnSelf();
+ $collector->shouldReceive('setPage')->andReturnSelf();
+ $collector->shouldReceive('withBudgetInformation')->andReturnSelf();
+ $collector->shouldReceive('withCategoryInformation')->andReturnSelf();
+ $collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+
$this->be($this->user());
$response = $this->get(route('bills.show', [1]));
$response->assertStatus(200);
@@ -112,6 +160,12 @@ class BillControllerTest extends TestCase
*/
public function testStore()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('store')->andReturn(new Bill);
+
$data = [
'name' => 'New Bill ' . rand(1000, 9999),
'match' => 'some words',
@@ -128,13 +182,6 @@ class BillControllerTest extends TestCase
$response = $this->post(route('bills.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
-
- // list must be updated
- $this->be($this->user());
- $response = $this->get(route('bills.index'));
- $response->assertStatus(200);
- $response->assertSee('');
- $response->assertSee($data['name']);
}
/**
@@ -142,6 +189,12 @@ class BillControllerTest extends TestCase
*/
public function testUpdate()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BillRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('update')->andReturn(new Bill);
+
$data = [
'name' => 'Updated Bill ' . rand(1000, 9999),
'match' => 'some more words',
@@ -159,12 +212,6 @@ class BillControllerTest extends TestCase
$response->assertStatus(302);
$response->assertSessionHas('success');
- // list must be updated
- $this->be($this->user());
- $response = $this->get(route('bills.index'));
- $response->assertStatus(200);
- $response->assertSee('');
- $response->assertSee($data['name']);
}
}
diff --git a/tests/Feature/Controllers/BudgetControllerTest.php b/tests/Feature/Controllers/BudgetControllerTest.php
index 399f19eccc..88c760cd9d 100644
--- a/tests/Feature/Controllers/BudgetControllerTest.php
+++ b/tests/Feature/Controllers/BudgetControllerTest.php
@@ -13,8 +13,12 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
+use FireflyIII\Models\Budget;
+use FireflyIII\Models\BudgetLimit;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -26,9 +30,13 @@ class BudgetControllerTest extends TestCase
*/
public function testAmount()
{
- $data = [
- 'amount' => 200,
- ];
+ // mock stuff
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('updateLimitAmount')->andReturn(new BudgetLimit);
+
+ $data = ['amount' => 200,];
$this->be($this->user());
$response = $this->post(route('budgets.amount', [1]), $data);
$response->assertStatus(200);
@@ -39,6 +47,10 @@ class BudgetControllerTest extends TestCase
*/
public function testCreate()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('budgets.create'));
$response->assertStatus(200);
@@ -51,6 +63,10 @@ class BudgetControllerTest extends TestCase
*/
public function testDelete()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('budgets.delete', [1]));
$response->assertStatus(200);
@@ -63,11 +79,14 @@ class BudgetControllerTest extends TestCase
*/
public function testDestroy()
{
- $this->session(['budgets.delete.url' => 'http://localhost']);
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $repository = $this->mock(BudgetRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
+ $this->session(['budgets.delete.url' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('budgets.destroy', [1]));
$response->assertStatus(302);
@@ -79,6 +98,10 @@ class BudgetControllerTest extends TestCase
*/
public function testEdit()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('budgets.edit', [1]));
$response->assertStatus(200);
@@ -96,7 +119,13 @@ class BudgetControllerTest extends TestCase
*/
public function testIndex(string $range)
{
- $repository = $this->mock(BudgetRepositoryInterface::class);
+ // mock stuff
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
+
$repository->shouldReceive('cleanupBudgets');
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
@@ -119,10 +148,11 @@ class BudgetControllerTest extends TestCase
*/
public function testNoBudget(string $range)
{
- $date = new Carbon();
- $this->session(['start' => $date, 'end' => clone $date]);
+ // mock stuff
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -131,6 +161,9 @@ class BudgetControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+ $date = new Carbon();
+ $this->session(['start' => $date, 'end' => clone $date]);
+
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('budgets.no-budget'));
@@ -144,9 +177,13 @@ class BudgetControllerTest extends TestCase
*/
public function testPostUpdateIncome()
{
- $data = [
- 'amount' => '200',
- ];
+ // mock stuff
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('setAvailableBudget');
+
+ $data = ['amount' => '200',];
$this->be($this->user());
$response = $this->post(route('budgets.income.post'), $data);
$response->assertStatus(302);
@@ -161,21 +198,11 @@ class BudgetControllerTest extends TestCase
*/
public function testShow(string $range)
{
- $date = new Carbon();
- $date->subDay();
- $this->session(['first' => $date]);
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->andReturn(new TransactionJournal);
- // mock account repository
- $accountRepository = $this->mock(AccountRepositoryInterface::class);
- $accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
-
-
- // mock budget repository
- $budgetRepository = $this->mock(BudgetRepositoryInterface::class);
- $budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
- $budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
- // mock journal collector:
- $collector = $this->mock(JournalCollectorInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
@@ -184,6 +211,16 @@ class BudgetControllerTest extends TestCase
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
+
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
+ $repository->shouldReceive('spentInPeriod')->andReturn('1');
+
+ $date = new Carbon();
+ $date->subDay();
+ $this->session(['first' => $date]);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -200,10 +237,15 @@ class BudgetControllerTest extends TestCase
*/
public function testShowByBudgetLimit(string $range)
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
// mock account repository
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
+
// mock budget repository
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
@@ -233,6 +275,13 @@ class BudgetControllerTest extends TestCase
*/
public function testStore()
{
+ // mock stuff
+ $budget = factory(Budget::class)->make();
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('find')->andReturn($budget);
+ $repository->shouldReceive('store')->andReturn($budget);
$this->session(['budgets.create.url' => 'http://localhost']);
$data = [
@@ -249,6 +298,14 @@ class BudgetControllerTest extends TestCase
*/
public function testUpdate()
{
+ // mock stuff
+ $budget = factory(Budget::class)->make();
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('find')->andReturn($budget);
+ $repository->shouldReceive('update');
+
$this->session(['budgets.edit.url' => 'http://localhost']);
$data = [
@@ -266,6 +323,12 @@ class BudgetControllerTest extends TestCase
*/
public function testUpdateIncome()
{
+ // mock stuff
+ $repository = $this->mock(BudgetRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('getAvailableBudget')->andReturn('1');
+
// must be in list
$this->be($this->user());
$response = $this->get(route('budgets.income', [1]));
diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.php
index 2d4737df42..c66c7a1a7c 100644
--- a/tests/Feature/Controllers/CategoryControllerTest.php
+++ b/tests/Feature/Controllers/CategoryControllerTest.php
@@ -13,8 +13,11 @@ namespace Tests\Feature\Controllers;
use Carbon\Carbon;
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
+use FireflyIII\Models\Category;
+use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
+use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
use Tests\TestCase;
@@ -26,6 +29,10 @@ class CategoryControllerTest extends TestCase
*/
public function testCreate()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('categories.create'));
$response->assertStatus(200);
@@ -38,6 +45,10 @@ class CategoryControllerTest extends TestCase
*/
public function testDelete()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('categories.delete', [1]));
$response->assertStatus(200);
@@ -50,10 +61,15 @@ class CategoryControllerTest extends TestCase
*/
public function testDestroy()
{
- $this->session(['categories.delete.url' => 'http://localhost']);
- $repository = $this->mock(CategoryRepositoryInterface::class);
+ // mock stuff
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+
$repository->shouldReceive('destroy')->andReturn(true);
+ $this->session(['categories.delete.url' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('categories.destroy', [1]));
$response->assertStatus(302);
@@ -65,6 +81,10 @@ class CategoryControllerTest extends TestCase
*/
public function testEdit()
{
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
$this->be($this->user());
$response = $this->get(route('categories.edit', [1]));
$response->assertStatus(200);
@@ -78,6 +98,13 @@ class CategoryControllerTest extends TestCase
*/
public function testIndex()
{
+ // mock stuff
+ $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);
+
$this->be($this->user());
$response = $this->get(route('categories.index'));
$response->assertStatus(200);
@@ -93,6 +120,16 @@ class CategoryControllerTest extends TestCase
*/
public function testNoCategory(string $range)
{
+ // mock stuff
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
+ $collector->shouldReceive('setRange')->andReturnSelf();
+ $collector->shouldReceive('withoutCategory')->andReturnSelf();
+ $collector->shouldReceive('getJournals')->andReturn(new Collection);
+
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.no-category'));
@@ -103,21 +140,27 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
+ * @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
+ *
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShow(string $range)
{
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $collector = $this->mock(JournalCollectorInterface::class);
- $accRepository = $this->mock(AccountRepositoryInterface::class);
- $catRepository = $this->mock(CategoryRepositoryInterface::class);
+ // mock stuff
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
+ $repository->shouldReceive('spentInPeriod')->andReturn('0');
+ $repository->shouldReceive('earnedInPeriod')->andReturn('0');
- $accRepository->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
- $catRepository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $accountRepos->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
- // collector stuff:
+ $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setPage')->andReturnSelf()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
@@ -126,11 +169,6 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
- // more repos stuff:
- $catRepository->shouldReceive('spentInPeriod')->andReturn('0');
- $catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
-
-
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.show', [1]));
@@ -146,16 +184,19 @@ class CategoryControllerTest extends TestCase
*/
public function testShowAll(string $range)
{
- $collector = $this->mock(JournalCollectorInterface::class);
-
- // collector stuff:
+ // mock stuff
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setPage')->andReturnSelf()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('firstUseDate')->andReturn(new Carbon);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -166,15 +207,22 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
+ * @covers \FireflyIII\Http\Controllers\CategoryController::getGroupedEntries
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowByDate(string $range)
{
- $collector = $this->mock(JournalCollectorInterface::class);
+ // mock stuff
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $collector = $this->mock(JournalCollectorInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+
+ $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection);
- // collector stuff:
$collector->shouldReceive('setPage')->andReturnSelf()->once();
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
@@ -183,8 +231,6 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
- // mock category repository
- $repository = $this->mock(CategoryRepositoryInterface::class);
$repository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
$repository->shouldReceive('spentInPeriod')->andReturn('-1');
$repository->shouldReceive('earnedInPeriod')->andReturn('1');
@@ -202,6 +248,12 @@ class CategoryControllerTest extends TestCase
*/
public function testStore()
{
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('find')->andReturn(new Category);
+ $repository->shouldReceive('store')->andReturn(new Category);
+
$this->session(['categories.create.url' => 'http://localhost']);
$data = [
@@ -211,13 +263,6 @@ class CategoryControllerTest extends TestCase
$response = $this->post(route('categories.store'), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
-
- // must be in list
- $this->be($this->user());
- $response = $this->get(route('categories.index'));
- $response->assertStatus(200);
- $response->assertSee('');
- $response->assertSee($data['name']);
}
/**
@@ -225,6 +270,12 @@ class CategoryControllerTest extends TestCase
*/
public function testUpdate()
{
+ $repository = $this->mock(CategoryRepositoryInterface::class);
+ $journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
+ $repository->shouldReceive('update');
+ $repository->shouldReceive('find')->andReturn(new Category);
+
$this->session(['categories.edit.url' => 'http://localhost']);
$data = [
@@ -235,13 +286,6 @@ class CategoryControllerTest extends TestCase
$response = $this->post(route('categories.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
-
- // must be in list
- $this->be($this->user());
- $response = $this->get(route('categories.index'));
- $response->assertStatus(200);
- $response->assertSee('');
- $response->assertSee($data['name']);
}