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

@@ -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 TestCase
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.
*

View File

@@ -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
*/

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);
}
}