mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-24 16:10:37 -06:00
tests for bill and attachment transformers.
This commit is contained in:
parent
9cc1bfb4b5
commit
78ba0f749c
@ -53,6 +53,8 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
public function __construct(ParameterBag $parameters)
|
||||
@ -61,6 +63,10 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach the user.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return Item
|
||||
@ -71,6 +77,8 @@ class AttachmentTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform attachment.
|
||||
*
|
||||
* @param Attachment $attachment
|
||||
*
|
||||
* @return array
|
||||
|
@ -58,6 +58,8 @@ class BillTransformer extends TransformerAbstract
|
||||
/**
|
||||
* BillTransformer constructor.
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param ParameterBag $parameters
|
||||
*/
|
||||
public function __construct(ParameterBag $parameters)
|
||||
@ -66,8 +68,11 @@ class BillTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any attachments.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeAttachments(Bill $bill): FractalCollection
|
||||
@ -78,8 +83,11 @@ class BillTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include any transactions.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return FractalCollection
|
||||
*/
|
||||
public function includeTransactions(Bill $bill): FractalCollection
|
||||
@ -102,8 +110,11 @@ class BillTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the user.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return \League\Fractal\Resource\Item
|
||||
*/
|
||||
public function includeUser(Bill $bill): Item
|
||||
@ -112,6 +123,8 @@ class BillTransformer extends TransformerAbstract
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform the bill.
|
||||
*
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return array
|
||||
|
64
tests/Unit/Transformers/AttachmentTransformerTest.php
Normal file
64
tests/Unit/Transformers/AttachmentTransformerTest.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* AttachmentTransformerTest.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\Transformers;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Transformers\AttachmentTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class AttachmentTransformerTest
|
||||
*/
|
||||
class AttachmentTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic transformer
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\AttachmentTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$md5 = md5('hello' . rand(1, 10000));
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'attachable_id' => 1,
|
||||
'attachable_type' => Account::class,
|
||||
'md5' => $md5,
|
||||
'filename' => 'hello.txt',
|
||||
'mime' => 'text/plain',
|
||||
'size' => 101,
|
||||
'uploaded' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
$transformer = new AttachmentTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($attachment);
|
||||
$this->assertEquals($md5, $result['md5']);
|
||||
$this->assertEquals('hello.txt', $result['filename']);
|
||||
}
|
||||
|
||||
}
|
145
tests/Unit/Transformers/BillTransformerTest.php
Normal file
145
tests/Unit/Transformers/BillTransformerTest.php
Normal file
@ -0,0 +1,145 @@
|
||||
<?php
|
||||
/**
|
||||
* BillTransformerTest.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\Transformers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Transformers\BillTransformer;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class BillTransformerTest
|
||||
*/
|
||||
class BillTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Basic coverage
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::transform
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::paidData
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::payDates
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
|
||||
$bill = Bill::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some bill ' . rand(1, 10000),
|
||||
'match' => 'word,' . rand(1, 10000),
|
||||
'amount_min' => 12.34,
|
||||
'amount_max' => 45.67,
|
||||
'date' => '2018-01-02',
|
||||
'repeat_freq' => 'weekly',
|
||||
'skip' => 0,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$transformer = new BillTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($bill);
|
||||
|
||||
$this->assertEquals($bill->name, $result['name']);
|
||||
$this->assertTrue($result['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic coverage with a note.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::transform
|
||||
*/
|
||||
public function testNote()
|
||||
{
|
||||
|
||||
$bill = Bill::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some bill ' . rand(1, 10000),
|
||||
'match' => 'word,' . rand(1, 10000),
|
||||
'amount_min' => 12.34,
|
||||
'amount_max' => 45.67,
|
||||
'date' => '2018-01-02',
|
||||
'repeat_freq' => 'weekly',
|
||||
'skip' => 0,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$noteText = 'I are a note ' . rand(1, 10000);
|
||||
$note = Note::create(
|
||||
[
|
||||
'noteable_id' => $bill->id,
|
||||
'noteable_type' => Bill::class,
|
||||
'text' => $noteText,
|
||||
]
|
||||
);
|
||||
$transformer = new BillTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($bill);
|
||||
|
||||
$this->assertEquals($bill->name, $result['name']);
|
||||
$this->assertEquals($noteText, $result['notes']);
|
||||
$this->assertTrue($result['active']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Coverage for dates.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::transform
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::paidData
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::payDates
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::lastPaidDate
|
||||
* @covers \FireflyIII\Transformers\BillTransformer::nextDateMatch
|
||||
*/
|
||||
public function testWithDates()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->andReturnSelf();
|
||||
$repository->shouldReceive('getPaidDatesInRange')->andReturn(new Collection([new Carbon]));
|
||||
$bill = Bill::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some bill ' . rand(1, 10000),
|
||||
'match' => 'word,' . rand(1, 10000),
|
||||
'amount_min' => 12.34,
|
||||
'amount_max' => 45.67,
|
||||
'date' => '2018-01-02',
|
||||
'repeat_freq' => 'weekly',
|
||||
'skip' => 0,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$parameters = new ParameterBag();
|
||||
$parameters->set('start', new Carbon('2018-01-01'));
|
||||
$parameters->set('end', new Carbon('2018-01-31'));
|
||||
$transformer = new BillTransformer($parameters);
|
||||
$result = $transformer->transform($bill);
|
||||
|
||||
$this->assertEquals($bill->name, $result['name']);
|
||||
$this->assertTrue($result['active']);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user