Refactored a lot of tests.

This commit is contained in:
James Cole
2019-07-21 17:15:06 +02:00
parent 5242c0368b
commit b7a4b0fdfd
58 changed files with 1847 additions and 1564 deletions

View File

@@ -22,19 +22,20 @@ declare(strict_types=1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\Account;
use Amount;
use Event;
use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Models\AccountType;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\Preference;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Preferences;
use Steam;
use Tests\TestCase;
/**
@@ -61,12 +62,7 @@ class HomeControllerTest extends TestCase
*/
public function testDateRange(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
$this->be($this->user());
$args = [
@@ -84,12 +80,7 @@ class HomeControllerTest extends TestCase
*/
public function testDateRangeCustom(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->mockDefaultSession();
$this->be($this->user());
$args = [
@@ -104,7 +95,6 @@ class HomeControllerTest extends TestCase
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\Controller
* @dataProvider dateRangeProvider
@@ -113,42 +103,54 @@ class HomeControllerTest extends TestCase
*/
public function testIndex(string $range): void
{
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
Event::fake();
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_index');
$account = $this->getRandomAsset();
return;
$pref = new Preference;
$pref->data = [$account->id];
Preferences::shouldReceive('get')->withArgs(['frontPageAccounts', [$account->id]])->atLeast()->once()->andReturn($pref);
//Preferences::shouldReceive('lastActivity')->atLeast()->once()->andReturn('md512345');
//FireflyConfig::shouldReceive('set')->withArgs(['last_update_check', Mockery::any()])->once()->andReturn(new Configuration);
Amount::shouldReceive('formatAnything')->atLeast()->once()->andReturn('x');
Steam::shouldReceive('balance')->atLeast()->once()->andReturn('5');
// mock stuff
$account = factory(Account::class)->make();
$collector = $this->mock(TransactionCollectorInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$billRepos = $this->mock(BillRepositoryInterface::class);
$collector = $this->mock(GroupCollectorInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$euro = $this->getEuro();
// $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
//
//
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(1);
$accountRepos->shouldReceive('count')->andReturn(1)->atLeast()->once();
$accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'currency_id'])->andReturn('1');
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]));
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]));
$billRepos->shouldReceive('getBills')->andReturn(new Collection);
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1));
$accountRepos->shouldReceive('getAccountsByType')->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->atLeast()->once();
$accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account]))->atLeast()->once();
$accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();
$billRepos->shouldReceive('getBills')->andReturn(new Collection)->atLeast()->once();
// $currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn($euro);
$collector->shouldReceive('setAccounts')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setRange')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setLimit')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('setPage')->atLeast()->once()->andReturnSelf();
$collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection);
$collector->shouldReceive('setAccounts')->andReturnSelf();
$collector->shouldReceive('setRange')->andReturnSelf();
$collector->shouldReceive('setLimit')->andReturnSelf();
$collector->shouldReceive('setPage')->andReturnSelf();
$collector->shouldReceive('getTransactions')->andReturn(new Collection);
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$response = $this->get(route('index'));
$response->assertStatus(200);
Event::assertDispatched(RequestedVersionCheckStatus::class);
}
/**
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\HomeController
* @covers \FireflyIII\Http\Controllers\Controller
* @dataProvider dateRangeProvider
@@ -157,12 +159,10 @@ class HomeControllerTest extends TestCase
*/
public function testIndexEmpty(string $range): void
{
$this->mockDefaultSession();
$this->mockIntroPreference('shown_demo_index');
// mock stuff
$accountRepos = $this->mock(AccountRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$accountRepos->shouldReceive('count')->andReturn(0);
$this->be($this->user());