mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-21 19:47:48 +00:00
Implement test of import command.
This commit is contained in:
@@ -22,16 +22,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Console\Commands;
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
use Artisan;
|
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Import\Logging\CommandHandler;
|
|
||||||
use FireflyIII\Import\Routine\RoutineInterface;
|
use FireflyIII\Import\Routine\RoutineInterface;
|
||||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Services\Internal\File\EncryptService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Log;
|
use Log;
|
||||||
use Monolog\Formatter\LineFormatter;
|
|
||||||
use Preferences;
|
use Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,46 +59,39 @@ class CreateImport extends Command
|
|||||||
{--token= : The user\'s access token.}
|
{--token= : The user\'s access token.}
|
||||||
{--start : Starts the job immediately.}';
|
{--start : Starts the job immediately.}';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the command.
|
* Run the command.
|
||||||
*
|
*
|
||||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
|
* @noinspection MultipleReturnStatementsInspection
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five exactly.
|
|
||||||
*
|
*
|
||||||
* @throws FireflyException
|
* @throws FireflyException
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle(): int
|
||||||
{
|
{
|
||||||
if (!$this->verifyAccessToken()) {
|
if (!$this->verifyAccessToken()) {
|
||||||
$this->errorLine('Invalid access token.');
|
$this->errorLine('Invalid access token.');
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
/** @var UserRepositoryInterface $userRepository */
|
/** @var UserRepositoryInterface $userRepository */
|
||||||
$userRepository = app(UserRepositoryInterface::class);
|
$userRepository = app(UserRepositoryInterface::class);
|
||||||
$file = $this->argument('file');
|
$file = $this->argument('file');
|
||||||
$configuration = $this->argument('configuration');
|
$configuration = $this->argument('configuration');
|
||||||
$user = $userRepository->find(intval($this->option('user')));
|
$user = $userRepository->findNull((int)$this->option('user'));
|
||||||
$cwd = getcwd();
|
$cwd = getcwd();
|
||||||
$type = strtolower($this->option('type'));
|
$type = strtolower($this->option('type'));
|
||||||
|
|
||||||
if (!$this->validArguments()) {
|
if (!$this->validArguments()) {
|
||||||
return;
|
$this->errorLine('Invalid arguments.');
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$configurationData = json_decode(file_get_contents($configuration), true);
|
$configurationData = json_decode(file_get_contents($configuration), true);
|
||||||
if (null === $configurationData) {
|
if (null === $configurationData) {
|
||||||
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
|
$this->errorLine(sprintf('Firefly III cannot read the contents of configuration file "%s" (working directory: "%s").', $configuration, $cwd));
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->infoLine(sprintf('Going to create a job to import file: %s', $file));
|
$this->infoLine(sprintf('Going to create a job to import file: %s', $file));
|
||||||
@@ -114,7 +105,10 @@ class CreateImport extends Command
|
|||||||
$job = $jobRepository->create($type);
|
$job = $jobRepository->create($type);
|
||||||
$this->infoLine(sprintf('Created job "%s"', $job->key));
|
$this->infoLine(sprintf('Created job "%s"', $job->key));
|
||||||
|
|
||||||
Artisan::call('firefly:encrypt-file', ['file' => $file, 'key' => $job->key]);
|
/** @var EncryptService $service */
|
||||||
|
$service = app(EncryptService::class);
|
||||||
|
$service->encrypt($file, $job->key);
|
||||||
|
|
||||||
$this->infoLine('Stored import data...');
|
$this->infoLine('Stored import data...');
|
||||||
|
|
||||||
$jobRepository->setConfiguration($job, $configurationData);
|
$jobRepository->setConfiguration($job, $configurationData);
|
||||||
@@ -154,50 +148,7 @@ class CreateImport extends Command
|
|||||||
// clear cache for user:
|
// clear cache for user:
|
||||||
Preferences::setForUser($user, 'lastActivity', microtime());
|
Preferences::setForUser($user, 'lastActivity', microtime());
|
||||||
|
|
||||||
return;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verify user inserts correct arguments.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) // it's five exactly.
|
|
||||||
*/
|
|
||||||
private function validArguments(): bool
|
|
||||||
{
|
|
||||||
/** @var UserRepositoryInterface $userRepository */
|
|
||||||
$userRepository = app(UserRepositoryInterface::class);
|
|
||||||
$file = $this->argument('file');
|
|
||||||
$configuration = $this->argument('configuration');
|
|
||||||
$user = $userRepository->find(intval($this->option('user')));
|
|
||||||
$cwd = getcwd();
|
|
||||||
$validTypes = config('import.options.file.import_formats');
|
|
||||||
$type = strtolower($this->option('type'));
|
|
||||||
if (null === $user) {
|
|
||||||
$this->errorLine(sprintf('There is no user with ID %d.', $this->option('user')));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($type, $validTypes)) {
|
|
||||||
$this->errorLine(sprintf('Cannot import file of type "%s"', $type));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($file)) {
|
|
||||||
$this->errorLine(sprintf('Firefly III cannot find file "%s" (working directory: "%s").', $file, $cwd));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file_exists($configuration)) {
|
|
||||||
$this->errorLine(sprintf('Firefly III cannot find configuration file "%s" (working directory: "%s").', $configuration, $cwd));
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -220,4 +171,39 @@ class CreateImport extends Command
|
|||||||
Log::info($message, $data ?? []);
|
Log::info($message, $data ?? []);
|
||||||
$this->line($message);
|
$this->line($message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify user inserts correct arguments.
|
||||||
|
*
|
||||||
|
* @noinspection MultipleReturnStatementsInspection
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function validArguments(): bool
|
||||||
|
{
|
||||||
|
$file = $this->argument('file');
|
||||||
|
$configuration = $this->argument('configuration');
|
||||||
|
$cwd = getcwd();
|
||||||
|
$validTypes = config('import.options.file.import_formats');
|
||||||
|
$type = strtolower($this->option('type'));
|
||||||
|
|
||||||
|
if (!\in_array($type, $validTypes, true)) {
|
||||||
|
$this->errorLine(sprintf('Cannot import file of type "%s"', $type));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
$this->errorLine(sprintf('Firefly III cannot find file "%s" (working directory: "%s").', $file, $cwd));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!file_exists($configuration)) {
|
||||||
|
$this->errorLine(sprintf('Firefly III cannot find configuration file "%s" (working directory: "%s").', $configuration, $cwd));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,7 +22,8 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace FireflyIII\Console\Commands;
|
namespace FireflyIII\Console\Commands;
|
||||||
|
|
||||||
use Crypt;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
use FireflyIII\Services\Internal\File\EncryptService;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -44,33 +45,26 @@ class EncryptFile extends Command
|
|||||||
*/
|
*/
|
||||||
protected $signature = 'firefly:encrypt-file {file} {key}';
|
protected $signature = 'firefly:encrypt-file {file} {key}';
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new command instance.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
parent::__construct();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$file = e(strval($this->argument('file')));
|
$code = 0;
|
||||||
if (!file_exists($file)) {
|
$file = (string)$this->argument('file');
|
||||||
$this->error(sprintf('File "%s" does not seem to exist.', $file));
|
$key = (string)$this->argument('key');
|
||||||
|
/** @var EncryptService $service */
|
||||||
|
$service = app(EncryptService::class);
|
||||||
|
|
||||||
return;
|
try {
|
||||||
|
$service->encrypt($file, $key);
|
||||||
|
} catch (FireflyException $e) {
|
||||||
|
$this->error($e->getMessage());
|
||||||
|
$code = 1;
|
||||||
}
|
}
|
||||||
$content = file_get_contents($file);
|
|
||||||
$content = Crypt::encrypt($content);
|
|
||||||
$newName = e(strval($this->argument('key'))) . '.upload';
|
|
||||||
|
|
||||||
$path = storage_path('upload') . '/' . $newName;
|
return $code;
|
||||||
file_put_contents($path, $content);
|
|
||||||
$this->line(sprintf('Encrypted "%s" and put it in "%s"', $file, $path));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
52
app/Services/Internal/File/EncryptService.php
Normal file
52
app/Services/Internal/File/EncryptService.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* EncryptService.php
|
||||||
|
* Copyright (c) 2018 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace FireflyIII\Services\Internal\File;
|
||||||
|
|
||||||
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class EncryptService
|
||||||
|
*/
|
||||||
|
class EncryptService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $file
|
||||||
|
* @param string $key
|
||||||
|
*
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
public function encrypt(string $file, string $key): void
|
||||||
|
{
|
||||||
|
if (!file_exists($file)) {
|
||||||
|
throw new FireflyException(sprintf('File "%s" does not seem to exist.', $file));
|
||||||
|
}
|
||||||
|
$content = file_get_contents($file);
|
||||||
|
$content = Crypt::encrypt($content);
|
||||||
|
$newName = sprintf('%s.upload', $key);
|
||||||
|
$path = storage_path('upload') . '/' . $newName;
|
||||||
|
|
||||||
|
file_put_contents($path, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -81,8 +81,8 @@ class CreateExportTest extends TestCase
|
|||||||
$processor->shouldReceive('createZipFile')->once();
|
$processor->shouldReceive('createZipFile')->once();
|
||||||
|
|
||||||
$fakeNews = 'I am a zipfile';
|
$fakeNews = 'I am a zipfile';
|
||||||
|
Storage::fake('export');
|
||||||
Storage::disk('export')->put(sprintf('%s.zip', $job->key), $fakeNews);
|
Storage::disk('export')->put(sprintf('%s.zip', $job->key), $fakeNews);
|
||||||
|
|
||||||
$output = $this->artisan(
|
$output = $this->artisan(
|
||||||
'firefly:create-export',
|
'firefly:create-export',
|
||||||
[
|
[
|
||||||
|
283
tests/Unit/Console/Commands/CreateImportTest.php
Normal file
283
tests/Unit/Console/Commands/CreateImportTest.php
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* CreateImportTest.php
|
||||||
|
* Copyright (c) 2018 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Unit\Console\Commands;
|
||||||
|
|
||||||
|
|
||||||
|
use FireflyIII\Import\Routine\FileRoutine;
|
||||||
|
use FireflyIII\Models\ImportJob;
|
||||||
|
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||||
|
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||||
|
use FireflyIII\Services\Internal\File\EncryptService;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use Storage;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class CreateImportTest
|
||||||
|
*/
|
||||||
|
class CreateImportTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testBasic()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(2);
|
||||||
|
$jobRepos->shouldReceive('setUser')->once();
|
||||||
|
$jobRepos->shouldReceive('create')->once()->andReturn($job);
|
||||||
|
$jobRepos->shouldReceive('setConfiguration')->once();
|
||||||
|
$jobRepos->shouldReceive('updateStatus')->once();
|
||||||
|
$encrypter->shouldReceive('encrypt')->once();
|
||||||
|
$routine->shouldReceive('setJob')->once();
|
||||||
|
$routine->shouldReceive('run')->once();
|
||||||
|
$routine->shouldReceive('getErrors')->once()->andReturn($collection);
|
||||||
|
$routine->shouldReceive('getJournals')->once()->andReturn(new Collection());
|
||||||
|
$routine->shouldReceive('getLines')->once()->andReturn(7);
|
||||||
|
|
||||||
|
Storage::fake('upload');
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'token',
|
||||||
|
'file' => 'storage/build/test-upload.csv',
|
||||||
|
'configuration' => 'storage/build/test-upload.json',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(0, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testInvalidToken()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(1);
|
||||||
|
|
||||||
|
Storage::fake('upload');
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'tokenX',
|
||||||
|
'file' => 'storage/build/test-upload.csv',
|
||||||
|
'configuration' => 'storage/build/test-upload.json',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testInvalidType()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(2);
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'token',
|
||||||
|
'--type' => 'csvX',
|
||||||
|
'file' => 'storage/build/test-upload.csv',
|
||||||
|
'configuration' => 'storage/build/test-upload.json',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testInvalidJSON()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(2);
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'token',
|
||||||
|
'--type' => 'csv',
|
||||||
|
'file' => 'storage/build/test-upload.csv',
|
||||||
|
'configuration' => 'storage/build/test-upload.csv',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testFileNotFound()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(2);
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'token',
|
||||||
|
'--type' => 'csv',
|
||||||
|
'file' => 'storage/build/test-uploadX.csv',
|
||||||
|
'configuration' => 'storage/build/test-upload.json',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers \FireflyIII\Console\Commands\CreateImport
|
||||||
|
* @covers \FireflyIII\Console\Commands\EncryptFile
|
||||||
|
* @covers \FireflyIII\Console\Commands\VerifiesAccessToken
|
||||||
|
*/
|
||||||
|
public function testConfigNotFound()
|
||||||
|
{
|
||||||
|
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||||
|
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||||
|
$encrypter = $this->mock(EncryptService::class);
|
||||||
|
$routine = $this->mock(FileRoutine::class);
|
||||||
|
|
||||||
|
$collection = new Collection();
|
||||||
|
$collection->push('I am error');
|
||||||
|
|
||||||
|
$job = new ImportJob;
|
||||||
|
$job->key = 'import-' . random_int(1, 1000);
|
||||||
|
$job->file_type = 'csv';
|
||||||
|
$job->user = $this->user();
|
||||||
|
|
||||||
|
$userRepos->shouldReceive('findNull')->andReturn($this->user())->times(2);
|
||||||
|
|
||||||
|
$output = $this->artisan(
|
||||||
|
'firefly:create-import',
|
||||||
|
[
|
||||||
|
'--user' => 1,
|
||||||
|
'--token' => 'token',
|
||||||
|
'--type' => 'csv',
|
||||||
|
'file' => 'storage/build/test-upload.csv',
|
||||||
|
'configuration' => 'storage/build/test-uploadX.json',
|
||||||
|
'--start' => true,
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $output);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user