Expand test coverage.

This commit is contained in:
James Cole
2019-07-26 17:48:24 +02:00
parent 6ff4a0b45c
commit d94d34ca63
57 changed files with 2243 additions and 1597 deletions

View File

@@ -56,7 +56,7 @@ class BunqRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brY_' . random_int(1, 10000);
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'bunq';
@@ -96,7 +96,7 @@ class BunqRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brY_' . random_int(1, 10000);
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'bunq';
@@ -140,7 +140,7 @@ class BunqRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'brX_' . random_int(1, 10000);
$job->key = 'brX_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'bunq';

View File

@@ -55,7 +55,7 @@ class FakeRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . random_int(1, 10000);
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'ahoy';
$job->provider = 'fake';
@@ -91,7 +91,7 @@ class FakeRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . random_int(1, 10000);
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'final';
$job->provider = 'fake';
@@ -128,7 +128,7 @@ class FakeRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_route_' . random_int(1, 10000);
$job->key = 'a_route_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'fake';

View File

@@ -25,9 +25,11 @@ namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\BunqRoutine;
use FireflyIII\Import\Routine\FileRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
use FireflyIII\Support\Import\Routine\File\CSVProcessor;
use Log;
use Mockery;
@@ -55,35 +57,35 @@ class FileRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_fr_' . random_int(1, 10000);
$job->key = 'brY_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'ready_to_run';
$job->provider = 'file';
$job->stage = 'go-for-import';
$job->provider = 'bunq';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock
$processor = $this->mock(CSVProcessor::class);
// mock stuff:
$repository = $this->mock(ImportJobRepositoryInterface::class);
$handler = $this->mock(StageImportDataHandler::class);
// calls
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once();
$repository->shouldReceive('getConfiguration')->withArgs([Mockery::any()])->once()->andReturn([]);
$processor->shouldReceive('setImportJob')->once();
$processor->shouldReceive('run')->once()->andReturn(['a' => 'b']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']);
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']);
$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
$routine = new FileRoutine;
$handler->shouldReceive('setImportJob')->once();
$handler->shouldReceive('run')->once();
$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
$handler->shouldReceive('isStillRunning')->andReturn(false);
$routine = new BunqRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
$this->assertFalse(true, $e->getMessage());
}
}
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* FinTSRoutineTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Tests\Unit\Import\Routine;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Import\Routine\FinTSRoutine;
use FireflyIII\Models\ImportJob;
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
use FireflyIII\Support\Import\Routine\FinTS\StageImportDataHandler;
use Log;
use Mockery;
use Tests\TestCase;
/**
* Class FinTSRoutineTest
*/
class FinTSRoutineTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
Log::info(sprintf('Now in %s.', get_class($this)));
}
/**
* @covers \FireflyIII\Import\Routine\FinTSRoutine
*/
public function testRunDefault(): void
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'a_fin_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'fints';
$job->file_type = '';
$job->configuration = [];
$job->save();
// mock
$handler = $this->mock(StageImportDataHandler::class);
$repository = $this->mock(ImportJobRepositoryInterface::class);
// calls
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running'])->once();
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->once();
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final'])->once();
$repository->shouldReceive('setTransactions')->withArgs([Mockery::any(), ['a' => 'b']])->once();
$handler->shouldReceive('setImportJob')->atLeast()->once();
$handler->shouldReceive('run')->once()->atLeast()->once();
$handler->shouldReceive('getTransactions')->atLeast()->once()->andReturn(['a' => 'b']);
$routine = new FinTSRoutine;
$routine->setImportJob($job);
try {
$routine->run();
} catch (FireflyException $e) {
$this->assertTrue(false, $e->getMessage());
}
}
}

View File

@@ -57,7 +57,7 @@ class SpectreRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR2b' . random_int(1, 10000);
$job->key = 'SR2b' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'authenticated';
$job->provider = 'spectre';
@@ -95,7 +95,7 @@ class SpectreRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR1A' . random_int(1, 10000);
$job->key = 'SR1A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'do-authenticate';
$job->provider = 'spectre';
@@ -126,7 +126,7 @@ class SpectreRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR3c' . random_int(1, 10000);
$job->key = 'SR3c' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'spectre';
@@ -165,7 +165,7 @@ class SpectreRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR4A' . random_int(1, 10000);
$job->key = 'SR4A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'spectre';
@@ -205,7 +205,7 @@ class SpectreRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'SR5A' . random_int(1, 10000);
$job->key = 'SR5A' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'new';
$job->provider = 'spectre';

View File

@@ -57,7 +57,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_7_' . random_int(1, 10000);
$job->key = 'ynab_r_7_' . $this->randomInt();
$job->status = 'not_ready_to_run';
$job->stage = 'bad_state';
$job->provider = 'ynab';
@@ -88,7 +88,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_6_' . random_int(1, 10000);
$job->key = 'ynab_r_6_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'bad_state';
$job->provider = 'ynab';
@@ -119,7 +119,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_1_' . random_int(1, 10000);
$job->key = 'ynab_r_1_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_access_token';
$job->provider = 'ynab';
@@ -158,7 +158,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_4_' . random_int(1, 10000);
$job->key = 'ynab_r_4_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_accounts';
$job->provider = 'ynab';
@@ -198,7 +198,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_5_' . random_int(1, 10000);
$job->key = 'ynab_r_5_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'go-for-import';
$job->provider = 'ynab';
@@ -239,7 +239,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_2_' . random_int(1, 10000);
$job->key = 'ynab_r_2_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_budgets';
$job->provider = 'ynab';
@@ -281,7 +281,7 @@ class YnabRoutineTest extends TestCase
{
$job = new ImportJob;
$job->user_id = $this->user()->id;
$job->key = 'ynab_r_3_' . random_int(1, 10000);
$job->key = 'ynab_r_3_' . $this->randomInt();
$job->status = 'ready_to_run';
$job->stage = 'get_budgets';
$job->provider = 'ynab';