Some generic code refactoring.

This commit is contained in:
James Cole
2019-06-21 19:10:02 +02:00
parent fb1af395f9
commit 2d3d7f7720
67 changed files with 920 additions and 603 deletions

View File

@@ -78,7 +78,7 @@ class ChartJsGeneratorTest extends TestCase
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->multiSet($data);
$this->assertEquals('one', $result['labels'][0]);
@@ -105,7 +105,7 @@ class ChartJsGeneratorTest extends TestCase
];
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->multiCurrencyPieChart($data);
$this->assertEquals('three', $result['labels'][0]);
@@ -126,7 +126,7 @@ class ChartJsGeneratorTest extends TestCase
];
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->multiCurrencyPieChart($data);
$this->assertEquals('three', $result['labels'][0]);
@@ -147,7 +147,7 @@ class ChartJsGeneratorTest extends TestCase
];
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->pieChart($data);
$this->assertEquals('three', $result['labels'][0]);
@@ -168,7 +168,7 @@ class ChartJsGeneratorTest extends TestCase
];
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->pieChart($data);
$this->assertEquals('three', $result['labels'][0]);
@@ -188,7 +188,7 @@ class ChartJsGeneratorTest extends TestCase
];
/** @var ChartJsGenerator $generator */
$generator = new ChartJsGenerator();
$generator = app(ChartJsGenerator::class);
$result = $generator->singleSet('Some label', $data);
$this->assertEquals('one', $result['labels'][0]);

View File

@@ -27,9 +27,7 @@ namespace Tests\Unit\Generator\Report\Audit;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Generator\Report\Audit\MonthReportGenerator;
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use Illuminate\Support\Collection;
@@ -56,187 +54,209 @@ class MonthReportGeneratorTest extends TestCase
/**
* @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
*/
public function testBasic(): void
public function testGetAuditReport(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
$asset = $this->getRandomAsset();
$date = new Carbon;
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$collection = new Collection([$asset]);
$euro = $this->getEuro();
$dollar = $this->getDollar();
$return = [
[
'description' => 'Hello',
'amount' => '10',
'foreign_currency_id' => null,
'currency_id' => $euro->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
],
[
'description' => 'Hello2',
'amount' => '10',
'foreign_amount' => '10',
'foreign_currency_id' => $euro->id,
'currency_id' => $dollar->id,
'source_id' => $asset->id,
'source_name' => $asset->name,
],
];
/** @var MonthReportGenerator $generator */
$generator = app(MonthReportGenerator::class);
return;
/** @var Account $account */
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$date = new Carbon;
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$generator = new MonthReportGenerator();
$generator->setStartDate($start);
$generator->setEndDate($end);
$collection = new Collection;
$generator->setAccounts($collection);
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
// mock calls
Steam::shouldReceive('balance')->times(2)->andReturn('100');
// mock calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
// mock collector:
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('withAccountInformation')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn($return);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro)->once();
try {
$result = $generator->getAuditReport($account, $date);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertFalse($result['exists']);
$this->assertEquals('100', $result['endBalance']);
}
/**
* @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
*/
public function testBasicNoCurrency(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Account $account */
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$date = new Carbon;
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$generator = new MonthReportGenerator();
$generator->setStartDate($start);
$generator->setEndDate($end);
$collection = new Collection;
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
Steam::shouldReceive('balance')->times(1)->andReturn('100');
// mock calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
try {
$generator->getAuditReport($account, $date);
} catch (FireflyException $e) {
$this->assertEquals('Unexpected NULL value in account currency preference.', $e->getMessage());
}
}
/**
* @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
*/
public function testBasicWithForeign(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Account $account */
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$date = new Carbon;
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$generator = new MonthReportGenerator();
$generator->setStartDate($start);
$generator->setEndDate($end);
$collection = new Collection;
$transaction = $this->user()->transactions()->first();
$transaction->transaction_amount = '30';
$transaction->foreign_currency_id = 1;
$transaction->transaction_foreign_amount = '30';
$collection->push($transaction);
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
Steam::shouldReceive('balance')->times(2)->andReturn('100');
// mock calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
try {
$result = $generator->getAuditReport($account, $date);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result['exists']);
$this->assertEquals('100', $result['endBalance']);
}
/**
* @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
*/
public function testBasicWithTransactions(): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
return;
/** @var Account $account */
$account = $this->user()->accounts()->where('account_type_id', 3)->first();
$date = new Carbon;
$start = Carbon::now()->startOfMonth();
$end = Carbon::now()->endOfMonth();
$generator = new MonthReportGenerator();
$generator->setStartDate($start);
$generator->setEndDate($end);
$collection = new Collection;
$transaction = $this->user()->transactions()->first();
$transaction->transaction_amount = '30';
$collection->push($transaction);
// mock stuff
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$collector = $this->mock(TransactionCollectorInterface::class);
Steam::shouldReceive('balance')->times(2)->andReturn('100');
// mock calls:
$accountRepos->shouldReceive('setUser')->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn($collection);
try {
$result = $generator->getAuditReport($account, $date);
$result = $generator->getAuditReport($asset, $date);
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
$this->assertTrue($result['exists']);
$this->assertEquals('100', $result['endBalance']);
}
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicNoCurrency(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(1)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(null)->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertEquals('Unexpected NULL value in account currency preference.', $e->getMessage());
// }
// }
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicWithForeign(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
// $transaction = $this->user()->transactions()->first();
// $transaction->transaction_amount = '30';
// $transaction->foreign_currency_id = 1;
// $transaction->transaction_foreign_amount = '30';
// $collection->push($transaction);
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(2)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $result = $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertTrue(false, $e->getMessage());
// }
// $this->assertTrue($result['exists']);
// $this->assertEquals('100', $result['endBalance']);
// }
//
// /**
// * @covers \FireflyIII\Generator\Report\Audit\MonthReportGenerator
// */
// public function testBasicWithTransactions(): void
// {
// $this->markTestIncomplete('Needs to be rewritten for v4.8.0');
//
// return;
// /** @var Account $account */
// $account = $this->user()->accounts()->where('account_type_id', 3)->first();
// $date = new Carbon;
// $start = Carbon::now()->startOfMonth();
// $end = Carbon::now()->endOfMonth();
// $generator = new MonthReportGenerator();
// $generator->setStartDate($start);
// $generator->setEndDate($end);
//
// $collection = new Collection;
// $transaction = $this->user()->transactions()->first();
// $transaction->transaction_amount = '30';
// $collection->push($transaction);
//
// // mock stuff
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
// $accountRepos = $this->mock(AccountRepositoryInterface::class);
// $collector = $this->mock(TransactionCollectorInterface::class);
// Steam::shouldReceive('balance')->times(2)->andReturn('100');
//
// // mock calls:
// $accountRepos->shouldReceive('setUser')->once();
// $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1')->once();
//
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::first())->once();
//
// $collector->shouldReceive('setAccounts')->andReturnSelf();
// $collector->shouldReceive('setRange')->andReturnSelf();
// $collector->shouldReceive('getTransactions')->andReturn($collection);
//
//
// try {
// $result = $generator->getAuditReport($account, $date);
// } catch (FireflyException $e) {
// $this->assertTrue(false, $e->getMessage());
// }
// $this->assertTrue($result['exists']);
// $this->assertEquals('100', $result['endBalance']);
// }
}