mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
Fix unit tests.
This commit is contained in:
@@ -65,7 +65,9 @@ class CreateExport extends Command
|
|||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return int
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
*/
|
*/
|
||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
|
@@ -51,8 +51,12 @@ class DecryptAttachment extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
|
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||||
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function handle(): void
|
public function handle(): int
|
||||||
{
|
{
|
||||||
/** @var AttachmentRepositoryInterface $repository */
|
/** @var AttachmentRepositoryInterface $repository */
|
||||||
$repository = app(AttachmentRepositoryInterface::class);
|
$repository = app(AttachmentRepositoryInterface::class);
|
||||||
@@ -64,28 +68,28 @@ class DecryptAttachment extends Command
|
|||||||
$this->error(sprintf('No attachment with id #%d', $attachmentId));
|
$this->error(sprintf('No attachment with id #%d', $attachmentId));
|
||||||
Log::error(sprintf('DecryptAttachment: No attachment with id #%d', $attachmentId));
|
Log::error(sprintf('DecryptAttachment: No attachment with id #%d', $attachmentId));
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($attachmentName !== $attachment->filename) {
|
if ($attachmentName !== $attachment->filename) {
|
||||||
$this->error('File name does not match.');
|
$this->error('File name does not match.');
|
||||||
Log::error('DecryptAttachment: File name does not match.');
|
Log::error('DecryptAttachment: File name does not match.');
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_dir($storagePath)) {
|
if (!is_dir($storagePath)) {
|
||||||
$this->error(sprintf('Path "%s" is not a directory.', $storagePath));
|
$this->error(sprintf('Path "%s" is not a directory.', $storagePath));
|
||||||
Log::error(sprintf('DecryptAttachment: Path "%s" is not a directory.', $storagePath));
|
Log::error(sprintf('DecryptAttachment: Path "%s" is not a directory.', $storagePath));
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_writable($storagePath)) {
|
if (!is_writable($storagePath)) {
|
||||||
$this->error(sprintf('Path "%s" is not writable.', $storagePath));
|
$this->error(sprintf('Path "%s" is not writable.', $storagePath));
|
||||||
Log::error(sprintf('DecryptAttachment: Path "%s" is not writable.', $storagePath));
|
Log::error(sprintf('DecryptAttachment: Path "%s" is not writable.', $storagePath));
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fullPath = $storagePath . DIRECTORY_SEPARATOR . $attachment->filename;
|
$fullPath = $storagePath . DIRECTORY_SEPARATOR . $attachment->filename;
|
||||||
@@ -95,9 +99,10 @@ class DecryptAttachment extends Command
|
|||||||
if (false === $result) {
|
if (false === $result) {
|
||||||
$this->error('Could not write to file.');
|
$this->error('Could not write to file.');
|
||||||
|
|
||||||
return;
|
return 1;
|
||||||
}
|
}
|
||||||
$this->info(sprintf('%d bytes written. Exiting now..', $result));
|
$this->info(sprintf('%d bytes written. Exiting now..', $result));
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -36,11 +36,18 @@ class ToAccountContainsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$count = 0;
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
do {
|
||||||
$account = $transaction->account;
|
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$trigger = ToAccountContains::makeFromStrings($account->name, false);
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$result = $trigger->triggered($journal);
|
$transactionCount = $journal->transactions()->count();
|
||||||
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
|
$count++;
|
||||||
|
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||||
|
|
||||||
|
|
||||||
|
$trigger = ToAccountContains::makeFromStrings($account->name, false);
|
||||||
|
$result = $trigger->triggered($journal);
|
||||||
$this->assertTrue($result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +56,16 @@ class ToAccountContainsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNot(): void
|
public function testTriggeredNot(): void
|
||||||
{
|
{
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$count = 0;
|
||||||
|
do {
|
||||||
|
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
|
$transactionCount = $journal->transactions()->count();
|
||||||
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
|
$count++;
|
||||||
|
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||||
|
|
||||||
|
|
||||||
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
$trigger = ToAccountContains::makeFromStrings('some name' . random_int(1, 234), false);
|
||||||
$result = $trigger->triggered($journal);
|
$result = $trigger->triggered($journal);
|
||||||
$this->assertFalse($result);
|
$this->assertFalse($result);
|
||||||
|
@@ -36,12 +36,12 @@ class ToAccountIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggered(): void
|
public function testTriggered(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
do {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$transactionCount = $journal->transactions()->count();
|
$transactionCount = $journal->transactions()->count();
|
||||||
$account = $transaction->account;
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
$count++;
|
$count++;
|
||||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||||
|
|
||||||
@@ -55,12 +55,12 @@ class ToAccountIsTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testTriggeredNot(): void
|
public function testTriggeredNot(): void
|
||||||
{
|
{
|
||||||
$count = 0;
|
$count = 0;
|
||||||
do {
|
do {
|
||||||
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = TransactionJournal::inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$transactionCount = $journal->transactions()->count();
|
$transactionCount = $journal->transactions()->count();
|
||||||
$account = $transaction->account;
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
$count++;
|
$count++;
|
||||||
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
} while ($account === null && $count < 30 && $transactionCount !== 2);
|
||||||
|
|
||||||
|
@@ -46,7 +46,7 @@ class ToAccountStartsTest extends TestCase
|
|||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = $transaction->account;
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
Log::debug(sprintf('Journal with id #%d', $journal->id));
|
Log::debug(sprintf('Journal with id #%d', $journal->id));
|
||||||
Log::debug(sprintf('Count of transactions is %d', $count));
|
Log::debug(sprintf('Count of transactions is %d', $count));
|
||||||
Log::debug(sprintf('Account is null: %s', var_export(null === $account, true)));
|
Log::debug(sprintf('Account is null: %s', var_export(null === $account, true)));
|
||||||
@@ -71,7 +71,7 @@ class ToAccountStartsTest extends TestCase
|
|||||||
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
$journal = $this->user()->transactionJournals()->inRandomOrder()->whereNull('deleted_at')->first();
|
||||||
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
$count = $journal->transactions()->where('amount', '>', 0)->count();
|
||||||
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
$transaction = $journal->transactions()->where('amount', '>', 0)->first();
|
||||||
$account = $transaction->account;
|
$account = null === $transaction ? null : $transaction->account;
|
||||||
Log::debug(sprintf('Journal with id #%d', $journal->id));
|
Log::debug(sprintf('Journal with id #%d', $journal->id));
|
||||||
Log::debug(sprintf('Count of transactions is %d', $count));
|
Log::debug(sprintf('Count of transactions is %d', $count));
|
||||||
Log::debug(sprintf('Account is null: %s', var_export(null === $account, true)));
|
Log::debug(sprintf('Account is null: %s', var_export(null === $account, true)));
|
||||||
|
Reference in New Issue
Block a user