Skip to content

Firefly III: a personal finances manager

Expand tests.

James Colee2f3788ff5e7
diff --git a/app/Http/Controllers/CategoryController.php b/app/Http/Controllers/CategoryController.php
index eb91a6bf53..d76c829e2a 100644
--- a/app/Http/Controllers/CategoryController.php
+++ b/app/Http/Controllers/CategoryController.php
@@ -438,8 +438,9 @@ class CategoryController extends Controller
return $cache->get(); // @codeCoverageIgnore
}
- Log::debug('Going to get period expenses and incomes.');
+ Log::debug(sprintf('Going to get period expenses and incomes between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d')));
while ($end >= $start) {
+ Log::debug('Loop!');
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
@@ -483,6 +484,7 @@ class CategoryController extends Controller
);
$end = Navigation::subtractPeriod($end, $range, 1);
}
+ Log::debug('End of loops');
$cache->store($entries);
return $entries;
diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php
index 0de48942a4..213fcd8350 100644
--- a/app/Http/Controllers/PiggyBankController.php
+++ b/app/Http/Controllers/PiggyBankController.php
@@ -229,7 +229,8 @@ class PiggyBankController extends Controller
'sumOfTargets' => $piggyBank->targetamount,
'leftToSave' => $piggyBank->leftToSave,
];
- } else {
+ }
+ if (isset($accounts[$account->id])) {
$accounts[$account->id]['sumOfSaved'] = bcadd($accounts[$account->id]['sumOfSaved'], strval($piggyBank->savedSoFar));
$accounts[$account->id]['sumOfTargets'] = bcadd($accounts[$account->id]['sumOfTargets'], $piggyBank->targetamount);
$accounts[$account->id]['leftToSave'] = bcadd($accounts[$account->id]['leftToSave'], $piggyBank->leftToSave);
diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php
index b0fc0e28ee..01066d5b8b 100644
--- a/app/Http/Controllers/TransactionController.php
+++ b/app/Http/Controllers/TransactionController.php
@@ -212,11 +212,12 @@ class TransactionController extends Controller
$cache->addProperty('transaction-list-entries');
if ($cache->has()) {
- return $cache->get(); // @codeCoverageIgnore
+ return $cache->get(); // @codeCoverageIgnore
}
- Log::debug('Going to get period expenses and incomes.');
+ Log::debug(sprintf('Going to get period expenses and incomes between %s and %s.', $start->format('Y-m-d'), $end->format('Y-m-d')));
while ($end >= $start) {
+ Log::debug('Loop start!');
$end = Navigation::startOfPeriod($end, $range);
$currentEnd = Navigation::endOfPeriod($end, $range);
@@ -238,6 +239,7 @@ class TransactionController extends Controller
'transferred' => 0,
'date' => clone $end,
];
+ Log::debug(sprintf('What is %s', $what));
switch ($what) {
default:
throw new FireflyException(sprintf('Cannot handle "%s"', $what));
@@ -249,6 +251,7 @@ class TransactionController extends Controller
break;
case 'transfers':
case 'transfer':
+ Log::debug('HERE');
$array['transferred'] = Steam::positive($sum);
break;
@@ -256,6 +259,7 @@ class TransactionController extends Controller
$entries->push($array);
$end = Navigation::subtractPeriod($end, $range, 1);
}
+ Log::debug('End of loop');
$cache->store($entries);
return $entries;
diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php
index 85729c895c..d727a45a98 100644
--- a/database/factories/ModelFactory.php
+++ b/database/factories/ModelFactory.php
@@ -33,6 +33,21 @@ $factory->define(
}
);
+$factory->define(
+ FireflyIII\Models\PiggyBank::class, function (Faker\Generator $faker) {
+ return [
+ 'id' => $faker->numberBetween(1, 10),
+ 'account_id' => $faker->numberBetween(1, 10),
+ 'name' => $faker->words(3, true),
+ 'target_amount' => '1000.00',
+ 'startdate' => '2017-01-01',
+ 'order' => 1,
+ 'active' => 1,
+ 'encrypted' => 0,
+ ];
+}
+);
+
$factory->define(
FireflyIII\Models\Tag::class, function (Faker\Generator $faker) {
return [
diff --git a/tests/Feature/Controllers/CategoryControllerTest.php b/tests/Feature/Controllers/CategoryControllerTest.php
index 5c4ed07c85..53fdbe9db9 100644
--- a/tests/Feature/Controllers/CategoryControllerTest.php
+++ b/tests/Feature/Controllers/CategoryControllerTest.php
@@ -20,6 +20,7 @@ use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
+use Steam;
use Tests\TestCase;
class CategoryControllerTest extends TestCase
@@ -114,6 +115,7 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::noCategory
+ * @covers \FireflyIII\Http\Controllers\CategoryController::noCategoryPeriodEntries
* @dataProvider dateRangeProvider
*
* @param string $range
@@ -137,6 +139,7 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
+ Steam::shouldReceive('positive')->once()->andReturn('1');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
@@ -148,6 +151,7 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::noCategory
+ * @covers \FireflyIII\Http\Controllers\CategoryController::noCategoryPeriodEntries
* @dataProvider dateRangeProvider
*
* @param string $range
@@ -181,6 +185,7 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::noCategory
+ * @covers \FireflyIII\Http\Controllers\CategoryController::noCategoryPeriodEntries
* @dataProvider dateRangeProvider
*
* @param string $range
@@ -204,6 +209,8 @@ class CategoryControllerTest extends TestCase
$collector->shouldReceive('disableInternalFilter')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
+ Steam::shouldReceive('positive')->once()->andReturn('1');
+
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('categories.no-category', ['2016-01-01']));
diff --git a/tests/Feature/Controllers/Chart/AccountControllerTest.php b/tests/Feature/Controllers/Chart/AccountControllerTest.php
index a6468fef80..b172f22278 100644
--- a/tests/Feature/Controllers/Chart/AccountControllerTest.php
+++ b/tests/Feature/Controllers/Chart/AccountControllerTest.php
@@ -31,6 +31,24 @@ use Tests\TestCase;
*/
class AccountControllerTest extends TestCase
{
+
+ /**
+ * @covers \FireflyIII\Http\Controllers\Chart\AccountController::all
+ */
+ public function testAll()
+ {
+ $generator = $this->mock(GeneratorInterface::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+
+ $accountRepos->shouldReceive('oldestJournalDate')->once()->andReturn(Carbon::now()->subMonth());
+ Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
+ $generator->shouldReceive('singleSet')->andReturn([]);
+
+ $this->be($this->user());
+ $response = $this->get(route('chart.account.all', [1]));
+ $response->assertStatus(200);
+ }
+
/**
* @covers \FireflyIII\Http\Controllers\Chart\AccountController::expenseAccounts
* @covers \FireflyIII\Generator\Chart\Basic\GeneratorInterface::singleSet
@@ -188,6 +206,7 @@ class AccountControllerTest extends TestCase
{
$generator = $this->mock(GeneratorInterface::class);
$generator->shouldReceive('multiSet')->andreturn([]);
+ Steam::shouldReceive('balanceInRange')->andReturn(['2012-01-01' => '0']);
$this->be($this->user());
$response = $this->get(route('chart.account.report', ['1', '20120101', '20120131']));
diff --git a/tests/Feature/Controllers/PiggyBankControllerTest.php b/tests/Feature/Controllers/PiggyBankControllerTest.php
index da2b048a2f..c5342504d4 100644
--- a/tests/Feature/Controllers/PiggyBankControllerTest.php
+++ b/tests/Feature/Controllers/PiggyBankControllerTest.php
@@ -19,6 +19,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection;
+use Steam;
use Tests\TestCase;
/**
@@ -141,8 +142,11 @@ class PiggyBankControllerTest extends TestCase
// mock stuff
$repository = $this->mock(PiggyBankRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
+ $piggyBank = factory(PiggyBank::class)->make();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
- $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection);
+ $repository->shouldReceive('getPiggyBanks')->andReturn(new Collection([$piggyBank]));
+
+ Steam::shouldReceive('balanceIgnoreVirtual')->twice()->andReturn('1');
$this->be($this->user());
$response = $this->get(route('piggy-banks.index'));
diff --git a/tests/Feature/Controllers/Transaction/SingleControllerTest.php b/tests/Feature/Controllers/Transaction/SingleControllerTest.php
index c8dd9095c3..684a2bb311 100644
--- a/tests/Feature/Controllers/Transaction/SingleControllerTest.php
+++ b/tests/Feature/Controllers/Transaction/SingleControllerTest.php
@@ -26,6 +26,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
+use Steam;
use Tests\TestCase;
/**
@@ -53,6 +54,7 @@ class SingleControllerTest extends TestCase
*/
public function testCreate()
{
+ Steam::shouldReceive('phpBytes')->andReturn(2048);
$repository = $this->mock(AccountRepositoryInterface::class);
$repository->shouldReceive('getActiveAccountsByType')->once()->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
diff --git a/tests/Feature/Controllers/TransactionControllerTest.php b/tests/Feature/Controllers/TransactionControllerTest.php
index a2f01787ae..4cc5face03 100644
--- a/tests/Feature/Controllers/TransactionControllerTest.php
+++ b/tests/Feature/Controllers/TransactionControllerTest.php
@@ -17,6 +17,7 @@ use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalTaskerInterface;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection;
+use Steam;
use Tests\TestCase;
class TransactionControllerTest extends TestCase
@@ -45,6 +46,8 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
+ Steam::shouldReceive('positive')->once()->andReturn('1');
+
$this->be($this->user());
$response = $this->get(route('transactions.index', ['transfer']));
$response->assertStatus(200);
@@ -103,6 +106,7 @@ class TransactionControllerTest extends TestCase
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$collector->shouldReceive('getJournals')->andReturn(new Collection);
+ Steam::shouldReceive('positive')->once()->andReturn('1');
$this->be($this->user());
$response = $this->get(route('transactions.index', ['transfer', '2016-01-01']));