Speed up some tests.

This commit is contained in:
James Cole 2016-12-22 07:13:37 +01:00
parent 782e2add88
commit e08e7b2c9b
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
6 changed files with 62 additions and 5 deletions

View File

@ -47,7 +47,8 @@
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*",
"barryvdh/laravel-debugbar": "2.*",
"barryvdh/laravel-ide-helper": "2.*"
"barryvdh/laravel-ide-helper": "2.*",
"johnkary/phpunit-speedtrap": "^1.0"
},
"autoload": {
"classmap": [

View File

@ -8,6 +8,9 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</directory>

View File

@ -287,7 +287,7 @@ Route::group(
Route::group(
['middleware' => 'user-full-auth', 'namespace' => 'Chart', 'prefix' => 'chart/category', 'as' => 'chart.category.'], function () {
Route::get('frontpage', ['uses' => 'CategoryController@frontpage']);
Route::get('frontpage', ['uses' => 'CategoryController@frontpage', 'as' => 'frontpage']);
Route::get('period/{category}', ['uses' => 'CategoryController@currentPeriod', 'as' => 'current']);
Route::get('period/{category}/{date}', ['uses' => 'CategoryController@specificPeriod', 'as' => 'specific']);
Route::get('all/{category}', ['uses' => 'CategoryController@all', 'as' => 'all']);

View File

@ -8,8 +8,11 @@
*
* See the LICENSE file for details.
*/
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Account\AccountTaskerInterface;
use Illuminate\Pagination\LengthAwarePaginator;
/**
@ -105,10 +108,18 @@ class AccountControllerTest extends TestCase
public function testShow(string $range)
{
$tasker = $this->mock(\FireflyIII\Repositories\Account\AccountTaskerInterface::class);
$tasker = $this->mock(AccountTaskerInterface::class);
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
$collector = $this->mock(JournalCollectorInterface::class);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('accounts.show', [1]));

View File

@ -11,6 +11,8 @@
namespace Chart;
use Carbon\Carbon;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use TestCase;
/**
@ -37,6 +39,11 @@ class BudgetControllerTest extends TestCase
*/
public function testBudget(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('firstUseDate')->andReturn(new Carbon('2015-01-01'));
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.budget.budget', [1]));
@ -51,9 +58,12 @@ class BudgetControllerTest extends TestCase
*/
public function testBudgetLimit(string $range)
{
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('-100');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.budget.budget', [1,1]));
$this->call('get', route('chart.budget.budget-limit', [1,1]));
$this->assertResponseStatus(200);
}

View File

@ -12,7 +12,9 @@
namespace Chart;
use Carbon\Carbon;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use Illuminate\Support\Collection;
use TestCase;
/**
@ -54,12 +56,22 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::currentPeriod
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testCurrentPeriod(string $range)
{
// this is actually for makePeriodChart
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.current', [1]));
@ -74,9 +86,21 @@ class CategoryControllerTest extends TestCase
*/
public function testFrontpage(string $range)
{
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
$category = $this->user()->categories()->first();
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
// get one category
$categoryRepository->shouldReceive('getCategories')->andReturn(new Collection([$category]));
// get one account
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
// always return zero
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.current', [1]));
$this->call('get', route('chart.category.frontpage', [1]));
$this->assertResponseStatus(200);
}
@ -102,12 +126,20 @@ class CategoryControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::specificPeriod
* @covers \FireflyIII\Http\Controllers\Chart\CategoryController::makePeriodChart
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testSpecificPeriod(string $range)
{
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$categoryRepository = $this->mock(CategoryRepositoryInterface::class);
$account = $this->user()->accounts()->where('account_type_id', 5)->first();
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
$categoryRepository->shouldReceive('spentInPeriod')->andReturn('0');
$categoryRepository->shouldReceive('earnedInPeriod')->andReturn('0');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('get', route('chart.category.specific', ['1', '2012-01-01']));