Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Speed up some tests.
James Colee08e7b2c9b48
diff --git a/composer.json b/composer.jsonindex 7deaaacb03..27a784e1bf 100755--- a/composer.json+++ b/composer.json@@ -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": [diff --git a/phpunit.xml b/phpunit.xmlindex 478d78f2b6..5e3d64c04c 100755--- a/phpunit.xml+++ b/phpunit.xml@@ -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>diff --git a/routes/web.php b/routes/web.phpindex 515573629e..e053bf6acd 100755--- a/routes/web.php+++ b/routes/web.php@@ -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']);diff --git a/tests/acceptance/Controllers/AccountControllerTest.php b/tests/acceptance/Controllers/AccountControllerTest.phpindex 4120968399..fb03855828 100644--- a/tests/acceptance/Controllers/AccountControllerTest.php+++ b/tests/acceptance/Controllers/AccountControllerTest.php@@ -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 TestCasepublic 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]));diff --git a/tests/acceptance/Controllers/Chart/BudgetControllerTest.php b/tests/acceptance/Controllers/Chart/BudgetControllerTest.phpindex a42033a4ef..dd9b49586b 100644--- a/tests/acceptance/Controllers/Chart/BudgetControllerTest.php+++ b/tests/acceptance/Controllers/Chart/BudgetControllerTest.php@@ -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);}diff --git a/tests/acceptance/Controllers/Chart/CategoryControllerTest.php b/tests/acceptance/Controllers/Chart/CategoryControllerTest.phpindex 3504ad79d5..06af5d366c 100644--- a/tests/acceptance/Controllers/Chart/CategoryControllerTest.php+++ b/tests/acceptance/Controllers/Chart/CategoryControllerTest.php@@ -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']));