Various code cleanup.

This commit is contained in:
James Cole
2017-03-29 21:20:54 +02:00
parent 569fec4610
commit 5920ccee04
11 changed files with 287 additions and 132 deletions

View File

@@ -7,7 +7,7 @@
* See the LICENSE file for details.
*/
declare(strict_types = 1);
declare(strict_types=1);
namespace Tests\Feature\Controllers\Popup;
@@ -17,6 +17,8 @@ use FireflyIII\Helpers\Collector\JournalCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\Tag;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
@@ -33,12 +35,98 @@ use Tests\TestCase;
class ReportControllerTest extends TestCase
{
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Could not parse end date
*/
public function testBadEndDate()
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'endDate' => 'bla-bla',
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Could not parse start date
*/
public function testBadStartDate()
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => 'bla-bla',
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(500);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
*/
public function testBalanceAmount()
public function testBalanceAmountDefaultNoBudget()
{
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$account = factory(Account::class)->make();
$budgetRepos->shouldReceive('find')->andReturn(new Budget)->once()->withArgs([0]);
$accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]);
$collector->shouldReceive('setAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->once()->andReturnSelf();
$collector->shouldReceive('setTypes')->once()->andReturnSelf();
$collector->shouldReceive('withoutBudget')->once()->andReturnSelf();
$collector->shouldReceive('getJournals')->once()->andReturn(new Collection);
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'balance-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 0,
'role' => 1, // ROLE_DEFAULTROLE
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
*/
public function testBalanceAmountDefaultRole()
{
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
@@ -46,13 +134,56 @@ class ReportControllerTest extends TestCase
$budget = factory(Budget::class)->make();
$account = factory(Account::class)->make();
$budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]);
$accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]);
$collector->shouldReceive('setAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setRange')->once()->andReturnSelf();
$collector->shouldReceive('setBudget')->once()->andReturnSelf();
$collector->shouldReceive('getJournals')->once()->andReturn(new Collection);
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'balance-amount',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
'role' => 1, // ROLE_DEFAULTROLE
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::balanceAmount
*/
public function testBalanceAmountDiffRole()
{
$collector = $this->mock(JournalCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
$budget = factory(Budget::class)->make();
$account = factory(Account::class)->make();
$one = factory(Transaction::class)->make();
$two = factory(Transaction::class)->make();
$tag = factory(Tag::class)->make();
$tag->tagMode = 'balancingAct';
$two->transactionJournal->tags()->save($tag);
$budgetRepos->shouldReceive('find')->andReturn($budget)->once()->withArgs([1]);
$accountRepos->shouldReceive('find')->andReturn($account)->once()->withArgs([1]);
$collector->shouldReceive('setAccounts')->andReturnSelf()->once();
$collector->shouldReceive('setTypes')->withArgs([[TransactionType::WITHDRAWAL]])->andReturnSelf();
$collector->shouldReceive('setRange')->once()->andReturnSelf();
$collector->shouldReceive('withoutBudget')->once()->andReturnSelf();
$collector->shouldReceive('getJournals')->once()->andReturn(new Collection);
$collector->shouldReceive('getJournals')->once()->andReturn(new Collection([$one, $two]));
$this->be($this->user());
$arguments = [
@@ -209,5 +340,29 @@ class ReportControllerTest extends TestCase
$response->assertStatus(200);
}
/**
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::general
* @covers \FireflyIII\Http\Controllers\Popup\ReportController::parseAttributes
* @expectedExceptionMessage Firefly cannot handle
*/
public function testWrongLocation()
{
$this->be($this->user());
$arguments = [
'attributes' => [
'location' => 'bla-bla',
'startDate' => Carbon::now()->startOfMonth()->format('Ymd'),
'endDate' => Carbon::now()->endOfMonth()->format('Ymd'),
'accounts' => 1,
'accountId' => 1,
'categoryId' => 1,
'budgetId' => 1,
],
];
$uri = route('popup.general') . '?' . http_build_query($arguments);
$response = $this->get($uri);
$response->assertStatus(500);
}
}