mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Better mocking of objects.
This commit is contained in:
parent
bf9c1c1875
commit
0d5efb8d27
@ -28,14 +28,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
return $app;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return User::find(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User
|
||||
*/
|
||||
@ -44,7 +36,6 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
||||
return 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\TestCase
|
||||
touch($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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -22,12 +22,10 @@ class ChartBudgetControllerTest extends TestCase
|
||||
public 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());
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user