Fix test coverage.

This commit is contained in:
James Cole
2019-01-27 12:30:52 +01:00
parent c3e6e4f034
commit f6d88521dd
6 changed files with 55 additions and 38 deletions

View File

@@ -80,7 +80,7 @@ class AccountControllerTest extends TestCase
$end = [$firstId => [1 => '121.45', 2 => '234.01',], $secondId => [1 => '121.45', 2 => '234.01',],];
// return them when collected:
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE, AccountType::BENEFICIARY]])->andReturn($accounts);
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::EXPENSE]])->andReturn($accounts);
// and return start and end balances:
Steam::shouldReceive('balancesPerCurrencyByAccounts')->twice()->andReturn($start, $end);

View File

@@ -83,16 +83,37 @@ class CategoryControllerTest extends TestCase
*
* @param string $range
*/
public function testFrontpage(string $range): void
public function testFrontPage(string $range): void
{
$repository = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// spent per currency data:
$spentData = [
1 => '-123.45',
2 => '567.21',
$spentNoCategory = [
1 =>
[
'spent' => '-123.45',
'currency_id' => 1,
'currency_code' => 'X',
'currency_symbol' => 'x',
'currency_decimal_places' => 2,
],
];
$spentData = [
1 => [
'name' => 'Car',
'spent' => [
1 => [
'spent' => '-123.45',
'currency_id' => 2,
'currency_code' => 'a',
'currency_symbol' => 'b',
'currency_decimal_places' => 2,
],
],
],
];
// grab two categories from the user
@@ -105,20 +126,10 @@ class CategoryControllerTest extends TestCase
$repository->shouldReceive('getCategories')->andReturn($categories)->once();
$accountRepos->shouldReceive('getAccountsByType')->once()->withArgs([[AccountType::ASSET, AccountType::DEFAULT]])->andReturn($accounts);
$repository->shouldReceive('spentInPeriodPerCurrency')
->times(2)->andReturn($spentData);
$repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentData);
$repository->shouldReceive('spentInPeriodPerCurrency')->times(2)->andReturn($spentData);
$repository->shouldReceive('spentInPeriodPcWoCategory')->once()->andReturn($spentNoCategory);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->once()->andReturn(TransactionCurrency::find(1));
$currencyRepos->shouldReceive('findNull')->withArgs([2])->once()->andReturn(TransactionCurrency::find(2));
//$category = factory(Category::class)->make();
//$account = factory(Account::class)->make();
// $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection([$account]));
// $repository->shouldReceive('spentInPeriod')->andReturn('0');
// $repository->shouldReceive('spentInPeriodWithoutCategory')->andReturn('0');
$generator->shouldReceive('multiSet')->andReturn([]);
$this->be($this->user());
@@ -132,10 +143,10 @@ class CategoryControllerTest extends TestCase
*/
public function testReportPeriod(): void
{
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('periodExpenses')->andReturn([])->once();
@@ -152,10 +163,10 @@ class CategoryControllerTest extends TestCase
*/
public function testReportPeriodNoCategory(): void
{
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$repository = $this->mock(CategoryRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$repository->shouldReceive('periodExpensesNoCategory')->andReturn([])->once();
@@ -179,8 +190,8 @@ class CategoryControllerTest extends TestCase
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$generator = $this->mock(GeneratorInterface::class);
$account = factory(Account::class)->make();
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$date = new Carbon;
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);