Improve test coverage.

This commit is contained in:
James Cole
2019-07-24 19:02:41 +02:00
parent 226e2f7185
commit ee95606ec0
39 changed files with 378 additions and 234 deletions

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
@@ -46,6 +47,9 @@ use Tests\TestCase;
/**
* Class AccountControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class AccountControllerTest extends TestCase
{
@@ -110,14 +114,15 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testExpenseBudget(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
@@ -157,8 +162,8 @@ class AccountControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$budget = $this->user()->budgets()->find($withdrawal['budget_id']);
@@ -188,14 +193,15 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testExpenseCategory(string $range): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
@@ -238,7 +244,7 @@ class AccountControllerTest extends TestCase
$collector = $this->mock(GroupCollectorInterface::class);
$categoryRepos = $this->mock(CategoryRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$this->mock(CurrencyRepositoryInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$category = $this->user()->categories()->find($withdrawal['category_id']);
@@ -267,6 +273,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testFrontpage(string $range): void
{
@@ -304,6 +311,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testIncomeCategory(string $range): void
{
@@ -382,6 +390,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testPeriod(string $range): void
{
@@ -444,6 +453,7 @@ class AccountControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testRevenueAccounts(string $range): void
{

View File

@@ -23,6 +23,7 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
@@ -38,6 +39,9 @@ use Tests\TestCase;
/**
* Class CategoryControllerTest
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class CategoryControllerTest extends TestCase
{
@@ -55,6 +59,7 @@ class CategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws FireflyException
*/
public function testAll(string $range): void
{
@@ -221,6 +226,7 @@ class CategoryControllerTest extends TestCase
* @dataProvider dateRangeProvider
*
* @param string $range
* @throws Exception
*/
public function testSpecificPeriod(string $range): void
{

View File

@@ -25,7 +25,6 @@ namespace Tests\Feature\Controllers\Chart;
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Basic\GeneratorInterface;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Helpers\Fiscal\FiscalHelperInterface;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
@@ -82,4 +81,40 @@ class ExpenseReportControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* Same test, but with a deposit
* @covers \FireflyIII\Http\Controllers\Chart\ExpenseReportController
*/
public function testMainChartDeposit(): void
{
$generator = $this->mock(GeneratorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$accountRepository = $this->mock(AccountRepositoryInterface::class);
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$expense = $this->getRandomExpense();
$date = new Carbon;
$deposit = $this->getRandomDepositAsArray();
$accountRepository->shouldReceive('findByName')->once()->andReturn($expense);
$this->mockDefaultSession();
Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
$fiscalHelper->shouldReceive('endOfFiscalYear')->atLeast()->once()->andReturn($date);
$fiscalHelper->shouldReceive('startOfFiscalYear')->atLeast()->once()->andReturn($date);
$collector->shouldReceive('setAccounts')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setRange')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('withAccountInformation')->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::DEPOSIT]])->andReturnSelf()->atLeast()->once();
$collector->shouldReceive('getExtractedJournals')->andReturn([$deposit])->atLeast()->once();
$generator->shouldReceive('multiSet')->andReturn([])->once();
$this->be($this->user());
$response = $this->get(route('chart.expense.main', ['1', $expense->id, '20120101', '20120131']));
$response->assertStatus(200);
}
}

View File

@@ -200,7 +200,7 @@ class TagReportControllerTest extends TestCase
$fiscalHelper = $this->mock(FiscalHelperInterface::class);
$withdrawal = $this->getRandomWithdrawalAsArray();
$tag = $this->user()->tags()->where('tag','Expensive')->first();
$tag = $this->user()->tags()->where('tag', 'Expensive')->first();
$date = new Carbon;
$false = new Preference;
$false->data = false;
@@ -237,7 +237,7 @@ class TagReportControllerTest extends TestCase
$generator = $this->mock(GeneratorInterface::class);
$pieChart = $this->mock(MetaPieChartInterface::class);
$tagRepos = $this->mock(TagRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$this->mock(AccountRepositoryInterface::class);
$tag = $this->user()->tags()->first();
$tagRepos->shouldReceive('setUser');
$tagRepos->shouldReceive('get')->andReturn(new Collection([$tag]));