Mock more repositories in tests.

This commit is contained in:
James Cole
2018-09-03 18:52:46 +02:00
parent 480b636c7e
commit 46ba0a5a5a
137 changed files with 496 additions and 222 deletions

View File

@@ -26,8 +26,10 @@ use FireflyIII\Models\Attachment;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use Illuminate\Support\Collection;
use Log;
use Mockery;
use Tests\TestCase;
/**
@@ -45,7 +47,7 @@ class AttachmentControllerTest extends TestCase
public function setUp(): void
{
parent::setUp();
Log::debug(sprintf('Now in %s.', \get_class($this)));
Log::info(sprintf('Now in %s.', \get_class($this)));
}
/**
@@ -56,6 +58,10 @@ class AttachmentControllerTest extends TestCase
// mock stuff
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.delete', [1]));
@@ -72,6 +78,8 @@ class AttachmentControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -90,6 +98,8 @@ class AttachmentControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -103,13 +113,14 @@ class AttachmentControllerTest extends TestCase
/**
* @covers \FireflyIII\Http\Controllers\AttachmentController
* @expectedExceptionMessage Could not find the indicated attachment
*/
public function testDownloadFail(): void
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(false);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -125,6 +136,10 @@ class AttachmentControllerTest extends TestCase
{
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$attachRepository->shouldReceive('getNoteText')->andReturn('OK');
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
@@ -140,6 +155,9 @@ class AttachmentControllerTest extends TestCase
public function testIndex()
{
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
$repository->shouldReceive('get')->andReturn(new Collection([Attachment::first()]))->once();
$repository->shouldReceive('exists')->andReturn(true)->once();
@@ -159,6 +177,8 @@ class AttachmentControllerTest extends TestCase
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
@@ -181,11 +201,14 @@ class AttachmentControllerTest extends TestCase
*/
public function testView(): void
{
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.view', [3]));
@@ -198,10 +221,13 @@ class AttachmentControllerTest extends TestCase
*/
public function testViewFail(): void
{
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$userRepos = $this->mock(UserRepositoryInterface::class);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(false);
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.view', [1]));