Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Better mocking of objects.
James Cole0d5efb8d27d3
diff --git a/tests/TestCase.php b/tests/TestCase.phpindex b77659a6f1..9ed7149f88 100755--- a/tests/TestCase.php+++ b/tests/TestCase.php@@ -28,14 +28,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCasereturn $app;}- /**- * @return User- */- public function user()- {- return User::find(1);- }-/*** @return User*/@@ -44,7 +36,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCasereturn User::find(2);}-/*** Sets up the fixture, for example, opens a network connection.* This method is called before a test is executed.@@ -65,7 +56,7 @@ class TestCase extends Illuminate\Foundation\Testing\TestCasetouch($original);Artisan::call('migrate', ['--seed' => true]);}-+copy($original, $copy);} else {if (file_exists($copy)) {@@ -99,5 +90,28 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase}+ /**+ * @return User+ */+ public function user()+ {+ return User::find(1);+ }++ /**+ * @param string $class+ *+ * @return \Mockery\MockInterface+ */+ protected function mock($class)+ {+ $object = Mockery::mock($class);+++ $this->app->instance($class, $object);++ return $object;+ }+}diff --git a/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php b/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.phpindex 78d71b7930..2e16d198af 100644--- a/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php+++ b/tests/acceptance/Controllers/Chart/ChartBudgetControllerTest.php@@ -22,12 +22,10 @@ class ChartBudgetControllerTest extends TestCasepublic function testBudget(){- $repository = Mockery::mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');$repository->shouldReceive('getExpensesPerMonth')->once()->andReturn(new Collection([new Budget]));$repository->shouldReceive('getFirstBudgetLimitDate')->once()->andReturn(new Carbon);- $this->app->instance('FireflyIII\Repositories\Budget\BudgetRepositoryInterface', $repository);-$this->be($this->user());$response = $this->call('GET', '/chart/budget/1');$this->assertEquals(200, $response->status());@@ -67,13 +65,10 @@ class ChartBudgetControllerTest extends TestCase$budget->dateFormatted = '2015';$budget->budgeted = 120;- $repository = Mockery::mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');$repository->shouldReceive('getBudgetedPerYear')->once()->andReturn(new Collection([$budget]));$repository->shouldReceive('getBudgetsAndExpensesPerYear')->once()->andReturn([]);- $this->app->instance('FireflyIII\Repositories\Budget\BudgetRepositoryInterface', $repository);--$this->be($this->user());$response = $this->call('GET', '/chart/budget/multi-year/default/20150101/20160101/1/1');$this->assertEquals(200, $response->status());@@ -85,11 +80,9 @@ class ChartBudgetControllerTest extends TestCase*/public function testYear(){- $repository = Mockery::mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');$repository->shouldReceive('getBudgetsAndExpensesPerMonth')->once()->andReturn([]);- $this->app->instance('FireflyIII\Repositories\Budget\BudgetRepositoryInterface', $repository);-$this->be($this->user());$response = $this->call('GET', '/chart/budget/year/default/20150101/20151231/1');$this->assertEquals(200, $response->status());diff --git a/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php b/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.phpindex 09041d064a..d10eee721a 100644--- a/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php+++ b/tests/acceptance/Controllers/Chart/ChartCategoryControllerTest.php@@ -41,11 +41,9 @@ class ChartCategoryControllerTest extends TestCase*/public function testEarnedInPeriod(){- $repository = Mockery::mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$repository->shouldReceive('earnedForAccountsPerMonth')->once()->andReturn(new Collection);- $this->app->instance('FireflyIII\Repositories\Category\CategoryRepositoryInterface', $repository);-$this->be($this->user());$response = $this->call('GET', '/chart/category/earned-in-period/default/20150101/20151231/1');$this->assertEquals(200, $response->status());@@ -56,13 +54,10 @@ class ChartCategoryControllerTest extends TestCase*/public function testFrontpage(){- $repository = Mockery::mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$repository->shouldReceive('spentForAccountsPerMonth')->once()->andReturn(new Collection);$repository->shouldReceive('sumSpentNoCategory')->once()->andReturn('120');- $this->app->instance('FireflyIII\Repositories\Category\CategoryRepositoryInterface', $repository);--$this->be($this->user());$response = $this->call('GET', '/chart/category/frontpage');$this->assertEquals(200, $response->status());@@ -73,11 +68,9 @@ class ChartCategoryControllerTest extends TestCase*/public function testMultiYear(){- $repository = Mockery::mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$repository->shouldReceive('listMultiYear')->once()->andReturn(new Collection);- $this->app->instance('FireflyIII\Repositories\Category\CategoryRepositoryInterface', $repository);-$this->be($this->user());$response = $this->call('GET', '/chart/category/multi-year/default/20150101/20151231/1/1');$this->assertEquals(200, $response->status());@@ -101,11 +94,9 @@ class ChartCategoryControllerTest extends TestCase{- $repository = Mockery::mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');+ $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface');$repository->shouldReceive('spentForAccountsPerMonth')->once()->andReturn(new Collection);- $this->app->instance('FireflyIII\Repositories\Category\CategoryRepositoryInterface', $repository);-$this->be($this->user());$response = $this->call('GET', '/chart/category/spent-in-period/default/20150101/20151231/1');$this->assertEquals(200, $response->status());