mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-19 16:10:00 +00:00
Speed up various tests.
This commit is contained in:
@@ -262,7 +262,7 @@ class BudgetController extends Controller
|
|||||||
$journals->setPath('/budgets/show/' . $budget->id);
|
$journals->setPath('/budgets/show/' . $budget->id);
|
||||||
|
|
||||||
|
|
||||||
$set = $budget->budgetlimits()->orderBy('start_date', 'DESC')->get();
|
$set = $repository->getBudgetLimits($budget, $start, $end);
|
||||||
$subTitle = e($budget->name);
|
$subTitle = e($budget->name);
|
||||||
$limits = new Collection();
|
$limits = new Collection();
|
||||||
|
|
||||||
|
|||||||
@@ -291,7 +291,7 @@ class BudgetRepository implements BudgetRepositoryInterface
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
)->get(['budget_limits.*']);
|
)->orderBy('budget_limits.start_date','DESC')->get(['budget_limits.*']);
|
||||||
|
|
||||||
return $set;
|
return $set;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,13 @@
|
|||||||
*
|
*
|
||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
use Carbon\Carbon;
|
||||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,11 +112,19 @@ class AccountControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow(string $range)
|
public function testShow(string $range)
|
||||||
{
|
{
|
||||||
|
$date = new Carbon;
|
||||||
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
$tasker = $this->mock(AccountTaskerInterface::class);
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
||||||
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
||||||
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
||||||
|
|
||||||
|
// mock repository:
|
||||||
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('oldestJournalDate')->andReturn(clone $date);
|
||||||
|
$repository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
|
|
||||||
$collector = $this->mock(JournalCollectorInterface::class);
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
||||||
$collector->shouldReceive('setRange')->andReturnSelf();
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
|||||||
@@ -8,7 +8,12 @@
|
|||||||
*
|
*
|
||||||
* See the LICENSE file for details.
|
* See the LICENSE file for details.
|
||||||
*/
|
*/
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||||
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,6 +75,7 @@ class BudgetControllerTest extends TestCase
|
|||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
$this->session(['budgets.delete.url' => 'http://localhost']);
|
$this->session(['budgets.delete.url' => 'http://localhost']);
|
||||||
|
|
||||||
$repository = $this->mock(BudgetRepositoryInterface::class);
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
$repository->shouldReceive('destroy')->andReturn(true);
|
$repository->shouldReceive('destroy')->andReturn(true);
|
||||||
|
|
||||||
@@ -99,6 +105,13 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIndex(string $range)
|
public function testIndex(string $range)
|
||||||
{
|
{
|
||||||
|
$repository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$repository->shouldReceive('cleanupBudgets');
|
||||||
|
$repository->shouldReceive('getActiveBudgets')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('getInactiveBudgets')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('getAvailableBudget')->andReturn('100.123');
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$this->call('GET', route('budgets.index'));
|
$this->call('GET', route('budgets.index'));
|
||||||
@@ -115,6 +128,18 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNoBudget(string $range)
|
public function testNoBudget(string $range)
|
||||||
{
|
{
|
||||||
|
$date = new Carbon();
|
||||||
|
$this->session(['start' => $date, 'end' => clone $date]);
|
||||||
|
|
||||||
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withoutBudget')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$this->call('GET', route('budgets.no-budget'));
|
$this->call('GET', route('budgets.no-budget'));
|
||||||
@@ -129,7 +154,7 @@ class BudgetControllerTest extends TestCase
|
|||||||
public function testPostUpdateIncome()
|
public function testPostUpdateIncome()
|
||||||
{
|
{
|
||||||
$data = [
|
$data = [
|
||||||
'amount' => '200',
|
'amount' => '200',
|
||||||
];
|
];
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->call('post', route('budgets.income.post'), $data);
|
$this->call('post', route('budgets.income.post'), $data);
|
||||||
@@ -144,6 +169,30 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShow(string $range)
|
public function testShow(string $range)
|
||||||
{
|
{
|
||||||
|
$date = new Carbon();
|
||||||
|
$date->subDay();
|
||||||
|
$this->session(['first' => $date]);
|
||||||
|
|
||||||
|
// mock account repository
|
||||||
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
|
|
||||||
|
// mock budget repository
|
||||||
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$budgetRepository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||||
|
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||||
|
// mock journal collector:
|
||||||
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$this->call('GET', route('budgets.show', [1]));
|
$this->call('GET', route('budgets.show', [1]));
|
||||||
@@ -159,6 +208,25 @@ class BudgetControllerTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testShowByBudgetLimit(string $range)
|
public function testShowByBudgetLimit(string $range)
|
||||||
{
|
{
|
||||||
|
// mock account repository
|
||||||
|
$accountRepository = $this->mock(AccountRepositoryInterface::class);
|
||||||
|
$accountRepository->shouldReceive('getAccountsByType')->andReturn(new Collection);
|
||||||
|
|
||||||
|
// mock budget repository
|
||||||
|
$budgetRepository = $this->mock(BudgetRepositoryInterface::class);
|
||||||
|
$budgetRepository->shouldReceive('spentInPeriod')->andReturn('1');
|
||||||
|
|
||||||
|
// mock journal collector:
|
||||||
|
$collector = $this->mock(JournalCollectorInterface::class);
|
||||||
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('setBudget')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('withCategoryInformation')->andReturnSelf();
|
||||||
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
||||||
|
|
||||||
|
|
||||||
$this->be($this->user());
|
$this->be($this->user());
|
||||||
$this->changeDateRange($this->user(), $range);
|
$this->changeDateRange($this->user(), $range);
|
||||||
$this->call('GET', route('budgets.show.limit', [1, 1]));
|
$this->call('GET', route('budgets.show.limit', [1, 1]));
|
||||||
@@ -181,14 +249,6 @@ class BudgetControllerTest extends TestCase
|
|||||||
$this->call('post', route('budgets.store'), $data);
|
$this->call('post', route('budgets.store'), $data);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success');
|
$this->assertSessionHas('success');
|
||||||
|
|
||||||
// must be in list
|
|
||||||
$this->be($this->user());
|
|
||||||
$this->call('GET', route('budgets.index'));
|
|
||||||
$this->assertResponseStatus(200);
|
|
||||||
$this->see('<ol class="breadcrumb">');
|
|
||||||
$this->see($data['name']);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,14 +266,7 @@ class BudgetControllerTest extends TestCase
|
|||||||
$this->call('post', route('budgets.update', [1]), $data);
|
$this->call('post', route('budgets.update', [1]), $data);
|
||||||
$this->assertResponseStatus(302);
|
$this->assertResponseStatus(302);
|
||||||
$this->assertSessionHas('success');
|
$this->assertSessionHas('success');
|
||||||
|
}
|
||||||
// must be in list
|
|
||||||
$this->be($this->user());
|
|
||||||
$this->call('GET', route('budgets.index'));
|
|
||||||
$this->assertResponseStatus(200);
|
|
||||||
$this->see('<ol class="breadcrumb">');
|
|
||||||
$this->see($data['name']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \FireflyIII\Http\Controllers\BudgetController::updateIncome
|
* @covers \FireflyIII\Http\Controllers\BudgetController::updateIncome
|
||||||
|
|||||||
Reference in New Issue
Block a user