Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fixed tests
James Colee155d3311c31
diff --git a/app/Http/Controllers/GoogleChartController.php b/app/Http/Controllers/GoogleChartController.phpindex a4cf4b4baa..9ee072a6b4 100644--- a/app/Http/Controllers/GoogleChartController.php+++ b/app/Http/Controllers/GoogleChartController.php@@ -359,7 +359,7 @@ class GoogleChartController extends Controllerwhile ($start <= $end) {$currentEnd = Navigation::endOfPeriod($start, $range->data);- $spent = $repository->spentInPeriodSum($category, $start, $currentEnd);+ $spent = $repository->spentInPeriod($category, $start, $currentEnd);$chart->addRow(clone $start, $spent);$start = Navigation::addPeriod($start, $range->data, 0);diff --git a/app/Http/Controllers/ReportChartController.php b/app/Http/Controllers/ReportChartController.phpindex 49d4e29f84..8adf8a4b7a 100644--- a/app/Http/Controllers/ReportChartController.php+++ b/app/Http/Controllers/ReportChartController.php@@ -5,6 +5,7 @@ namespace FireflyIII\Http\Controllers;use Carbon\Carbon;use FireflyIII\Helpers\Report\ReportQueryInterface;use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;+use FireflyIII\Repositories\Category\CategoryRepositoryInterface;use Grumpydictator\Gchart\GChart;use Response;@@ -52,11 +53,35 @@ class ReportChartController extends Controllerreturn Response::json($chart->getData());}- public function yearCategories(GChart $chart, $year, $shared = false)+ public function yearCategories(GChart $chart, CategoryRepositoryInterface $repository, $year, $shared = false){$start = new Carbon($year . '-01-01');$end = new Carbon($year . '-12-31');$shared = $shared == 'shared' ? true : false;+ $categories = $repository->getCategories();++ // add columns:+ $chart->addColumn(trans('firefly.month'), 'date');+ foreach ($categories as $category) {+ $chart->addColumn($category->name, 'number');+ }++ while ($start < $end) {+ // month is the current end of the period:+ $month = clone $start;+ $month->endOfMonth();+ // make a row:+ $row = [clone $start];++ // each budget, fill the row:+ foreach ($categories as $category) {+ $spent = $repository->spentInPeriod($category, $start, $month, $shared);+ $row[] = $spent;+ }+ $chart->addRowArray($row);++ $start->addMonth();+ }$chart->generate();diff --git a/app/Repositories/Category/CategoryRepository.php b/app/Repositories/Category/CategoryRepository.phpindex 9fe14b1bbb..b81b2b4dd5 100644--- a/app/Repositories/Category/CategoryRepository.php+++ b/app/Repositories/Category/CategoryRepository.php@@ -170,9 +170,15 @@ class CategoryRepository implements CategoryRepositoryInterface** @return float*/- public function spentInPeriodSum(Category $category, Carbon $start, Carbon $end)+ public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false){- return floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;+ if($shared === false) {+ // do something else, SEE budgets.+ $sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;+ } else {+ $sum = floatval($category->transactionjournals()->before($end)->after($start)->lessThan(0)->sum('amount')) * -1;+ }+ return $sum;}/**diff --git a/app/Repositories/Category/CategoryRepositoryInterface.php b/app/Repositories/Category/CategoryRepositoryInterface.phpindex 30456995a1..547ce752bb 100644--- a/app/Repositories/Category/CategoryRepositoryInterface.php+++ b/app/Repositories/Category/CategoryRepositoryInterface.php@@ -77,7 +77,7 @@ interface CategoryRepositoryInterface** @return float*/- public function spentInPeriodSum(Category $category, Carbon $start, Carbon $end);+ public function spentInPeriod(Category $category, Carbon $start, Carbon $end, $shared = false);/*** @param Category $categorydiff --git a/tests/controllers/GoogleChartControllerTest.php b/tests/controllers/GoogleChartControllerTest.phpindex f51f7028f9..82b7a5f7f1 100644--- a/tests/controllers/GoogleChartControllerTest.php+++ b/tests/controllers/GoogleChartControllerTest.php@@ -212,7 +212,7 @@ class GoogleChartControllerTest extends TestCase// mock!$repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$repository->shouldReceive('getFirstActivityDate')->andReturn($start);- $repository->shouldReceive('spentInPeriodSum')->andReturn(rand(1, 100));+ $repository->shouldReceive('spentInPeriod')->andReturn(rand(1, 100));Preferences::shouldReceive('get')->andReturn($pref);Navigation::shouldReceive('startOfPeriod')->andReturn($start);diff --git a/tests/repositories/BudgetRepositoryTest.php b/tests/repositories/BudgetRepositoryTest.phpindex b9b9d018bc..72c0d29f59 100644--- a/tests/repositories/BudgetRepositoryTest.php+++ b/tests/repositories/BudgetRepositoryTest.php@@ -292,11 +292,11 @@ class BudgetRepositoryTest extends TestCase/*** @covers FireflyIII\Repositories\Budget\BudgetRepository::spentInMonth*/- public function testSpentInMonth()+ public function testSpentInPeriod(){$budget = FactoryMuffin::create('FireflyIII\Models\Budget');- $amount = $this->object->spentInMonth($budget, new Carbon);+ $amount = $this->object->spentInPeriod($budget, new Carbon, new Carbon);$this->assertEquals(0, $amount);}diff --git a/tests/repositories/CategoryRepositoryTest.php b/tests/repositories/CategoryRepositoryTest.phpindex e17bcae14f..57c6a96553 100644--- a/tests/repositories/CategoryRepositoryTest.php+++ b/tests/repositories/CategoryRepositoryTest.php@@ -189,12 +189,12 @@ class CategoryRepositoryTest extends TestCase}/**- * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodSum+ * @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriod*/public function testSpentInPeriodSum(){$category = FactoryMuffin::create('FireflyIII\Models\Category');- $sum = $this->object->spentInPeriodSum($category, new Carbon, new Carbon);+ $sum = $this->object->spentInPeriod($category, new Carbon, new Carbon);$this->assertEquals(0, $sum);