mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 15:18:05 +00:00
Improve test coverage.
This commit is contained in:
@@ -30,6 +30,7 @@ use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Illuminate\Support\Str;
|
||||
use Log;
|
||||
@@ -42,12 +43,12 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
*/
|
||||
class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
/** @var int */
|
||||
private $maxUploadSize;
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
|
||||
protected $uploadDisk;
|
||||
/** @var int */
|
||||
private $maxUploadSize;
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -70,6 +71,24 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $this->setExtendedStatus($job, $extended);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $error
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function addErrorMessage(ImportJob $job, string $error): ImportJob
|
||||
{
|
||||
$errors = $job->errors;
|
||||
$errors[] = $error;
|
||||
$job->errors = $errors;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param int $steps
|
||||
@@ -176,6 +195,18 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all attachments for job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAttachments(ImportJob $job): Collection
|
||||
{
|
||||
return $job->attachments()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return configuration of job.
|
||||
*
|
||||
@@ -393,6 +424,20 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $this->setExtendedStatus($job, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTag(ImportJob $job, Tag $tag): ImportJob
|
||||
{
|
||||
$job->tag()->associate($tag);
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param int $count
|
||||
@@ -408,43 +453,6 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $this->setExtendedStatus($job, $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $status
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function updateStatus(ImportJob $job, string $status): ImportJob
|
||||
{
|
||||
$job->status = $status;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return import file content.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function uploadFileContents(ImportJob $job): string
|
||||
{
|
||||
return $job->uploadFileContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param array $transactions
|
||||
@@ -460,52 +468,13 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Add message to job.
|
||||
*
|
||||
* @param ImportJob $job
|
||||
* @param string $error
|
||||
*
|
||||
* @return ImportJob
|
||||
* @param User $user
|
||||
*/
|
||||
public function addErrorMessage(ImportJob $job, string $error): ImportJob
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$errors = $job->errors;
|
||||
$errors[] = $error;
|
||||
$job->errors = $errors;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param Tag $tag
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function setTag(ImportJob $job, Tag $tag): ImportJob
|
||||
{
|
||||
$job->tag()->associate($tag);
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validSize(UploadedFile $file): bool
|
||||
{
|
||||
$size = $file->getSize();
|
||||
|
||||
return $size > $this->maxUploadSize;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle upload for job.
|
||||
*
|
||||
@@ -526,7 +495,7 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
return $messages;
|
||||
}
|
||||
$count = $job->attachments()->get()->filter(
|
||||
function (Attachment $att) use($name) {
|
||||
function (Attachment $att) use ($name) {
|
||||
return $att->filename === $name;
|
||||
}
|
||||
)->count();
|
||||
@@ -560,4 +529,47 @@ class ImportJobRepository implements ImportJobRepositoryInterface
|
||||
// return it.
|
||||
return new MessageBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ImportJob $job
|
||||
* @param string $status
|
||||
*
|
||||
* @return ImportJob
|
||||
*/
|
||||
public function updateStatus(ImportJob $job, string $status): ImportJob
|
||||
{
|
||||
$job->status = $status;
|
||||
$job->save();
|
||||
|
||||
return $job;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return import file content.
|
||||
*
|
||||
* @deprecated
|
||||
*
|
||||
* @param ImportJob $job
|
||||
*
|
||||
* @return string
|
||||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
|
||||
*/
|
||||
public function uploadFileContents(ImportJob $job): string
|
||||
{
|
||||
return $job->uploadFileContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function validSize(UploadedFile $file): bool
|
||||
{
|
||||
$size = $file->getSize();
|
||||
|
||||
return $size > $this->maxUploadSize;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user