From 7ffb936aba980460e8eb870d050314e8d6068959 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 20 Jul 2014 21:56:20 +0200 Subject: [PATCH] Trying to fix the tests [skip-ci] --- app/controllers/ChartController.php | 8 +- app/tests/controllers/ChartControllerTest.php | 87 ++++--------------- 2 files changed, 19 insertions(+), 76 deletions(-) diff --git a/app/controllers/ChartController.php b/app/controllers/ChartController.php index c5e1d19549..ba8b7ae7a6 100644 --- a/app/controllers/ChartController.php +++ b/app/controllers/ChartController.php @@ -132,12 +132,13 @@ class ChartController extends BaseController return View::make('charts.info')->with('rows', $result)->with('sum', $sum); } - public function homeCategories() { + public function homeCategories() + { list($start, $end) = tk::getDateRange(); $account = null; $result = []; // grab all transaction journals in this period: - $journals = $this->_journals->getByDateRange($start,$end); + $journals = $this->_journals->getByDateRange($start, $end); $result = []; foreach ($journals as $journal) { @@ -163,12 +164,11 @@ class ChartController extends BaseController arsort($result); $chartData = [ ]; - foreach($result as $name => $value) { + foreach ($result as $name => $value) { $chartData[] = [$name, $value]; } - return Response::json($chartData); } diff --git a/app/tests/controllers/ChartControllerTest.php b/app/tests/controllers/ChartControllerTest.php index 1b915d0377..a4dd9bae9a 100644 --- a/app/tests/controllers/ChartControllerTest.php +++ b/app/tests/controllers/ChartControllerTest.php @@ -1,6 +1,6 @@ mock('Preference'); $pref->shouldReceive('getAttribute', 'data')->andReturn('1M'); + $pref2 = $this->mock('Preference'); + $pref2->shouldReceive('getAttribute', 'data')->andReturn([]); // mock preferences helper: $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); $preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref); + $preferences->shouldReceive('get')->with('frontpageAccounts', [])->once()->andReturn($pref2); + // mock toolkit: $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); @@ -34,6 +38,7 @@ class ChartControllerTest extends TestCase $one = $this->mock('Account'); $one->shouldReceive('getAttribute')->andReturn($personal); $one->shouldReceive('balance')->andReturn(0); + $one->shouldReceive('predict')->andReturn(null); // collection: $c = new \Illuminate\Database\Eloquent\Collection([$one]); @@ -79,57 +84,24 @@ class ChartControllerTest extends TestCase $this->assertResponseOk(); } - public function testhomeBudgets() - { - // mock preference: - $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); - - $start = new \Carbon\Carbon; - $end = new \Carbon\Carbon; - - // mock transaction journal - $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); - $tj->shouldReceive('homeBudgetChart')->andReturn(['entry' => 30]); - - // mock toolkit: - $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); - $toolkit->shouldReceive('getDateRange')->andReturn([$start, $end]); - - - // mock preferences helper: - $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); - $preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref); - - - // call - $this->call('GET', '/chart/home/budgets'); - - // test - $this->assertResponseOk(); - } - public function testhomeCategories() { - // mock preference: - $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); - $start = new \Carbon\Carbon; $end = new \Carbon\Carbon; - // mock transaction journal - $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); - $tj->shouldReceive('homeCategoryChart')->andReturn(['entry' => 30]); + $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); + $toolkit->shouldReceive('getDateRange')->andReturn(null); // mock toolkit: - $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); - $toolkit->shouldReceive('getDateRange')->andReturn([$start, $end]); +// $class = $this->getMockClass('Foo', array('baz')); +// $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); +// $toolkit::static ->shouldReceive('getDateRange')->once()->andReturn([$start, $end]); +// // mock transaction journal +// $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); +// $tj->shouldReceive('getByDateRange')->with($start, $end)->andReturn([]); +// - // mock preferences helper: - $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); - $preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref); // call @@ -139,35 +111,6 @@ class ChartControllerTest extends TestCase $this->assertResponseOk(); } - public function testhomeBeneficiaries() - { - // mock preference: - $pref = $this->mock('Preference'); - $pref->shouldReceive('getAttribute', 'data')->andReturn('week'); - - $start = new \Carbon\Carbon; - $end = new \Carbon\Carbon; - - // mock transaction journal - $tj = $this->mock('Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface'); - $tj->shouldReceive('homeBeneficiaryChart')->andReturn(['entry' => 30]); - - // mock toolkit: - $toolkit = $this->mock('Firefly\Helper\Toolkit\ToolkitInterface'); - $toolkit->shouldReceive('getDateRange')->andReturn([$start, $end]); - - - // mock preferences helper: - $preferences = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface'); - $preferences->shouldReceive('get')->with('viewRange', '1M')->once()->andReturn($pref); - - - // call - $this->call('GET', '/chart/home/beneficiaries'); - - // test - $this->assertResponseOk(); - } public function tearDown() { Mockery::close();