Update test coverage.

This commit is contained in:
James Cole 2018-08-25 20:45:42 +02:00
parent 2099da7142
commit c55b80f467
21 changed files with 169 additions and 2 deletions

View File

@ -144,9 +144,11 @@ class AttachmentHelper implements AttachmentHelperInterface
{ {
$resource = tmpfile(); $resource = tmpfile();
if (false === $resource) { if (false === $resource) {
// @codeCoverageIgnoreStart
Log::error('Cannot create temp-file for file upload.'); Log::error('Cannot create temp-file for file upload.');
return false; return false;
// @codeCoverageIgnoreEnd
} }
$path = stream_get_meta_data($resource)['uri']; $path = stream_get_meta_data($resource)['uri'];
fwrite($resource, $content); fwrite($resource, $content);
@ -341,9 +343,12 @@ class AttachmentHelper implements AttachmentHelperInterface
if (!$this->validMime($file)) { if (!$this->validMime($file)) {
$result = false; $result = false;
} }
// @codeCoverageIgnoreStart
// can't seem to reach this point.
if (true === $result && !$this->validSize($file)) { if (true === $result && !$this->validSize($file)) {
$result = false; $result = false;
} }
// @codeCoverageIgnoreEnd
if (true === $result && $this->hasFile($file, $model)) { if (true === $result && $this->hasFile($file, $model)) {
$result = false; $result = false;
} }

View File

@ -26,6 +26,8 @@ use Illuminate\Support\Collection;
/** /**
* Class Balance. * Class Balance.
*
* @codeCoverageIgnore
*/ */
class Balance class Balance
{ {

View File

@ -26,6 +26,8 @@ use FireflyIII\Models\Account as AccountModel;
/** /**
* Class BalanceEntry. * Class BalanceEntry.
*
* @codeCoverageIgnore
*/ */
class BalanceEntry class BalanceEntry
{ {

View File

@ -27,6 +27,8 @@ use Illuminate\Support\Collection;
/** /**
* Class BalanceHeader. * Class BalanceHeader.
*
* @codeCoverageIgnore
*/ */
class BalanceHeader class BalanceHeader
{ {

View File

@ -29,6 +29,8 @@ use Illuminate\Support\Collection;
/** /**
* Class BalanceLine. * Class BalanceLine.
*
* @codeCoverageIgnore
*/ */
class BalanceLine class BalanceLine
{ {

View File

@ -29,6 +29,8 @@ use Log;
/** /**
* Class Bill. * Class Bill.
*
* @codeCoverageIgnore
*/ */
class Bill class Bill
{ {

View File

@ -27,6 +27,8 @@ use FireflyIII\Models\Bill as BillModel;
/** /**
* Class BillLine. * Class BillLine.
*
* @codeCoverageIgnore
*/ */
class BillLine class BillLine
{ {

View File

@ -27,6 +27,8 @@ use Illuminate\Support\Collection;
/** /**
* Class Category. * Class Category.
*
* @codeCoverageIgnore
*/ */
class Category class Category
{ {

View File

@ -52,6 +52,8 @@ use Log;
/** /**
* Class TransactionCollector * Class TransactionCollector
*
* @codeCoverageIgnore
*/ */
class TransactionCollector implements TransactionCollectorInterface class TransactionCollector implements TransactionCollectorInterface
{ {

View File

@ -31,6 +31,7 @@ use Illuminate\Support\Collection;
/** /**
* Class CountAttachmentsFilter * Class CountAttachmentsFilter
* @codeCoverageIgnore
*/ */
class CountAttachmentsFilter implements FilterInterface class CountAttachmentsFilter implements FilterInterface
{ {

View File

@ -26,6 +26,8 @@ use Illuminate\Support\Collection;
/** /**
* Class EmptyFilter. * Class EmptyFilter.
*
* @codeCoverageIgnore
*/ */
class EmptyFilter implements FilterInterface class EmptyFilter implements FilterInterface
{ {

View File

@ -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 * 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 * account id's (in $parameters) where A and B are mentioned. So transfers between the mentioned
* accounts will be removed. * accounts will be removed.
*
* @codeCoverageIgnore
*/ */
class InternalTransferFilter implements FilterInterface class InternalTransferFilter implements FilterInterface
{ {

View File

@ -30,6 +30,8 @@ use Log;
* Class NegativeAmountFilter. * Class NegativeAmountFilter.
* *
* This filter removes entries with a negative amount (the original modifier is -1). * This filter removes entries with a negative amount (the original modifier is -1).
*
* @codeCoverageIgnore
*/ */
class NegativeAmountFilter implements FilterInterface class NegativeAmountFilter implements FilterInterface
{ {

View File

@ -31,6 +31,8 @@ use Log;
* *
* This filter is similar to the internal transfer filter but only removes transactions when the opposing account is * 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). * amongst $parameters (list of account ID's).
*
* @codeCoverageIgnore
*/ */
class OpposingAccountFilter implements FilterInterface class OpposingAccountFilter implements FilterInterface
{ {

View File

@ -33,6 +33,8 @@ use Log;
* *
* This filter removes transactions with either a positive amount ($parameters = 1) or a negative amount * 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. * ($parameter = -1). This is helpful when a Collection has you with both transactions in a journal.
*
* @codeCoverageIgnore
*/ */
class PositiveAmountFilter implements FilterInterface class PositiveAmountFilter implements FilterInterface
{ {

View File

@ -30,6 +30,8 @@ use Illuminate\Support\Collection;
/** /**
* Class SplitIndicatorFilter * Class SplitIndicatorFilter
*
* @codeCoverageIgnore
*/ */
class SplitIndicatorFilter implements FilterInterface class SplitIndicatorFilter implements FilterInterface
{ {

View File

@ -35,6 +35,8 @@ use Log;
* *
* This is used in the mass-edit routine. * This is used in the mass-edit routine.
* *
* @codeCoverageIgnore
*
*/ */
class TransactionViewFilter implements FilterInterface class TransactionViewFilter implements FilterInterface
{ {

View File

@ -30,6 +30,8 @@ use Illuminate\Support\Collection;
* Class TransferFilter. * Class TransferFilter.
* *
* This filter removes any transfers that are in the collection twice (from A to B and from B to A). * 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 class TransferFilter implements FilterInterface
{ {

View File

@ -20,14 +20,16 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace Tests\Unit\Helpers; namespace Tests\Unit\Helpers\Attachments;
use Crypt;
use FireflyIII\Helpers\Attachments\AttachmentHelper; use FireflyIII\Helpers\Attachments\AttachmentHelper;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use Illuminate\Http\UploadedFile; use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Tests\TestCase; use Tests\TestCase;
use Log;
/** /**
* Class AttachmentHelperTest * Class AttachmentHelperTest
@ -38,6 +40,15 @@ use Tests\TestCase;
*/ */
class AttachmentHelperTest extends 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 * @covers \FireflyIII\Helpers\Attachments\AttachmentHelper
*/ */
@ -97,6 +108,45 @@ class AttachmentHelperTest extends TestCase
Storage::disk('upload')->assertExists(sprintf('at-%d.data', $attachments->first()->id)); Storage::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. * Test double file upload. Needs to be after testSave.
* *

View File

@ -20,7 +20,7 @@
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace Tests\Unit\Helpers; namespace Tests\Unit\Helpers\Chart;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Helpers\Chart\MetaPieChart; use FireflyIII\Helpers\Chart\MetaPieChart;
@ -35,6 +35,7 @@ use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Tests\TestCase; use Tests\TestCase;
use Log;
/** /**
* Class MetaPieChartTest * Class MetaPieChartTest
@ -45,6 +46,15 @@ use Tests\TestCase;
*/ */
class MetaPieChartTest extends 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 * @covers \FireflyIII\Helpers\Chart\MetaPieChart
*/ */

View File

@ -0,0 +1,69 @@
<?php
/**
* AmountFilterTest.php
* Copyright (c) 2018 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Tests\Unit\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);
}
}