Skip to content

Firefly III: a personal finances manager

Improve test coverage.

James Cole2b54363dd750
diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.php
index 26e3a5c5e0..6be9b42330 100644
--- a/app/Factory/AccountFactory.php
+++ b/app/Factory/AccountFactory.php
@@ -132,6 +132,7 @@ class AccountFactory
}
/**
+ *
* @param string $accountName
* @param string $accountType
*
diff --git a/app/Factory/AccountMetaFactory.php b/app/Factory/AccountMetaFactory.php
index 67ec707046..5861e81b4d 100644
--- a/app/Factory/AccountMetaFactory.php
+++ b/app/Factory/AccountMetaFactory.php
@@ -65,7 +65,7 @@ class AccountMetaFactory
// if $data has field and $entry is null, create new one:
if (null === $entry) {
Log::debug(sprintf('Created meta-field "%s":"%s" for account #%d ("%s") ', $field, $value, $account->id, $account->name));
- $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]);
+ return $this->create(['account_id' => $account->id, 'name' => $field, 'data' => $value]);
}
// if $data has field and $entry is not null, update $entry:
@@ -75,12 +75,13 @@ class AccountMetaFactory
Log::debug(sprintf('Updated meta-field "%s":"%s" for #%d ("%s") ', $field, $value, $account->id, $account->name));
}
}
- if ('' === $value && null !== $entry && isset($data[$field])) {
+ if ('' === $value && null !== $entry) {
try {
$entry->delete();
- } catch (Exception $e) {
- Log::debug(sprintf('Could not delete entry: %s', $e->getMessage()));
+ } catch (Exception $e) { // @codeCoverageIgnore
+ Log::debug(sprintf('Could not delete entry: %s', $e->getMessage())); // @codeCoverageIgnore
}
+ return null;
}
return $entry;
diff --git a/app/Factory/TransactionFactory.php b/app/Factory/TransactionFactory.php
index 39d483b46a..57fb616b4b 100644
--- a/app/Factory/TransactionFactory.php
+++ b/app/Factory/TransactionFactory.php
@@ -59,10 +59,10 @@ class TransactionFactory
$currencyId = isset($data['currency']) ? $data['currency']->id : $currencyId;
if ('' === $data['amount']) {
Log::error('Empty string in data.', $data);
- throw new FireflyException('Amount is an empty string, which Firefly III cannot handle. Apologies.'); // @codeCoverageIgnore
+ throw new FireflyException('Amount is an empty string, which Firefly III cannot handle. Apologies.');
}
if (null === $currencyId) {
- throw new FireflyException('Cannot store transaction without currency information.'); // @codeCoverageIgnore
+ throw new FireflyException('Cannot store transaction without currency information.');
}
$data['foreign_amount'] = '' === (string)$data['foreign_amount'] ? null : $data['foreign_amount'];
Log::debug(sprintf('Create transaction for account #%d ("%s") with amount %s', $data['account']->id, $data['account']->name, $data['amount']));
@@ -154,7 +154,7 @@ class TransactionFactory
]
);
if (null === $source || null === $dest) {
- throw new FireflyException('Could not create transactions.');
+ throw new FireflyException('Could not create transactions.'); // @codeCoverageIgnore
}
// set foreign currency
diff --git a/app/Factory/TransactionTypeFactory.php b/app/Factory/TransactionTypeFactory.php
index 05f0fdf67d..d684555390 100644
--- a/app/Factory/TransactionTypeFactory.php
+++ b/app/Factory/TransactionTypeFactory.php
@@ -28,7 +28,6 @@ namespace FireflyIII\Factory;
use FireflyIII\Models\TransactionType;
/**
- * @codeCoverageIgnore
* Class TransactionTypeFactory
*/
class TransactionTypeFactory
diff --git a/app/Generator/Chart/Basic/ChartJsGenerator.php b/app/Generator/Chart/Basic/ChartJsGenerator.php
index c21522586e..875774e4de 100644
--- a/app/Generator/Chart/Basic/ChartJsGenerator.php
+++ b/app/Generator/Chart/Basic/ChartJsGenerator.php
@@ -120,7 +120,7 @@ class ChartJsGenerator implements GeneratorInterface
// different sort when values are positive and when they're negative.
asort($data);
$next = next($data);
- if (!\is_bool($next) && 1 === bccomp($next, '0')) {
+ if (!\is_bool($next) && 1 === bccomp((string)$next, '0')) {
// next is positive, sort other way around.
arsort($data);
}
@@ -129,7 +129,7 @@ class ChartJsGenerator implements GeneratorInterface
$index = 0;
foreach ($data as $key => $value) {
// make larger than 0
- $chartData['datasets'][0]['data'][] = (float)app('steam')->positive($value);
+ $chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$value);
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['labels'][] = $key;
++$index;
diff --git a/app/Generator/Report/Account/MonthReportGenerator.php b/app/Generator/Report/Account/MonthReportGenerator.php
index ab135909f7..f9a53e5979 100644
--- a/app/Generator/Report/Account/MonthReportGenerator.php
+++ b/app/Generator/Report/Account/MonthReportGenerator.php
@@ -30,6 +30,8 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ *
+ * @codeCoverageIgnore
*/
class MonthReportGenerator implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Account/MultiYearReportGenerator.php b/app/Generator/Report/Account/MultiYearReportGenerator.php
index a4d17d0d83..ada1211667 100644
--- a/app/Generator/Report/Account/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Account/MultiYearReportGenerator.php
@@ -24,6 +24,8 @@ namespace FireflyIII\Generator\Report\Account;
/**
* Class MultiYearReportGenerator.
+ *
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Account/YearReportGenerator.php b/app/Generator/Report/Account/YearReportGenerator.php
index c1e890ba19..bdee367fed 100644
--- a/app/Generator/Report/Account/YearReportGenerator.php
+++ b/app/Generator/Report/Account/YearReportGenerator.php
@@ -24,6 +24,8 @@ namespace FireflyIII\Generator\Report\Account;
/**
* Class YearReportGenerator.
+ *
+ * @codeCoverageIgnore
*/
class YearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Audit/MonthReportGenerator.php b/app/Generator/Report/Audit/MonthReportGenerator.php
index 5a68b7e41f..26e1ac3f43 100644
--- a/app/Generator/Report/Audit/MonthReportGenerator.php
+++ b/app/Generator/Report/Audit/MonthReportGenerator.php
@@ -97,6 +97,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Collection $accounts
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setAccounts(Collection $accounts): ReportGeneratorInterface
{
@@ -111,6 +112,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Collection $budgets
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setBudgets(Collection $budgets): ReportGeneratorInterface
{
@@ -123,6 +125,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Collection $categories
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setCategories(Collection $categories): ReportGeneratorInterface
{
@@ -135,6 +138,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Carbon $date
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setEndDate(Carbon $date): ReportGeneratorInterface
{
@@ -149,6 +153,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Collection $expense
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setExpense(Collection $expense): ReportGeneratorInterface
{
@@ -161,6 +166,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Carbon $date
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setStartDate(Carbon $date): ReportGeneratorInterface
{
@@ -175,6 +181,7 @@ class MonthReportGenerator implements ReportGeneratorInterface
* @param Collection $tags
*
* @return ReportGeneratorInterface
+ * @codeCoverageIgnore
*/
public function setTags(Collection $tags): ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Audit/MultiYearReportGenerator.php b/app/Generator/Report/Audit/MultiYearReportGenerator.php
index 0bd3b5697f..ade7d0b84b 100644
--- a/app/Generator/Report/Audit/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Audit/MultiYearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Audit;
/**
* Class MultiYearReportGenerator.
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Audit/YearReportGenerator.php b/app/Generator/Report/Audit/YearReportGenerator.php
index e341718728..4ff82713f4 100644
--- a/app/Generator/Report/Audit/YearReportGenerator.php
+++ b/app/Generator/Report/Audit/YearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Audit;
/**
* Class YearReportGenerator.
+ * @codeCoverageIgnore
*/
class YearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Budget/MonthReportGenerator.php b/app/Generator/Report/Budget/MonthReportGenerator.php
index dcda49ed7a..6b7539c0d4 100644
--- a/app/Generator/Report/Budget/MonthReportGenerator.php
+++ b/app/Generator/Report/Budget/MonthReportGenerator.php
@@ -39,6 +39,8 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ *
+ * @codeCoverageIgnore
*/
class MonthReportGenerator extends Support implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Budget/MultiYearReportGenerator.php b/app/Generator/Report/Budget/MultiYearReportGenerator.php
index 1e32b8d8ce..ecfad642be 100644
--- a/app/Generator/Report/Budget/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Budget/MultiYearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Budget;
/**
* Class MultiYearReportGenerator.
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Budget/YearReportGenerator.php b/app/Generator/Report/Budget/YearReportGenerator.php
index a025513451..4323ce2ddd 100644
--- a/app/Generator/Report/Budget/YearReportGenerator.php
+++ b/app/Generator/Report/Budget/YearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Budget;
/**
* Class YearReportGenerator.
+ * @codeCoverageIgnore
*/
class YearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Category/MonthReportGenerator.php b/app/Generator/Report/Category/MonthReportGenerator.php
index 02fa859ca8..ad477f15f1 100644
--- a/app/Generator/Report/Category/MonthReportGenerator.php
+++ b/app/Generator/Report/Category/MonthReportGenerator.php
@@ -40,6 +40,7 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ * @codeCoverageIgnore
*/
class MonthReportGenerator extends Support implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Category/MultiYearReportGenerator.php b/app/Generator/Report/Category/MultiYearReportGenerator.php
index 2fe96eb9cd..39a881178e 100644
--- a/app/Generator/Report/Category/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Category/MultiYearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Category;
/**
* Class MultiYearReportGenerator.
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Category/YearReportGenerator.php b/app/Generator/Report/Category/YearReportGenerator.php
index 920ea366e7..57f07fd975 100644
--- a/app/Generator/Report/Category/YearReportGenerator.php
+++ b/app/Generator/Report/Category/YearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Category;
/**
* Class YearReportGenerator.
+ * @codeCoverageIgnore
*/
class YearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/ReportGeneratorFactory.php b/app/Generator/Report/ReportGeneratorFactory.php
index 6e06480a33..04e264bb3d 100644
--- a/app/Generator/Report/ReportGeneratorFactory.php
+++ b/app/Generator/Report/ReportGeneratorFactory.php
@@ -27,6 +27,7 @@ use FireflyIII\Exceptions\FireflyException;
/**
* Class ReportGeneratorFactory.
+ * @codeCoverageIgnore
*/
class ReportGeneratorFactory
{
diff --git a/app/Generator/Report/Standard/MonthReportGenerator.php b/app/Generator/Report/Standard/MonthReportGenerator.php
index ad0a9c0b99..ba6fc749a3 100644
--- a/app/Generator/Report/Standard/MonthReportGenerator.php
+++ b/app/Generator/Report/Standard/MonthReportGenerator.php
@@ -31,6 +31,7 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ * @codeCoverageIgnore
*/
class MonthReportGenerator implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Standard/MultiYearReportGenerator.php b/app/Generator/Report/Standard/MultiYearReportGenerator.php
index 9310554b33..e9ba9d40f5 100644
--- a/app/Generator/Report/Standard/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Standard/MultiYearReportGenerator.php
@@ -30,6 +30,7 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Standard/YearReportGenerator.php b/app/Generator/Report/Standard/YearReportGenerator.php
index bec85e462a..7479aa7024 100644
--- a/app/Generator/Report/Standard/YearReportGenerator.php
+++ b/app/Generator/Report/Standard/YearReportGenerator.php
@@ -30,6 +30,7 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ * @codeCoverageIgnore
*/
class YearReportGenerator implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Support.php b/app/Generator/Report/Support.php
index 0d5e42f4f2..d2b6c76f32 100644
--- a/app/Generator/Report/Support.php
+++ b/app/Generator/Report/Support.php
@@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
* Class Support.
* @method Collection getExpenses()
* @method Collection getIncome()
+ * @codeCoverageIgnore
*/
class Support
{
diff --git a/app/Generator/Report/Tag/MonthReportGenerator.php b/app/Generator/Report/Tag/MonthReportGenerator.php
index 0c83883786..975a1080aa 100644
--- a/app/Generator/Report/Tag/MonthReportGenerator.php
+++ b/app/Generator/Report/Tag/MonthReportGenerator.php
@@ -42,6 +42,7 @@ use Throwable;
/**
* Class MonthReportGenerator.
+ * @codeCoverageIgnore
*/
class MonthReportGenerator extends Support implements ReportGeneratorInterface
{
diff --git a/app/Generator/Report/Tag/MultiYearReportGenerator.php b/app/Generator/Report/Tag/MultiYearReportGenerator.php
index 0d6380416b..c34136289a 100644
--- a/app/Generator/Report/Tag/MultiYearReportGenerator.php
+++ b/app/Generator/Report/Tag/MultiYearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Tag;
/**
* Class MultiYearReportGenerator.
+ * @codeCoverageIgnore
*/
class MultiYearReportGenerator extends MonthReportGenerator
{
diff --git a/app/Generator/Report/Tag/YearReportGenerator.php b/app/Generator/Report/Tag/YearReportGenerator.php
index 0cb3f216a0..087485a166 100644
--- a/app/Generator/Report/Tag/YearReportGenerator.php
+++ b/app/Generator/Report/Tag/YearReportGenerator.php
@@ -24,6 +24,7 @@ namespace FireflyIII\Generator\Report\Tag;
/**
* Class YearReportGenerator.
+ * @codeCoverageIgnore
*/
class YearReportGenerator extends MonthReportGenerator
{
diff --git a/tests/Unit/Factory/AccountFactoryTest.php b/tests/Unit/Factory/AccountFactoryTest.php
index 8e8bd86452..7354f3c6ea 100644
--- a/tests/Unit/Factory/AccountFactoryTest.php
+++ b/tests/Unit/Factory/AccountFactoryTest.php
@@ -25,9 +25,12 @@ namespace Tests\Unit\Factory;
use Carbon\Carbon;
+use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\AccountFactory;
+use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AccountType;
+use Log;
use Tests\TestCase;
/**
@@ -35,6 +38,15 @@ use Tests\TestCase;
*/
class AccountFactoryTest extends TestCase
{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* Test minimal set of data to make factory work (asset account).
*
@@ -522,4 +534,53 @@ class AccountFactoryTest extends TestCase
$this->assertEquals($account->id, $existing->id);
}
+ /**
+ * Can't find account type.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testCreateNoType(): void
+ {
+
+ $data = [
+ 'account_type_id' => null,
+ 'accountType' => 'bla-bla',
+ 'iban' => null,
+ 'name' => 'Basic asset account #' . random_int(1, 10000),
+ 'virtualBalance' => null,
+ 'active' => true,
+ 'accountRole' => 'defaultAsset',
+ ];
+
+ /** @var AccountFactory $factory */
+ $factory = app(AccountFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->create($data);
+ } catch (FireflyException $e) {
+ $this->assertContains('AccountFactory::create() was unable to find account type #0 ("bla-bla").', $e->getMessage());
+ }
+ }
+
+ /**
+ * Test only for existing account because the rest has been covered by other tests.
+ *
+ * @covers \FireflyIII\Factory\AccountFactory
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ * @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
+ */
+ public function testFindOrCreate(): void
+ {
+ /** @var Account $account */
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ /** @var AccountFactory $factory */
+ $factory = app(AccountFactory::class);
+ $factory->setUser($this->user());
+
+ $result = $factory->findOrCreate($account->name, $account->accountType->type);
+ $this->assertEquals($result->id, $account->id);
+ }
+
}
diff --git a/tests/Unit/Factory/AccountMetaFactoryTest.php b/tests/Unit/Factory/AccountMetaFactoryTest.php
new file mode 100644
index 0000000000..0ddc5d788f
--- /dev/null
+++ b/tests/Unit/Factory/AccountMetaFactoryTest.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * AccountMetaFactoryTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Factory;
+
+
+use FireflyIII\Factory\AccountMetaFactory;
+use Log;
+use Tests\TestCase;
+
+/**
+ *
+ * Class AccountMetaFactoryTest
+ */
+class AccountMetaFactoryTest extends TestCase
+{
+
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ */
+ public function testCreate(): void
+ {
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $data = [
+ 'account_id' => $account->id,
+ 'name' => 'Some name',
+ 'data' => 'Some value',
+ ];
+
+ $factory = new AccountMetaFactory;
+ $result = $factory->create($data);
+ $this->assertEquals($data['name'], $result->name);
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ */
+ public function testCrudDelete(): void
+ {
+ $factory = new AccountMetaFactory;
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $data = [
+ 'account_id' => $account->id,
+ 'name' => 'Some name ' . random_int(1, 100000),
+ 'data' => 'Some value',
+ ];
+
+ $factory->create($data);
+
+ // update existing one
+ $result = $factory->crud($account, $data['name'], '');
+ $this->assertNull($result);
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ */
+ public function testCrudExisting(): void
+ {
+ $factory = new AccountMetaFactory;
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $data = [
+ 'account_id' => $account->id,
+ 'name' => 'Some name ' . random_int(1, 100000),
+ 'data' => 'Some value',
+ ];
+
+ $existing = $factory->create($data);
+
+ // update existing one
+ $result = $factory->crud($account, $data['name'], 'Some NEW value');
+ $this->assertNotNull($result);
+ $this->assertEquals($result->account_id, $account->id);
+ $this->assertEquals($existing->name, $result->name);
+ $this->assertEquals('Some NEW value', $result->data);
+
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\AccountMetaFactory
+ */
+ public function testCrudNew(): void
+ {
+ $account = $this->user()->accounts()->inRandomOrder()->first();
+ $factory = new AccountMetaFactory;
+ $result = $factory->crud($account, 'random name ' . random_int(1, 100000), 'Some value');
+ $this->assertNotNull($result);
+ $this->assertEquals($result->account_id, $account->id);
+
+ }
+}
\ No newline at end of file
diff --git a/tests/Unit/Factory/AttachmentFactoryTest.php b/tests/Unit/Factory/AttachmentFactoryTest.php
new file mode 100644
index 0000000000..cb5c3abf48
--- /dev/null
+++ b/tests/Unit/Factory/AttachmentFactoryTest.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * AttachmentFactoryTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Factory;
+
+
+use FireflyIII\Factory\AttachmentFactory;
+use FireflyIII\Models\TransactionJournal;
+use Log;
+use Tests\TestCase;
+
+/**
+ *
+ * Class AttachmentFactoryTest
+ */
+class AttachmentFactoryTest extends TestCase
+{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\AttachmentFactory
+ */
+ public function testCreate(): void
+ {
+
+ $journal = $this->user()->transactionJournals()->inRandomOrder()->first();
+ $data = [
+ 'model_id' => $journal->id,
+ 'model' => TransactionJournal::class,
+ 'filename' => 'testfile.pdf',
+ 'title' => 'File name',
+ 'notes' => 'Some notes',
+ ];
+
+ $factory = new AttachmentFactory;
+ $factory->setUser($this->user());
+ $result = $factory->create($data);
+ $this->assertEquals($data['title'], $result->title);
+ $this->assertEquals(1, $result->notes()->count());
+
+
+ }
+}
\ No newline at end of file
diff --git a/tests/Unit/Factory/BillFactoryTest.php b/tests/Unit/Factory/BillFactoryTest.php
index 048cff0a37..cb6289eba0 100644
--- a/tests/Unit/Factory/BillFactoryTest.php
+++ b/tests/Unit/Factory/BillFactoryTest.php
@@ -25,6 +25,7 @@ namespace Tests\Unit\Factory;
use FireflyIII\Factory\BillFactory;
+use Log;
use Tests\TestCase;
/**
@@ -33,6 +34,16 @@ use Tests\TestCase;
class BillFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* Create basic bill with minimum data.
*
@@ -77,17 +88,17 @@ class BillFactoryTest extends TestCase
public function testCreateEmptyNotes(): void
{
$data = [
- 'name' => 'Some new bill #' . random_int(1, 10000),
- 'amount_min' => '5',
- 'amount_max' => '10',
- 'date' => '2018-01-01',
- 'repeat_freq' => 'monthly',
- 'currency_id' => 1,
+ 'name' => 'Some new bill #' . random_int(1, 10000),
+ 'amount_min' => '5',
+ 'amount_max' => '10',
+ 'date' => '2018-01-01',
+ 'repeat_freq' => 'monthly',
+ 'currency_id' => 1,
'currency_code' => '',
- 'skip' => 0,
- 'automatch' => true,
- 'active' => true,
- 'notes' => '',
+ 'skip' => 0,
+ 'automatch' => true,
+ 'active' => true,
+ 'notes' => '',
];
/** @var BillFactory $factory */
diff --git a/tests/Unit/Factory/BudgetFactoryTest.php b/tests/Unit/Factory/BudgetFactoryTest.php
index 5544a4ba70..e4fbef4f06 100644
--- a/tests/Unit/Factory/BudgetFactoryTest.php
+++ b/tests/Unit/Factory/BudgetFactoryTest.php
@@ -25,6 +25,7 @@ namespace Tests\Unit\Factory;
use FireflyIII\Factory\BudgetFactory;
+use Log;
use Tests\TestCase;
/**
@@ -32,6 +33,16 @@ use Tests\TestCase;
*/
class BudgetFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* Put in ID, return it.
*
diff --git a/tests/Unit/Factory/CategoryFactoryTest.php b/tests/Unit/Factory/CategoryFactoryTest.php
index f98e9b353d..3c878df809 100644
--- a/tests/Unit/Factory/CategoryFactoryTest.php
+++ b/tests/Unit/Factory/CategoryFactoryTest.php
@@ -24,6 +24,7 @@ declare(strict_types=1);
namespace Tests\Unit\Factory;
use FireflyIII\Factory\CategoryFactory;
+use Log;
use Tests\TestCase;
/**
@@ -31,6 +32,16 @@ use Tests\TestCase;
*/
class CategoryFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\CategoryFactory
*/
diff --git a/tests/Unit/Factory/PiggyBankEventFactoryTest.php b/tests/Unit/Factory/PiggyBankEventFactoryTest.php
index c6079835bf..1d6f5a8af1 100644
--- a/tests/Unit/Factory/PiggyBankEventFactoryTest.php
+++ b/tests/Unit/Factory/PiggyBankEventFactoryTest.php
@@ -29,6 +29,7 @@ use FireflyIII\Models\PiggyBankEvent;
use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
+use Log;
use Tests\TestCase;
/**
@@ -36,6 +37,16 @@ use Tests\TestCase;
*/
class PiggyBankEventFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\PiggyBankEventFactory
*/
diff --git a/tests/Unit/Factory/PiggyBankFactoryTest.php b/tests/Unit/Factory/PiggyBankFactoryTest.php
index ff36f2d594..e9e39382cc 100644
--- a/tests/Unit/Factory/PiggyBankFactoryTest.php
+++ b/tests/Unit/Factory/PiggyBankFactoryTest.php
@@ -25,6 +25,7 @@ namespace Tests\Unit\Factory;
use FireflyIII\Factory\PiggyBankFactory;
+use Log;
use Tests\TestCase;
/**
@@ -32,6 +33,16 @@ use Tests\TestCase;
*/
class PiggyBankFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* Put in ID, return it.
*
diff --git a/tests/Unit/Factory/RecurrenceFactoryTest.php b/tests/Unit/Factory/RecurrenceFactoryTest.php
new file mode 100644
index 0000000000..fd7a658a3e
--- /dev/null
+++ b/tests/Unit/Factory/RecurrenceFactoryTest.php
@@ -0,0 +1,552 @@
+<?php
+/**
+ * RecurrenceFactoryTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Factory;
+
+
+use Amount;
+use Carbon\Carbon;
+use FireflyIII\Factory\BudgetFactory;
+use FireflyIII\Factory\CategoryFactory;
+use FireflyIII\Factory\PiggyBankFactory;
+use FireflyIII\Factory\RecurrenceFactory;
+use FireflyIII\Factory\TransactionCurrencyFactory;
+use FireflyIII\Factory\TransactionTypeFactory;
+use FireflyIII\Models\TransactionCurrency;
+use FireflyIII\Models\TransactionType;
+use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use Log;
+use Tests\TestCase;
+
+/**
+ *
+ * Class RecurrenceFactoryTest
+ */
+class RecurrenceFactoryTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * With piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testBasic(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $accountA = $this->user()->accounts()->inRandomOrder()->first();
+ $accountB = $this->user()->accounts()->inRandomOrder()->first();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category= $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ // mock calls:
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($accountA, $accountB);
+
+ $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
+ $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
+
+ $budgetFactory->shouldReceive('setUser')->once();
+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
+
+ $categoryFactory->shouldReceive('setUser')->once();
+ $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'withdrawal',
+ 'first_date' => Carbon::create()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . random_int(1, 100000),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'meta' => [
+ 'tags' => ['a', 'b', 'c'],
+ 'piggy_bank_id' => 1,
+ 'piggy_bank_name' => 'Bla bla',
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ 'budget_name' => 'Some budget',
+ 'category_id' => 2,
+ 'category_name' => 'Some category',
+
+ ],
+ ],
+ ];
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
+ /**
+ * Deposit. With piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testBasicDeposit(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $accountA = $this->user()->accounts()->inRandomOrder()->first();
+ $accountB = $this->user()->accounts()->inRandomOrder()->first();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category= $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ // mock calls:
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($accountA, $accountB);
+
+ $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
+ $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
+
+ $budgetFactory->shouldReceive('setUser')->once();
+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
+
+ $categoryFactory->shouldReceive('setUser')->once();
+ $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'deposit',
+ 'first_date' => Carbon::create()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . random_int(1, 100000),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'meta' => [
+ 'tags' => ['a', 'b', 'c'],
+ 'piggy_bank_id' => 1,
+ 'piggy_bank_name' => 'Bla bla',
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ 'budget_name' => 'Some budget',
+ 'category_id' => 2,
+ 'category_name' => 'Some category',
+
+ ],
+ ],
+ ];
+
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(2));
+
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
+ /**
+ * Deposit. With piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testBasicTransfer(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $accountA = $this->user()->accounts()->inRandomOrder()->first();
+ $accountB = $this->user()->accounts()->inRandomOrder()->first();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category= $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ // mock calls:
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($accountA, $accountB);
+
+ $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
+ $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
+
+ $budgetFactory->shouldReceive('setUser')->once();
+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
+
+ $categoryFactory->shouldReceive('setUser')->once();
+ $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'transfer',
+ 'first_date' => Carbon::create()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . random_int(1, 100000),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'meta' => [
+ 'tags' => ['a', 'b', 'c'],
+ 'piggy_bank_id' => 1,
+ 'piggy_bank_name' => 'Bla bla',
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ 'budget_name' => 'Some budget',
+ 'category_id' => 2,
+ 'category_name' => 'Some category',
+
+ ],
+ ],
+ ];
+
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(3));
+
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
+ /**
+ * With piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testBasicNoTags(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $accountA = $this->user()->accounts()->inRandomOrder()->first();
+ $accountB = $this->user()->accounts()->inRandomOrder()->first();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category= $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ // mock calls:
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn($piggyBank);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($accountA, $accountB);
+
+ $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
+ $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
+
+ $budgetFactory->shouldReceive('setUser')->once();
+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
+
+ $categoryFactory->shouldReceive('setUser')->once();
+ $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'withdrawal',
+ 'first_date' => Carbon::create()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . random_int(1, 100000),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'meta' => [
+ 'tags' => [],
+ 'piggy_bank_id' => 1,
+ 'piggy_bank_name' => 'Bla bla',
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ 'budget_name' => 'Some budget',
+ 'category_id' => 2,
+ 'category_name' => 'Some category',
+
+ ],
+ ],
+ ];
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
+ /**
+ * No piggy bank. With tags. With budget. With category.
+ *
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ * @covers \FireflyIII\Services\Internal\Support\RecurringTransactionTrait
+ */
+ public function testBasicNoPiggybank(): void
+ {
+ // objects to return:
+ $piggyBank = $this->user()->piggyBanks()->inRandomOrder()->first();
+ $accountA = $this->user()->accounts()->inRandomOrder()->first();
+ $accountB = $this->user()->accounts()->inRandomOrder()->first();
+ $budget = $this->user()->budgets()->inRandomOrder()->first();
+ $category= $this->user()->categories()->inRandomOrder()->first();
+
+ // mock other factories:
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ // mock calls:
+ Amount::shouldReceive('getDefaultCurrencyByUser')->andReturn(TransactionCurrency::find(1))->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('find')->withArgs([1, 'Bla bla'])->andReturn(null);
+
+ $accountRepos->shouldReceive('setUser')->twice();
+ $accountRepos->shouldReceive('findNull')->twice()->andReturn($accountA, $accountB);
+
+ $currencyFactory->shouldReceive('find')->once()->withArgs([1, 'EUR'])->andReturn(null);
+ $currencyFactory->shouldReceive('find')->once()->withArgs([null, null])->andReturn(null);
+
+ $budgetFactory->shouldReceive('setUser')->once();
+ $budgetFactory->shouldReceive('find')->withArgs([1, 'Some budget'])->once()->andReturn($budget);
+
+ $categoryFactory->shouldReceive('setUser')->once();
+ $categoryFactory->shouldReceive('findOrCreate')->withArgs([2, 'Some category'])->once()->andReturn($category);
+
+ // data for basic recurrence.
+ $data = [
+ 'recurrence' => [
+ 'type' => 'withdrawal',
+ 'first_date' => Carbon::create()->addDay(),
+ 'repetitions' => 0,
+ 'title' => 'Test recurrence' . random_int(1, 100000),
+ 'description' => 'Description thing',
+ 'apply_rules' => true,
+ 'active' => true,
+ 'repeat_until' => null,
+ ],
+ 'meta' => [
+ 'tags' => ['a', 'b', 'c'],
+ 'piggy_bank_id' => 1,
+ 'piggy_bank_name' => 'Bla bla',
+ ],
+ 'repetitions' => [
+ [
+ 'type' => 'daily',
+ 'moment' => '',
+ 'skip' => 0,
+ 'weekend' => 1,
+ ],
+ ],
+ 'transactions' => [
+ [
+ 'source_id' => 1,
+ 'source_name' => 'Some name',
+ 'destination_id' => 2,
+ 'destination_name' => 'some otjer name',
+ 'currency_id' => 1,
+ 'currency_code' => 'EUR',
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'description' => 'Bla bla bla',
+ 'amount' => '100',
+ 'budget_id' => 1,
+ 'budget_name' => 'Some budget',
+ 'category_id' => 2,
+ 'category_name' => 'Some category',
+
+ ],
+ ],
+ ];
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(TransactionType::find(1));
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertEquals($result->title, $data['recurrence']['title']);
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\RecurrenceFactory
+ */
+ public function testCreateBadTransactionType(): void
+ {
+ $data = [
+ 'recurrence' => [
+ 'type' => 'bad type',
+ ],
+ ];
+
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $typeFactory->shouldReceive('find')->once()->withArgs([ucfirst($data['recurrence']['type'])])->andReturn(null);
+
+
+ $factory = new RecurrenceFactory;
+ $factory->setUser($this->user());
+
+ $result = $factory->create($data);
+ $this->assertNull($result);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Factory/TagFactoryTest.php b/tests/Unit/Factory/TagFactoryTest.php
index 284ac8c6c6..cc4b984de1 100644
--- a/tests/Unit/Factory/TagFactoryTest.php
+++ b/tests/Unit/Factory/TagFactoryTest.php
@@ -25,6 +25,7 @@ namespace Tests\Unit\Factory;
use FireflyIII\Factory\TagFactory;
+use Log;
use Tests\TestCase;
/**
@@ -32,6 +33,16 @@ use Tests\TestCase;
*/
class TagFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\TagFactory
*/
diff --git a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php b/tests/Unit/Factory/TransactionCurrencyFactoryTest.php
index 3172100117..a0200409f5 100644
--- a/tests/Unit/Factory/TransactionCurrencyFactoryTest.php
+++ b/tests/Unit/Factory/TransactionCurrencyFactoryTest.php
@@ -26,6 +26,7 @@ namespace Tests\Unit\Factory;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\TransactionCurrency;
+use Log;
use Tests\TestCase;
/**
@@ -33,6 +34,16 @@ use Tests\TestCase;
*/
class TransactionCurrencyFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\TransactionCurrencyFactory
*/
diff --git a/tests/Unit/Factory/TransactionFactoryTest.php b/tests/Unit/Factory/TransactionFactoryTest.php
index 76253ceaff..4590025604 100644
--- a/tests/Unit/Factory/TransactionFactoryTest.php
+++ b/tests/Unit/Factory/TransactionFactoryTest.php
@@ -35,6 +35,7 @@ use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
+use Log;
use Tests\TestCase;
/**
@@ -42,6 +43,16 @@ use Tests\TestCase;
*/
class TransactionFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\TransactionFactory
* @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
@@ -617,6 +628,70 @@ class TransactionFactoryTest extends TestCase
$this->assertNull($first->foreign_currency_id);
}
+ /**
+ * @covers \FireflyIII\Factory\TransactionFactory
+ * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
+ */
+ public function testCreatePairEmptyAmount(): void
+ {
+ // objects:
+ $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
+ $euro = TransactionCurrency::first();
+
+ // mocked classes
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ $data = [
+ 'currency_id' => 1,
+ 'currency_code' => null,
+ 'description' => null,
+ 'source_id' => $asset->id,
+ 'source_name' => null,
+ 'destination_id' => $expense->id,
+ 'destination_name' => null,
+ 'amount' => '',
+ 'reconciled' => false,
+ 'identifier' => 0,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ ];
+
+ // mock:
+ $accountRepos->shouldReceive('setUser');
+ $budgetFactory->shouldReceive('setUser');
+ $categoryFactory->shouldReceive('setUser');
+ // first search action is for the asset account, second is for expense account.
+ $accountRepos->shouldReceive('findNull')->andReturn($asset, $expense)->atLeast()->once();
+
+ // factories return various stuff:
+ $currencyFactory->shouldReceive('find')->andReturn($euro, null)->atLeast()->once();
+
+ /** @var TransactionJournal $withdrawal */
+ $withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
+ $count = $withdrawal->transactions()->count();
+
+ /** @var TransactionFactory $factory */
+ $factory = app(TransactionFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->createPair($withdrawal, $data);
+ } catch (FireflyException $e) {
+ $this->assertEquals('Amount is an empty string, which Firefly III cannot handle. Apologies.', $e->getMessage());
+ }
+
+ $newCount = $withdrawal->transactions()->count();
+ $this->assertEquals($count, $newCount);
+ }
+
/**
* @covers \FireflyIII\Factory\TransactionFactory
* @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
@@ -695,6 +770,135 @@ class TransactionFactoryTest extends TestCase
$this->assertEquals($foreign->id, $first->foreign_currency_id);
}
+ /**
+ * @covers \FireflyIII\Factory\TransactionFactory
+ * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
+ */
+ public function testCreatePairNoAccounts(): void
+ {
+ // objects:
+ $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
+ $euro = TransactionCurrency::first();
+
+ // mocked classes
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ $data = [
+ 'currency_id' => 1,
+ 'currency_code' => null,
+ 'description' => null,
+ 'source_id' => $asset->id,
+ 'source_name' => null,
+ 'destination_id' => $expense->id,
+ 'destination_name' => null,
+ 'amount' => '10',
+ 'reconciled' => false,
+ 'identifier' => 0,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ ];
+
+ // mock:
+ $accountRepos->shouldReceive('setUser');
+ $budgetFactory->shouldReceive('setUser');
+ $categoryFactory->shouldReceive('setUser');
+ // first search action is for the asset account, second is for expense account.
+ $accountRepos->shouldReceive('findNull')->andReturn(null, null)->atLeast()->once();
+
+ // factories return various stuff:
+ $currencyFactory->shouldReceive('find')->andReturn($euro, null)->atLeast()->once();
+
+ /** @var TransactionJournal $withdrawal */
+ $withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
+ $count = $withdrawal->transactions()->count();
+
+ /** @var TransactionFactory $factory */
+ $factory = app(TransactionFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->createPair($withdrawal, $data);
+ } catch (FireflyException $e) {
+ $this->assertEquals('Could not determine source or destination account.', $e->getMessage());
+ }
+
+ $newCount = $withdrawal->transactions()->count();
+
+ $this->assertEquals($count, $newCount);
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\TransactionFactory
+ * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
+ */
+ public function testCreatePairNoCurrency(): void
+ {
+ // objects:
+ $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
+
+ // mocked classes
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ $data = [
+ 'description' => null,
+ 'source_id' => $asset->id,
+ 'source_name' => null,
+ 'destination_id' => $expense->id,
+ 'currency_id' => null,
+ 'currency_code' => null,
+ 'destination_name' => null,
+ 'amount' => '10',
+ 'reconciled' => false,
+ 'identifier' => 0,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ ];
+
+ // mock:
+ $accountRepos->shouldReceive('setUser');
+ $budgetFactory->shouldReceive('setUser');
+ $categoryFactory->shouldReceive('setUser');
+ // first search action is for the asset account, second is for expense account.
+ $accountRepos->shouldReceive('findNull')->andReturn($asset, $expense)->atLeast()->once();
+
+ // factories return various stuff:
+ $currencyFactory->shouldReceive('find')->andReturn(null, null)->atLeast()->once();
+
+ /** @var TransactionJournal $withdrawal */
+ $withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
+ $count = $withdrawal->transactions()->count();
+
+ /** @var TransactionFactory $factory */
+ $factory = app(TransactionFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->createPair($withdrawal, $data);
+ } catch (FireflyException $e) {
+ $this->assertEquals('Cannot store transaction without currency information.', $e->getMessage());
+ }
+
+ $newCount = $withdrawal->transactions()->count();
+
+ $this->assertEquals($count, $newCount);
+ }
+
/**
* Create reconciliation using minimal data.
*
@@ -706,8 +910,8 @@ class TransactionFactoryTest extends TestCase
// objects:
$asset = $this->user()->accounts()->where('account_type_id', 3)->first();
$reconAccount = $this->user()->accounts()->where('account_type_id', 10)->first();
- $euro = TransactionCurrency::first();
- $foreign = TransactionCurrency::where('id', '!=', $euro->id)->first();
+ $euro = TransactionCurrency::first();
+ $foreign = TransactionCurrency::where('id', '!=', $euro->id)->first();
// mocked classes
$accountRepos = $this->mock(AccountRepositoryInterface::class);
@@ -776,6 +980,134 @@ class TransactionFactoryTest extends TestCase
$this->assertNull($first->foreign_currency_id);
}
+ /**
+ * @covers \FireflyIII\Factory\TransactionFactory
+ * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
+ */
+ public function testCreatePairSameBadType(): void
+ {
+ // objects:
+ $expense = $this->user()->accounts()->where('account_type_id', 4)->first();
+ $revenue = $this->user()->accounts()->where('account_type_id', 5)->first();
+ $euro = TransactionCurrency::first();
+
+ // mocked classes
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ $data = [
+ 'currency_id' => 1,
+ 'currency_code' => null,
+ 'description' => null,
+ 'source_id' => $expense->id,
+ 'source_name' => null,
+ 'destination_id' => $revenue->id,
+ 'destination_name' => null,
+ 'amount' => '10',
+ 'reconciled' => false,
+ 'identifier' => 0,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ ];
+
+ // mock:
+ $accountRepos->shouldReceive('setUser');
+ $budgetFactory->shouldReceive('setUser');
+ $categoryFactory->shouldReceive('setUser');
+ // first search action is for the asset account, second is for expense account.
+ $accountRepos->shouldReceive('findNull')->andReturn($expense, $revenue);
+
+ // factories return various stuff:
+ $currencyFactory->shouldReceive('find')->andReturn($euro, null)->atLeast()->once();
+
+ /** @var TransactionJournal $withdrawal */
+ $withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
+ $count = $withdrawal->transactions()->count();
+
+ /** @var TransactionFactory $factory */
+ $factory = app(TransactionFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->createPair($withdrawal, $data);
+ } catch (FireflyException $e) {
+ $this->assertEquals('At least one of the accounts must be an asset account.', $e->getMessage());
+ }
+
+ $newCount = $withdrawal->transactions()->count();
+ $this->assertEquals($count, $newCount);
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\TransactionFactory
+ * @covers \FireflyIII\Services\Internal\Support\TransactionServiceTrait
+ */
+ public function testCreatePairSameType(): void
+ {
+ // objects:
+ $asset = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $alsoAsset = $this->user()->accounts()->where('account_type_id', 3)->first();
+ $euro = TransactionCurrency::first();
+
+ // mocked classes
+ $accountRepos = $this->mock(AccountRepositoryInterface::class);
+ $budgetFactory = $this->mock(BudgetFactory::class);
+ $categoryFactory = $this->mock(CategoryFactory::class);
+ $currencyFactory = $this->mock(TransactionCurrencyFactory::class);
+
+ $data = [
+ 'currency_id' => 1,
+ 'currency_code' => null,
+ 'description' => null,
+ 'source_id' => $asset->id,
+ 'source_name' => null,
+ 'destination_id' => $alsoAsset->id,
+ 'destination_name' => null,
+ 'amount' => '10',
+ 'reconciled' => false,
+ 'identifier' => 0,
+ 'foreign_currency_id' => null,
+ 'foreign_currency_code' => null,
+ 'foreign_amount' => null,
+ 'budget_id' => null,
+ 'budget_name' => null,
+ 'category_id' => null,
+ 'category_name' => null,
+ ];
+
+ // mock:
+ $accountRepos->shouldReceive('setUser');
+ $budgetFactory->shouldReceive('setUser');
+ $categoryFactory->shouldReceive('setUser');
+ // first search action is for the asset account, second is for expense account.
+ $accountRepos->shouldReceive('findNull')->andReturn($asset, $alsoAsset);
+
+ // factories return various stuff:
+ $currencyFactory->shouldReceive('find')->andReturn($euro, null)->atLeast()->once();
+
+ /** @var TransactionJournal $withdrawal */
+ $withdrawal = $this->user()->transactionJournals()->where('transaction_type_id', 1)->first();
+ $count = $withdrawal->transactions()->count();
+
+ /** @var TransactionFactory $factory */
+ $factory = app(TransactionFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $factory->createPair($withdrawal, $data);
+ } catch (FireflyException $e) {
+ $this->assertEquals('Source and destination account cannot be both of the type "Asset account"', $e->getMessage());
+ }
+
+ $newCount = $withdrawal->transactions()->count();
+ $this->assertEquals($count, $newCount);
+ }
+
/**
* Create reconciliation using minimal (bad) data.
*
diff --git a/tests/Unit/Factory/TransactionJournalFactoryTest.php b/tests/Unit/Factory/TransactionJournalFactoryTest.php
index 434d52ebde..bf3109fa0b 100644
--- a/tests/Unit/Factory/TransactionJournalFactoryTest.php
+++ b/tests/Unit/Factory/TransactionJournalFactoryTest.php
@@ -37,6 +37,7 @@ use FireflyIII\Factory\TransactionTypeFactory;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
+use Log;
use Tests\TestCase;
/**
@@ -45,6 +46,15 @@ use Tests\TestCase;
class TransactionJournalFactoryTest extends TestCase
{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\TransactionJournalFactory
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
@@ -106,6 +116,71 @@ class TransactionJournalFactoryTest extends TestCase
}
+ /**
+ * @covers \FireflyIII\Factory\TransactionJournalFactory
+ * @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
+ */
+ public function testCreateBasicEmptyAmount(): void
+ {
+ // mock used classes:
+ $type = TransactionType::find(1);
+ $euro = TransactionCurrency::find(1);
+ $billFactory = $this->mock(BillFactory::class);
+ $tagFactory = $this->mock(TagFactory::class);
+ $metaFactory = $this->mock(TransactionJournalMetaFactory::class);
+ $typeFactory = $this->mock(TransactionTypeFactory::class);
+ $transactionFactory = $this->mock(TransactionFactory::class);
+ $piggyFactory = $this->mock(PiggyBankFactory::class);
+ $eventFactory = $this->mock(PiggyBankEventFactory::class);
+ $currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
+
+ // mock stuff:
+ $typeFactory->shouldReceive('find')->andReturn($type);
+ $currencyRepos->shouldReceive('find')->andReturn($euro);
+
+ $metaFactory->shouldReceive('updateOrCreate');
+
+ // mock factories:
+ $transactionFactory->shouldReceive('setUser')->once();
+ $billFactory->shouldReceive('setUser')->once();
+ $piggyFactory->shouldReceive('setUser')->once();
+ $tagFactory->shouldReceive('setUser')->once();
+
+ $transactionFactory->shouldReceive('createPair')->once();
+ $billFactory->shouldReceive('find')->andReturn(null);
+ $piggyFactory->shouldReceive('find')->andReturn(null);
+ $data = [
+ 'type' => 'withdrawal',
+ 'user' => $this->user()->id,
+ 'description' => 'I are journal',
+ 'date' => new Carbon('2018-01-01'),
+ 'bill_id' => null,
+ 'bill_name' => null,
+ 'piggy_bank_id' => null,
+ 'piggy_bank_name' => null,
+ 'notes' => 'Hello',
+ 'tags' => [],
+ 'transactions' => [
+ [
+ 'amount' => '',
+ ]
+ ],
+ ];
+
+ /** @var TransactionJournalFactory $factory */
+ $factory = app(TransactionJournalFactory::class);
+ $factory->setUser($this->user());
+ try {
+ $journal = $factory->create($data);
+ } catch (FireflyException $e) {
+ $this->assertTrue(false, $e->getMessage());
+ }
+ $this->assertEquals($data['description'], $journal->description);
+ $this->assertEquals('2018-01-01', $journal->date->format('Y-m-d'));
+ $this->assertEquals(1, $journal->notes()->count());
+
+ }
+
/**
* Same but with added meta data
diff --git a/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php b/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php
index 748308c763..8b6b310d7f 100644
--- a/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php
+++ b/tests/Unit/Factory/TransactionJournalMetaFactoryTest.php
@@ -27,6 +27,7 @@ use Carbon\Carbon;
use FireflyIII\Factory\TransactionJournalMetaFactory;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalMeta;
+use Log;
use Tests\TestCase;
/**
@@ -34,6 +35,16 @@ use Tests\TestCase;
*/
class TransactionJournalMetaFactoryTest extends TestCase
{
+
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
/**
* @covers \FireflyIII\Factory\TransactionJournalMetaFactory
*/
diff --git a/tests/Unit/Factory/TransactionTypeFactoryTest.php b/tests/Unit/Factory/TransactionTypeFactoryTest.php
new file mode 100644
index 0000000000..fbc3d7a457
--- /dev/null
+++ b/tests/Unit/Factory/TransactionTypeFactoryTest.php
@@ -0,0 +1,62 @@
+<?php
+/**
+ * TransactionTypeFactoryTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Factory;
+
+
+use FireflyIII\Factory\TransactionTypeFactory;
+use FireflyIII\Models\TransactionType;
+use Log;
+use Tests\TestCase;
+
+/**
+ *
+ * Class TransactionTypeFactoryTest
+ */
+class TransactionTypeFactoryTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Factory\TransactionTypeFactory
+ */
+ public function testFind(): void
+ {
+ /** @var TransactionType $type */
+ $type = TransactionType::first();
+ /** @var TransactionTypeFactory $factory */
+ $factory = app(TransactionTypeFactory::class);
+
+ $result = $factory->find($type->type);
+
+ $this->assertEquals($result->id, $type->id);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php b/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php
new file mode 100644
index 0000000000..77af41988e
--- /dev/null
+++ b/tests/Unit/Generator/Chart/Basic/ChartJsGeneratorTest.php
@@ -0,0 +1,156 @@
+<?php
+/**
+ * ChartJsGeneratorTest.php
+ * Copyright (c) 2018 [email protected]
+ *
+ * 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\Generator\Chart\Basic;
+
+use FireflyIII\Generator\Chart\Basic\ChartJsGenerator;
+use Log;
+use Tests\TestCase;
+
+/**
+ *
+ * Class ChartJsGeneratorTest
+ */
+class ChartJsGeneratorTest extends TestCase
+{
+ /**
+ *
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+ Log::debug(sprintf('Now in %s.', \get_class($this)));
+ }
+
+ /**
+ * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
+ */
+ public function testBasic(): void
+ {
+
+ $data = [
+ [
+ 'label' => 'Today',
+ 'fill' => '#abcdef',
+ 'yAxisID' => 'a',
+ 'entries' => [
+ 'one' => 1,
+ 'two' => 2,
+ 'three' => 3,
+ 'four' => 4,
+ 'five' => 5,
+ ],
+ ],
+ [
+
+ 'currency_symbol' => 'X',
+ 'backgroundColor' => '#123456',
+ 'label' => 'Tomorrow',
+ 'entries' => [
+ 'one' => 6,
+ 'two' => 7,
+ 'three' => 8,
+ 'four' => 9,
+ 'five' => 10,
+ ],
+ ],
+ ];
+
+
+ /** @var ChartJsGenerator $generator */
+ $generator = new ChartJsGenerator();
+
+ $result = $generator->multiSet($data);
+ $this->assertEquals('one', $result['labels'][0]);
+ $this->assertEquals(2, $result['count']);
+ $this->assertCount(2, $result['datasets']);
+
+ $this->assertEquals('a', $result['datasets'][0]['yAxisID']);
+ $this->assertEquals('#abcdef', $result['datasets'][0]['fill']);
+
+ $this->assertEquals('X', $result['datasets'][1]['currency_symbol']);
+ $this->assertEquals('#123456', $result['datasets'][1]['backgroundColor']);
+ }
+
+ /**
+ * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
+ */
+ public function testPieChart(): void
+ {
+
+ $data = [
+ 'one' => -1,
+ 'two' => -2,
+ 'three' => -3,
+ ];
+
+ /** @var ChartJsGenerator $generator */
+ $generator = new ChartJsGenerator();
+ $result = $generator->pieChart($data);
+
+ $this->assertEquals('three', $result['labels'][0]);
+ $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
+
+ }
+
+ /**
+ * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
+ */
+ public function testPieChartReversed(): void
+ {
+
+ $data = [
+ 'one' => 1,
+ 'two' => 2,
+ 'three' => 3,
+ ];
+
+ /** @var ChartJsGenerator $generator */
+ $generator = new ChartJsGenerator();
+ $result = $generator->pieChart($data);
+
+ $this->assertEquals('three', $result['labels'][0]);
+ $this->assertEquals(3.0, $result['datasets'][0]['data'][0]);
+
+ }
+
+ /**
+ * @covers \FireflyIII\Generator\Chart\Basic\ChartJsGenerator
+ */
+ public function testSingleSet(): void
+ {
+ $data = [
+ 'one' => '1',
+ 'two' => '2',
+ 'three' => '3',
+ ];
+
+ /** @var ChartJsGenerator $generator */
+ $generator = new ChartJsGenerator();
+ $result = $generator->singleSet('Some label', $data);
+
+ $this->assertEquals('one', $result['labels'][0]);
+ $this->assertEquals(1.0, $result['datasets'][0]['data'][0]);
+ }
+
+}
\ No newline at end of file
diff --git a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php b/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
index 482589d2e0..09c856a573 100644
--- a/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
+++ b/tests/Unit/Support/Import/Routine/File/ImportableConverterTest.php
@@ -146,9 +146,10 @@ class ImportableConverterTest extends TestCase
$assetMapper->shouldReceive('map')->once()->withArgs([null, $nullAccount])->andReturn($asset);
$opposingMapper->shouldReceive('map')->once()->withArgs([null, '45.67', $nullAccount])->andReturn($other);
+
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['name' => null, 'code' => null, 'symbol' => null]])->andReturn(null);
$currencyMapper->shouldReceive('map')->once()->withArgs([null, ['code' => null]])->andReturn(null);
- $currencyMapper->shouldReceive('map')->times(2)->withArgs([$euro->id, []])->andReturn($euro);
+ $currencyMapper->shouldReceive('map')->times(1)->withArgs([$euro->id, []])->andReturn($euro);
$converter = new ImportableConverter;