Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update test coverage.
James Colec55b80f46752
diff --git a/app/Helpers/Attachments/AttachmentHelper.php b/app/Helpers/Attachments/AttachmentHelper.phpindex 8714dfec07..9c9c7bf55e 100644--- a/app/Helpers/Attachments/AttachmentHelper.php+++ b/app/Helpers/Attachments/AttachmentHelper.php@@ -144,9 +144,11 @@ class AttachmentHelper implements AttachmentHelperInterface{$resource = tmpfile();if (false === $resource) {+ // @codeCoverageIgnoreStartLog::error('Cannot create temp-file for file upload.');return false;+ // @codeCoverageIgnoreEnd}$path = stream_get_meta_data($resource)['uri'];fwrite($resource, $content);@@ -341,9 +343,12 @@ class AttachmentHelper implements AttachmentHelperInterfaceif (!$this->validMime($file)) {$result = false;}+ // @codeCoverageIgnoreStart+ // can't seem to reach this point.if (true === $result && !$this->validSize($file)) {$result = false;}+ // @codeCoverageIgnoreEndif (true === $result && $this->hasFile($file, $model)) {$result = false;}diff --git a/app/Helpers/Collection/Balance.php b/app/Helpers/Collection/Balance.phpindex b10674cefd..71573853ea 100644--- a/app/Helpers/Collection/Balance.php+++ b/app/Helpers/Collection/Balance.php@@ -26,6 +26,8 @@ use Illuminate\Support\Collection;/*** Class Balance.+ *+ * @codeCoverageIgnore*/class Balance{diff --git a/app/Helpers/Collection/BalanceEntry.php b/app/Helpers/Collection/BalanceEntry.phpindex 8f2e4fb195..86eddf607b 100644--- a/app/Helpers/Collection/BalanceEntry.php+++ b/app/Helpers/Collection/BalanceEntry.php@@ -26,6 +26,8 @@ use FireflyIII\Models\Account as AccountModel;/*** Class BalanceEntry.+ *+ * @codeCoverageIgnore*/class BalanceEntry{diff --git a/app/Helpers/Collection/BalanceHeader.php b/app/Helpers/Collection/BalanceHeader.phpindex 46c3091333..3769b0f5c0 100644--- a/app/Helpers/Collection/BalanceHeader.php+++ b/app/Helpers/Collection/BalanceHeader.php@@ -27,6 +27,8 @@ use Illuminate\Support\Collection;/*** Class BalanceHeader.+ *+ * @codeCoverageIgnore*/class BalanceHeader{diff --git a/app/Helpers/Collection/BalanceLine.php b/app/Helpers/Collection/BalanceLine.phpindex a679ef66ff..89668f0963 100644--- a/app/Helpers/Collection/BalanceLine.php+++ b/app/Helpers/Collection/BalanceLine.php@@ -29,6 +29,8 @@ use Illuminate\Support\Collection;/*** Class BalanceLine.+ *+ * @codeCoverageIgnore*/class BalanceLine{diff --git a/app/Helpers/Collection/Bill.php b/app/Helpers/Collection/Bill.phpindex 9ce761345d..f950a93914 100644--- a/app/Helpers/Collection/Bill.php+++ b/app/Helpers/Collection/Bill.php@@ -29,6 +29,8 @@ use Log;/*** Class Bill.+ *+ * @codeCoverageIgnore*/class Bill{diff --git a/app/Helpers/Collection/BillLine.php b/app/Helpers/Collection/BillLine.phpindex 4be29cb07a..eb1e4c8fee 100644--- a/app/Helpers/Collection/BillLine.php+++ b/app/Helpers/Collection/BillLine.php@@ -27,6 +27,8 @@ use FireflyIII\Models\Bill as BillModel;/*** Class BillLine.+ *+ * @codeCoverageIgnore*/class BillLine{diff --git a/app/Helpers/Collection/Category.php b/app/Helpers/Collection/Category.phpindex 9868bdb945..ce774387ae 100644--- a/app/Helpers/Collection/Category.php+++ b/app/Helpers/Collection/Category.php@@ -27,6 +27,8 @@ use Illuminate\Support\Collection;/*** Class Category.+ *+ * @codeCoverageIgnore*/class Category{diff --git a/app/Helpers/Collector/TransactionCollector.php b/app/Helpers/Collector/TransactionCollector.phpindex b397203fcd..cb06889b14 100644--- a/app/Helpers/Collector/TransactionCollector.php+++ b/app/Helpers/Collector/TransactionCollector.php@@ -52,6 +52,8 @@ use Log;/*** Class TransactionCollector+ *+ * @codeCoverageIgnore*/class TransactionCollector implements TransactionCollectorInterface{diff --git a/app/Helpers/Filter/CountAttachmentsFilter.php b/app/Helpers/Filter/CountAttachmentsFilter.phpindex bcb61fa3c2..c47cb838d9 100644--- a/app/Helpers/Filter/CountAttachmentsFilter.php+++ b/app/Helpers/Filter/CountAttachmentsFilter.php@@ -31,6 +31,7 @@ use Illuminate\Support\Collection;/*** Class CountAttachmentsFilter+ * @codeCoverageIgnore*/class CountAttachmentsFilter implements FilterInterface{diff --git a/app/Helpers/Filter/EmptyFilter.php b/app/Helpers/Filter/EmptyFilter.phpindex 2235fe2bfa..716b3d9cdb 100644--- a/app/Helpers/Filter/EmptyFilter.php+++ b/app/Helpers/Filter/EmptyFilter.php@@ -26,6 +26,8 @@ use Illuminate\Support\Collection;/*** Class EmptyFilter.+ *+ * @codeCoverageIgnore*/class EmptyFilter implements FilterInterface{diff --git a/app/Helpers/Filter/InternalTransferFilter.php b/app/Helpers/Filter/InternalTransferFilter.phpindex 1442db3d20..a72474c4e0 100644--- a/app/Helpers/Filter/InternalTransferFilter.php+++ b/app/Helpers/Filter/InternalTransferFilter.php@@ -32,6 +32,8 @@ use Log;* This filter removes any filters that are from A to B or from B to A given a set of* account id's (in $parameters) where A and B are mentioned. So transfers between the mentioned* accounts will be removed.+ *+ * @codeCoverageIgnore*/class InternalTransferFilter implements FilterInterface{diff --git a/app/Helpers/Filter/NegativeAmountFilter.php b/app/Helpers/Filter/NegativeAmountFilter.phpindex b6b0f10cf6..58ebc6ed3b 100644--- a/app/Helpers/Filter/NegativeAmountFilter.php+++ b/app/Helpers/Filter/NegativeAmountFilter.php@@ -30,6 +30,8 @@ use Log;* Class NegativeAmountFilter.** This filter removes entries with a negative amount (the original modifier is -1).+ *+ * @codeCoverageIgnore*/class NegativeAmountFilter implements FilterInterface{diff --git a/app/Helpers/Filter/OpposingAccountFilter.php b/app/Helpers/Filter/OpposingAccountFilter.phpindex 5df2170ce6..681a4c26b2 100644--- a/app/Helpers/Filter/OpposingAccountFilter.php+++ b/app/Helpers/Filter/OpposingAccountFilter.php@@ -31,6 +31,8 @@ use Log;** This filter is similar to the internal transfer filter but only removes transactions when the opposing account is* amongst $parameters (list of account ID's).+ *+ * @codeCoverageIgnore*/class OpposingAccountFilter implements FilterInterface{diff --git a/app/Helpers/Filter/PositiveAmountFilter.php b/app/Helpers/Filter/PositiveAmountFilter.phpindex 155c6c3f33..257bdf43b4 100644--- a/app/Helpers/Filter/PositiveAmountFilter.php+++ b/app/Helpers/Filter/PositiveAmountFilter.php@@ -33,6 +33,8 @@ use Log;** This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount* ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.+ *+ * @codeCoverageIgnore*/class PositiveAmountFilter implements FilterInterface{diff --git a/app/Helpers/Filter/SplitIndicatorFilter.php b/app/Helpers/Filter/SplitIndicatorFilter.phpindex afc42c30c5..609c3a424e 100644--- a/app/Helpers/Filter/SplitIndicatorFilter.php+++ b/app/Helpers/Filter/SplitIndicatorFilter.php@@ -30,6 +30,8 @@ use Illuminate\Support\Collection;/*** Class SplitIndicatorFilter+ *+ * @codeCoverageIgnore*/class SplitIndicatorFilter implements FilterInterface{diff --git a/app/Helpers/Filter/TransactionViewFilter.php b/app/Helpers/Filter/TransactionViewFilter.phpindex 1c8dc2938a..baae12173d 100644--- a/app/Helpers/Filter/TransactionViewFilter.php+++ b/app/Helpers/Filter/TransactionViewFilter.php@@ -35,6 +35,8 @@ use Log;** This is used in the mass-edit routine.*+ * @codeCoverageIgnore+ **/class TransactionViewFilter implements FilterInterface{diff --git a/app/Helpers/Filter/TransferFilter.php b/app/Helpers/Filter/TransferFilter.phpindex 40f2037a3b..26037700a8 100644--- a/app/Helpers/Filter/TransferFilter.php+++ b/app/Helpers/Filter/TransferFilter.php@@ -30,6 +30,8 @@ use Illuminate\Support\Collection;* Class TransferFilter.** This filter removes any transfers that are in the collection twice (from A to B and from B to A).+ *+ * @codeCoverageIgnore*/class TransferFilter implements FilterInterface{diff --git a/tests/Unit/Helpers/AttachmentHelperTest.php b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.phpsimilarity index 78%rename from tests/Unit/Helpers/AttachmentHelperTest.phprename to tests/Unit/Helpers/Attachments/AttachmentHelperTest.phpindex f70d66464a..4ecafc8d1a 100644--- a/tests/Unit/Helpers/AttachmentHelperTest.php+++ b/tests/Unit/Helpers/Attachments/AttachmentHelperTest.php@@ -20,14 +20,16 @@*/declare(strict_types=1);-namespace Tests\Unit\Helpers;+namespace Tests\Unit\Helpers\Attachments;+use Crypt;use FireflyIII\Helpers\Attachments\AttachmentHelper;use FireflyIII\Models\Attachment;use FireflyIII\Models\TransactionJournal;use Illuminate\Http\UploadedFile;use Illuminate\Support\Facades\Storage;use Tests\TestCase;+use Log;/*** Class AttachmentHelperTest@@ -38,6 +40,15 @@ use Tests\TestCase;*/class AttachmentHelperTest extends TestCase{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::debug(sprintf('Now in %s.', \get_class($this)));+ }+/*** @covers \FireflyIII\Helpers\Attachments\AttachmentHelper*/@@ -97,6 +108,45 @@ class AttachmentHelperTest extends TestCaseStorage::disk('upload')->assertExists(sprintf('at-%d.data', $attachments->first()->id));}+ /**+ * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper+ */+ public function testSaveAttachmentFromApi(): void+ {+ // mock calls:+ Crypt::shouldReceive('encrypt')->times(2)->andReturn('Some encrypted content');+ Storage::fake('upload');++ $path = public_path('apple-touch-icon.png');+ $helper = new AttachmentHelper;+ $attachment = Attachment::first();++ // call helper+ $result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));++ $this->assertTrue($result);++ }++ /**+ * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper+ */+ public function testSaveAttachmentFromApiBadMime(): void+ {+ // mock calls:+ Storage::fake('upload');++ $path = public_path('browserconfig.xml');+ $helper = new AttachmentHelper;+ $attachment = Attachment::first();++ // call helper+ $result = $helper->saveAttachmentFromApi($attachment, file_get_contents($path));++ $this->assertFalse($result);++ }+/*** Test double file upload. Needs to be after testSave.*diff --git a/tests/Unit/Helpers/MetaPieChartTest.php b/tests/Unit/Helpers/Chart/MetaPieChartTest.phpsimilarity index 98%rename from tests/Unit/Helpers/MetaPieChartTest.phprename to tests/Unit/Helpers/Chart/MetaPieChartTest.phpindex 9a30d81e47..5b44be9c61 100644--- a/tests/Unit/Helpers/MetaPieChartTest.php+++ b/tests/Unit/Helpers/Chart/MetaPieChartTest.php@@ -20,7 +20,7 @@*/declare(strict_types=1);-namespace Tests\Unit\Helpers;+namespace Tests\Unit\Helpers\Chart;use Carbon\Carbon;use FireflyIII\Helpers\Chart\MetaPieChart;@@ -35,6 +35,7 @@ use FireflyIII\Models\TransactionType;use FireflyIII\Repositories\Account\AccountRepositoryInterface;use Illuminate\Support\Collection;use Tests\TestCase;+use Log;/*** Class MetaPieChartTest@@ -45,6 +46,15 @@ use Tests\TestCase;*/class MetaPieChartTest extends TestCase{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::debug(sprintf('Now in %s.', \get_class($this)));+ }+/*** @covers \FireflyIII\Helpers\Chart\MetaPieChart*/diff --git a/tests/Unit/Helpers/Filter/AmountFilterTest.php b/tests/Unit/Helpers/Filter/AmountFilterTest.phpnew file mode 100644index 0000000000..ae68185e44--- /dev/null+++ b/tests/Unit/Helpers/Filter/AmountFilterTest.php@@ -0,0 +1,69 @@+<?php+/**+ * AmountFilterTest.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\Helpers\Filter;+++use FireflyIII\Helpers\Filter\AmountFilter;+use FireflyIII\Models\Transaction;+use Illuminate\Support\Collection;+use Log;+use Tests\TestCase;++/**+ *+ * Class AmountFilterTest+ */+class AmountFilterTest extends TestCase+{+ /**+ *+ */+ public function setUp(): void+ {+ parent::setUp();+ Log::debug(sprintf('Now in %s.', \get_class($this)));+ }++ /**+ * @covers \FireflyIII\Helpers\Filter\AmountFilter+ */+ public function testBasicPositive(): void+ {+ $count = 0;+ $collection = new Collection;+ for ($i = 0; $i < 10; $i++) {+ $amount = random_int(-10, 10);+ $transaction = new Transaction;+ $transaction->transaction_amount = (string)$amount;+ if ($amount <= 0) {+ $count++;+ }+ $collection->push($transaction);+ }++ $filter = new AmountFilter(1);+ $result = $filter->filter($collection);+ $this->assertCount($count, $result);+ }+}\ No newline at end of file