From 7c5bed2bb593707fcefae8446dae5163634d9bae Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 2 Jan 2017 09:23:24 +0100 Subject: [PATCH] Fix export controller tests. --- .../ExportJob/ExportJobRepository.php | 2 +- .../Controllers/ExportControllerTest.php | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/Repositories/ExportJob/ExportJobRepository.php b/app/Repositories/ExportJob/ExportJobRepository.php index 66458230ec..b83818284a 100644 --- a/app/Repositories/ExportJob/ExportJobRepository.php +++ b/app/Repositories/ExportJob/ExportJobRepository.php @@ -124,7 +124,7 @@ class ExportJobRepository implements ExportJobRepositoryInterface /** * @param string $key * - * @return ExportJob|null + * @return ExportJob */ public function findByKey(string $key): ExportJob { diff --git a/tests/acceptance/Controllers/ExportControllerTest.php b/tests/acceptance/Controllers/ExportControllerTest.php index f0eb8d5716..39a7bd4ebc 100644 --- a/tests/acceptance/Controllers/ExportControllerTest.php +++ b/tests/acceptance/Controllers/ExportControllerTest.php @@ -8,9 +8,13 @@ * * See the LICENSE file for details. */ +use Carbon\Carbon; use FireflyIII\Export\Processor; +use FireflyIII\Export\ProcessorInterface; use FireflyIII\Models\ExportJob; +use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface; +use Illuminate\Support\Collection; /** * Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:41. @@ -70,6 +74,11 @@ class ExportControllerTest extends TestCase */ public function testPostIndex() { + $this->session( + ['first' => new Carbon('2014-01-01')] + ); + + $data = [ 'export_start_range' => '2015-01-01', @@ -78,7 +87,11 @@ class ExportControllerTest extends TestCase 'accounts' => [1], 'job' => 'testExport', ]; - $processor = $this->mock(Processor::class); + + $accountRepository = $this->mock(AccountRepositoryInterface::class); + $accountRepository->shouldReceive('getAccountsById')->withArgs([$data['accounts']])->andReturn(new Collection); + + $processor = $this->mock(ProcessorInterface::class); $processor->shouldReceive('collectJournals')->once(); $processor->shouldReceive('convertJournals')->once(); $processor->shouldReceive('exportJournals')->once(); @@ -88,8 +101,8 @@ class ExportControllerTest extends TestCase $repository->shouldReceive('changeStatus')->andReturn(true); $repository->shouldReceive('findByKey')->andReturn(new ExportJob); - $this->be($this->user()); + $this->call('post', route('export.export'), $data); $this->assertResponseStatus(200); $this->see('ok');