Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
New tests.
James Cole70eed5cb5ef7
diff --git a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.phpindex b17cfe7f04..f6af9c4568 100644--- a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php+++ b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php@@ -45,6 +45,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator/*** @codeCoverageIgnore+ ** @param Collection $entries** @return array@@ -62,7 +63,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorpublic function frontpage(Collection $entries){$data = [- 'count' => 2,+ 'count' => 0,'labels' => [],'datasets' => [],];@@ -119,7 +120,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGeneratorforeach ($budgets as $budget) {$data['labels'][] = $budget->name;- $data['count']++;}/** @var array $entry */foreach ($entries as $entry) {@@ -132,6 +132,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator$data['datasets'][] = $array;}+ $data['count'] = count($data['datasets']);return $data;}diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.phpindex 91a8aef3e7..c2feb4c660 100644--- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php+++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php@@ -69,6 +69,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator}/**+ * @codeCoverageIgnore* @param Collection $entries** @return arraydiff --git a/tests/generators/ChartJsBillChartGeneratorTest.php b/tests/generators/ChartJsBillChartGeneratorTest.phpindex 53cdb49c69..62485e9c84 100644--- a/tests/generators/ChartJsBillChartGeneratorTest.php+++ b/tests/generators/ChartJsBillChartGeneratorTest.php@@ -10,7 +10,7 @@ use League\FactoryMuffin\Facade as FactoryMuffin;class ChartJsBillChartGeneratorTest extends TestCase{- /** @var \FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator */+ /** @var ChartJsBillChartGenerator */protected $object;/**diff --git a/tests/generators/ChartJsBudgetChartGeneratorTest.php b/tests/generators/ChartJsBudgetChartGeneratorTest.phpindex 9749a5dd0b..7381287ad2 100644--- a/tests/generators/ChartJsBudgetChartGeneratorTest.php+++ b/tests/generators/ChartJsBudgetChartGeneratorTest.php@@ -1,4 +1,8 @@<?php+use Carbon\Carbon;+use FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator;+use Illuminate\Support\Collection;+use League\FactoryMuffin\Facade as FactoryMuffin;/*** Class ChartJsBudgetChartGeneratorTest@@ -6,6 +10,10 @@class ChartJsBudgetChartGeneratorTest extends TestCase{++ /** @var ChartJsBudgetChartGenerator */+ protected $object;+/*** Sets up the fixture, for example, opens a network connection.* This method is called before a test is executed.@@ -14,6 +22,8 @@ class ChartJsBudgetChartGeneratorTest extends TestCase{parent::setUp();+ $this->object = new ChartJsBudgetChartGenerator();+}/**@@ -31,15 +41,17 @@ class ChartJsBudgetChartGeneratorTest extends TestCase*/public function testBudget(){- $this->markTestIncomplete();- }+ // make a collection with some amounts in them.+ $collection = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $collection->push([null, 100]);+ }- /**- * @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::budgetLimit- */- public function testBudgetLimit()- {- $this->markTestIncomplete();+ $data = $this->object->budget($collection);++ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets'][0]['data']);+ $this->assertEquals(100, $data['datasets'][0]['data'][0]);}/**@@ -47,7 +59,20 @@ class ChartJsBudgetChartGeneratorTest extends TestCase*/public function testFrontpage(){- $this->markTestIncomplete();+ // make a collection with some amounts in them.+ $collection = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $collection->push(['Some label', 100, 200, 300]);+ }++ $data = $this->object->frontpage($collection);++ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets'][0]['data']);+ $this->assertEquals(100, $data['datasets'][0]['data'][0]);+ $this->assertEquals(200, $data['datasets'][1]['data'][0]);+ $this->assertEquals(300, $data['datasets'][2]['data'][0]);+}/**@@ -55,6 +80,27 @@ class ChartJsBudgetChartGeneratorTest extends TestCase*/public function testYear(){- $this->markTestIncomplete();+ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->data = 'en';+ $preference->save();++ $budgets = new Collection;+ $entries = new Collection;++ // make some budgets:+ for ($i = 0; $i < 5; $i++) {+ $budgets->push(FactoryMuffin::create('FireflyIII\Models\Budget'));+ $entries->push([new Carbon, 100, 100, 100]);+ }++ // mock language preference:+ Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);++ $data = $this->object->year($budgets, $entries);++ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets']);+ $this->assertCount(3, $data['datasets'][0]['data']);+}}\ No newline at end of filediff --git a/tests/generators/ChartJsCategoryChartGeneratorTest.php b/tests/generators/ChartJsCategoryChartGeneratorTest.phpindex 343782815d..d90276cc46 100644--- a/tests/generators/ChartJsCategoryChartGeneratorTest.php+++ b/tests/generators/ChartJsCategoryChartGeneratorTest.php@@ -1,4 +1,9 @@<?php+use Carbon\Carbon;+use FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator;+use Illuminate\Support\Collection;+use League\FactoryMuffin\Facade as FactoryMuffin;+/*** Class ChartJsCategoryChartGeneratorTest@@ -6,6 +11,10 @@class ChartJsCategoryChartGeneratorTest extends TestCase{++ /** @var ChartJsCategoryChartGenerator */+ protected $object;+/*** Sets up the fixture, for example, opens a network connection.* This method is called before a test is executed.@@ -14,6 +23,8 @@ class ChartJsCategoryChartGeneratorTest extends TestCase{parent::setUp();+ $this->object = new ChartJsCategoryChartGenerator;+}/**@@ -31,7 +42,17 @@ class ChartJsCategoryChartGeneratorTest extends TestCase*/public function testAll(){- $this->markTestIncomplete();+ // make a collection of stuff:+ $collection = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $collection->push([null, 100]);+ }++ $data = $this->object->all($collection);++ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets'][0]['data']);+ $this->assertEquals(100, $data['datasets'][0]['data'][0]);}/**@@ -39,15 +60,18 @@ class ChartJsCategoryChartGeneratorTest extends TestCase*/public function testFrontpage(){- $this->markTestIncomplete();- }+ // make a collection of stuff:+ $collection = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $collection->push(['name' => 'Something', 'sum' => 100]);+ }- /**- * @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::month- */- public function testMonth()- {- $this->markTestIncomplete();+ $data = $this->object->frontpage($collection);++ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets'][0]['data']);+ $this->assertEquals('Something', $data['labels'][0]);+ $this->assertEquals(100, $data['datasets'][0]['data'][0]);}/**@@ -55,6 +79,27 @@ class ChartJsCategoryChartGeneratorTest extends TestCase*/public function testYear(){- $this->markTestIncomplete();+ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->data = 'en';+ $preference->save();++ // mock language preference:+ Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);++ // make a collection of stuff:+ $collection = new Collection;+ $categories = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $categories->push(FactoryMuffin::create('FireflyIII\Models\Category'));+ $collection->push([new Carbon, 100, 100, 100]);+ }++ $data = $this->object->year($categories, $collection);++ $this->assertCount(5, $data['labels']);+ $this->assertEquals($categories->first()->name, $data['labels'][0]);+ $this->assertCount(3, $data['datasets'][0]['data']);++}}\ No newline at end of filediff --git a/tests/generators/ChartJsPiggyBankChartGeneratorTest.php b/tests/generators/ChartJsPiggyBankChartGeneratorTest.phpindex e684baeca8..e63b9d73fd 100644--- a/tests/generators/ChartJsPiggyBankChartGeneratorTest.php+++ b/tests/generators/ChartJsPiggyBankChartGeneratorTest.php@@ -1,10 +1,16 @@<?php+use Carbon\Carbon;+use FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator;+use Illuminate\Support\Collection;+use League\FactoryMuffin\Facade as FactoryMuffin;/*** Class ChartJsPiggyBankChartGeneratorTest*/class ChartJsPiggyBankChartGeneratorTest extends TestCase{+ /** @var ChartJsPiggyBankChartGenerator */+ protected $object;/*** Sets up the fixture, for example, opens a network connection.@@ -14,6 +20,8 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase{parent::setUp();+ $this->object = new ChartJsPiggyBankChartGenerator;+}/**@@ -31,6 +39,28 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase*/public function testHistory(){- $this->markTestIncomplete();+ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->data = 'en';+ $preference->save();++ // mock language preference:+ Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);++ // create a set+ $set = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $obj = new stdClass;+ $obj->date = new Carbon;+ $obj->sum = 100;+ $set->push($obj);+ }++ $data = $this->object->history($set);+ $this->assertCount(5, $data['labels']);+ $this->assertCount(5, $data['datasets'][0]['data']);+ $this->assertEquals(100, $data['datasets'][0]['data'][0]);+ $this->assertEquals(500, $data['datasets'][0]['data'][4]);++}}\ No newline at end of filediff --git a/tests/generators/ChartJsReportChartGeneratorTest.php b/tests/generators/ChartJsReportChartGeneratorTest.phpindex a0e624c735..28f69e8fc2 100644--- a/tests/generators/ChartJsReportChartGeneratorTest.php+++ b/tests/generators/ChartJsReportChartGeneratorTest.php@@ -1,4 +1,9 @@<?php+use Carbon\Carbon;+use FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator;+use Illuminate\Support\Collection;+use League\FactoryMuffin\Facade as FactoryMuffin;+/*** Class ChartJsReportChartGeneratorTest@@ -6,6 +11,9 @@class ChartJsReportChartGeneratorTest extends TestCase{+ /** @var ChartJsReportChartGenerator */+ protected $object;+/*** Sets up the fixture, for example, opens a network connection.* This method is called before a test is executed.@@ -14,6 +22,8 @@ class ChartJsReportChartGeneratorTest extends TestCase{parent::setUp();+ $this->object = new ChartJsReportChartGenerator;+}/**@@ -31,7 +41,25 @@ class ChartJsReportChartGeneratorTest extends TestCase*/public function testYearInOut(){- $this->markTestIncomplete();+ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->data = 'en';+ $preference->save();++ // mock language preference:+ Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);++ // make set:+ $collection = new Collection;+ for ($i = 0; $i < 5; $i++) {+ $collection->push([new Carbon, 200, 100]);+ }++ $data = $this->object->yearInOut($collection);++ $this->assertEquals(200, $data['datasets'][0]['data'][0]);+ $this->assertEquals(100, $data['datasets'][1]['data'][0]);+ $this->assertCount(5, $data['labels']);+}/**@@ -39,6 +67,21 @@ class ChartJsReportChartGeneratorTest extends TestCase*/public function testYearInOutSummarized(){- $this->markTestIncomplete();+ $preference = FactoryMuffin::create('FireflyIII\Models\Preference');+ $preference->data = 'en';+ $preference->save();++ // mock language preference:+ Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);++ // make set:+ $income = 2400;+ $expense = 1200;++ $data = $this->object->yearInOutSummarized($income, $expense, 12);++ $this->assertEquals(200, $data['datasets'][0]['data'][1]);+ $this->assertEquals(100, $data['datasets'][1]['data'][1]);+}}\ No newline at end of file