2018-05-10 20:05:02 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* FileRoutineTest.php
|
2019-10-02 06:45:03 +02:00
|
|
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
2018-05-10 20:05:02 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-05-10 20:05:02 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-05-10 20:05:02 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-05-10 20:05:02 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:45:03 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-05-10 20:05:02 +02:00
|
|
|
*
|
2019-10-02 06:45:03 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-05-10 20:05:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Unit\Import\Routine;
|
|
|
|
|
|
|
|
|
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
2019-07-31 16:53:09 +02:00
|
|
|
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
|
2018-05-10 20:05:02 +02:00
|
|
|
use FireflyIII\Import\Routine\FileRoutine;
|
|
|
|
use FireflyIII\Models\ImportJob;
|
|
|
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
2019-07-26 17:48:24 +02:00
|
|
|
use FireflyIII\Support\Import\Routine\Bunq\StageImportDataHandler;
|
2018-05-10 20:05:02 +02:00
|
|
|
use FireflyIII\Support\Import\Routine\File\CSVProcessor;
|
2019-07-31 16:53:09 +02:00
|
|
|
use Illuminate\Support\Collection;
|
2019-04-09 15:32:48 +02:00
|
|
|
use Log;
|
2018-05-10 20:05:02 +02:00
|
|
|
use Mockery;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class FileRoutineTest
|
2019-08-17 10:48:28 +02:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2018-05-10 20:05:02 +02:00
|
|
|
*/
|
|
|
|
class FileRoutineTest extends TestCase
|
|
|
|
{
|
2018-09-04 09:52:19 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 20:05:20 +02:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-09-04 09:52:19 +02:00
|
|
|
}
|
|
|
|
|
2018-05-10 20:05:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Import\Routine\FileRoutine
|
|
|
|
*/
|
|
|
|
public function testRunDefault(): void
|
|
|
|
{
|
|
|
|
$job = new ImportJob;
|
|
|
|
$job->user_id = $this->user()->id;
|
2019-07-26 17:48:24 +02:00
|
|
|
$job->key = 'brY_' . $this->randomInt();
|
2018-05-13 09:01:10 +02:00
|
|
|
$job->status = 'ready_to_run';
|
2019-07-26 17:48:24 +02:00
|
|
|
$job->stage = 'go-for-import';
|
2019-07-31 16:53:09 +02:00
|
|
|
$job->provider = 'file';
|
2018-05-10 20:05:02 +02:00
|
|
|
$job->file_type = '';
|
|
|
|
$job->configuration = [];
|
|
|
|
$job->save();
|
|
|
|
|
2019-07-26 17:48:24 +02:00
|
|
|
// mock stuff:
|
2018-05-10 20:05:02 +02:00
|
|
|
$repository = $this->mock(ImportJobRepositoryInterface::class);
|
2019-07-26 17:48:24 +02:00
|
|
|
$handler = $this->mock(StageImportDataHandler::class);
|
2019-07-31 16:53:09 +02:00
|
|
|
$this->mock(AttachmentHelperInterface::class);
|
|
|
|
$csv = $this->mock(CSVProcessor::class);
|
2018-05-10 20:05:02 +02:00
|
|
|
|
2019-07-31 16:53:09 +02:00
|
|
|
$csv->shouldReceive('setImportJob')->atLeast()->once();
|
|
|
|
$csv->shouldReceive('run')->atLeast()->once();
|
2018-05-10 20:05:02 +02:00
|
|
|
|
2019-07-31 16:53:09 +02:00
|
|
|
|
|
|
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
2019-07-26 17:48:24 +02:00
|
|
|
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'running']);
|
|
|
|
$repository->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished']);
|
|
|
|
$repository->shouldReceive('setStage')->withArgs([Mockery::any(), 'final']);
|
2019-07-31 16:53:09 +02:00
|
|
|
$repository->shouldReceive('getConfiguration')->atLeast()->once()->andReturn([]);
|
|
|
|
//$repository->shouldReceive('getAttachments')->atLeast()->once()->andReturn(new Collection);
|
|
|
|
$repository->shouldReceive('setTransactions')->atLeast()->once();
|
|
|
|
//$repository->shouldReceive('appendTransactions')->withArgs([Mockery::any(), ['a' => 'c']])->once();
|
2018-05-10 20:05:02 +02:00
|
|
|
|
2019-07-31 16:53:09 +02:00
|
|
|
//$handler->shouldReceive('setImportJob')->once();
|
|
|
|
//$handler->shouldReceive('run')->once();
|
|
|
|
//$handler->shouldReceive('getTransactions')->once()->andReturn(['a' => 'c']);
|
2019-07-26 17:48:24 +02:00
|
|
|
$handler->shouldReceive('isStillRunning')->andReturn(false);
|
2019-07-31 16:53:09 +02:00
|
|
|
$routine = new FileRoutine;
|
2018-05-12 15:50:01 +02:00
|
|
|
$routine->setImportJob($job);
|
2018-05-10 20:05:02 +02:00
|
|
|
try {
|
|
|
|
$routine->run();
|
|
|
|
} catch (FireflyException $e) {
|
2019-07-26 17:48:24 +02:00
|
|
|
$this->assertFalse(true, $e->getMessage());
|
2018-05-10 20:05:02 +02:00
|
|
|
}
|
|
|
|
}
|
2018-05-11 09:51:47 +02:00
|
|
|
}
|