2018-02-16 15:47:08 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BillTransformerTest.php
|
2019-10-01 23:45:03 -05:00
|
|
|
* Copyright (c) 2019 thegrumpydictator@gmail.com
|
2018-02-16 15:47:08 -06:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-02-16 15:47:08 -06:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2018-02-16 15:47:08 -06:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-02-16 15:47:08 -06:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-01 23:45:03 -05:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-02-16 15:47:08 -06:00
|
|
|
*
|
2019-10-01 23:45:03 -05:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-02-16 15:47:08 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Tests\Unit\Transformers;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Models\Bill;
|
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|
|
|
use FireflyIII\Transformers\BillTransformer;
|
|
|
|
use Illuminate\Support\Collection;
|
2018-12-19 12:02:16 -06:00
|
|
|
use Log;
|
2018-02-16 15:47:08 -06:00
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BillTransformerTest
|
2019-08-17 03:48:28 -05:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2018-02-16 15:47:08 -06:00
|
|
|
*/
|
|
|
|
class BillTransformerTest extends TestCase
|
|
|
|
{
|
2018-12-19 12:02:16 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2019-04-09 13:05:20 -05:00
|
|
|
Log::info(sprintf('Now in %s.', get_class($this)));
|
2018-12-19 12:02:16 -06:00
|
|
|
}
|
|
|
|
|
2018-02-16 15:47:08 -06:00
|
|
|
/**
|
|
|
|
* Basic coverage
|
|
|
|
*
|
2018-08-09 13:17:15 -05:00
|
|
|
* @covers \FireflyIII\Transformers\BillTransformer
|
2018-02-16 15:47:08 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testBasic(): void
|
2018-02-16 15:47:08 -06:00
|
|
|
{
|
2018-12-18 23:06:01 -06:00
|
|
|
$repository = $this->mock(BillRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('');
|
2018-02-16 15:47:08 -06:00
|
|
|
|
|
|
|
|
2018-12-18 23:06:01 -06:00
|
|
|
/** @var Bill $bill */
|
|
|
|
$bill = Bill::first();
|
|
|
|
$transformer = app(BillTransformer::class);
|
|
|
|
$transformer->setParameters(new ParameterBag);
|
|
|
|
$result = $transformer->transform($bill);
|
|
|
|
|
|
|
|
// assert fields.
|
2018-02-16 15:47:08 -06:00
|
|
|
$this->assertEquals($bill->name, $result['name']);
|
2018-12-18 23:06:01 -06:00
|
|
|
$this->assertEquals($bill->transactionCurrency->decimal_places, $result['currency_decimal_places']);
|
|
|
|
$this->assertEquals($bill->active, $result['active']);
|
|
|
|
$this->assertNull($result['notes']);
|
2018-02-16 15:47:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-12-18 23:06:01 -06:00
|
|
|
* Basic coverage
|
2018-02-16 15:47:08 -06:00
|
|
|
*
|
2018-08-09 13:17:15 -05:00
|
|
|
* @covers \FireflyIII\Transformers\BillTransformer
|
2018-02-16 15:47:08 -06:00
|
|
|
*/
|
2018-05-11 12:58:10 -05:00
|
|
|
public function testWithDates(): void
|
2018-02-16 15:47:08 -06:00
|
|
|
{
|
|
|
|
$repository = $this->mock(BillRepositoryInterface::class);
|
2018-12-18 23:06:01 -06:00
|
|
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$repository->shouldReceive('getNoteText')->atLeast()->once()->andReturn('');
|
|
|
|
|
|
|
|
// repos should also receive call for dates:
|
|
|
|
$list = new Collection(
|
2019-08-23 02:41:31 -05:00
|
|
|
[
|
|
|
|
(object)['date' => new Carbon('2018-01-02'), 'id' => 1, 'transaction_group_id' => 1,],
|
|
|
|
(object)['date' => new Carbon('2018-01-09'), 'id' => 1, 'transaction_group_id' => 1,],
|
|
|
|
(object)['date' => new Carbon('2018-01-16'), 'id' => 1, 'transaction_group_id' => 1,],
|
|
|
|
(object)['date' => new Carbon('2018-01-21'), 'id' => 1, 'transaction_group_id' => 1,],
|
|
|
|
(object)['date' => new Carbon('2018-01-30'), 'id' => 1, 'transaction_group_id' => 1,],
|
2018-02-16 15:47:08 -06:00
|
|
|
]
|
|
|
|
);
|
2018-12-18 23:06:01 -06:00
|
|
|
$repository->shouldReceive('getPaidDatesInRange')->atLeast()->once()->andReturn($list);
|
|
|
|
|
|
|
|
$parameters = new ParameterBag;
|
2018-02-16 15:47:08 -06:00
|
|
|
$parameters->set('start', new Carbon('2018-01-01'));
|
|
|
|
$parameters->set('end', new Carbon('2018-01-31'));
|
|
|
|
|
2018-12-18 23:06:01 -06:00
|
|
|
/** @var Bill $bill */
|
|
|
|
$bill = Bill::first();
|
|
|
|
$transformer = app(BillTransformer::class);
|
|
|
|
$transformer->setParameters($parameters);
|
|
|
|
$result = $transformer->transform($bill);
|
|
|
|
|
|
|
|
// assert fields.
|
2018-02-16 15:47:08 -06:00
|
|
|
$this->assertEquals($bill->name, $result['name']);
|
2018-12-18 23:06:01 -06:00
|
|
|
$this->assertEquals($bill->transactionCurrency->decimal_places, $result['currency_decimal_places']);
|
|
|
|
$this->assertEquals($bill->active, $result['active']);
|
|
|
|
$this->assertNull($result['notes']);
|
|
|
|
|
|
|
|
$this->assertEquals('2018-03-01', $result['next_expected_match']);
|
2020-01-05 12:29:28 -06:00
|
|
|
//$this->assertEquals(['2018-01-01'], $result['pay_dates']);
|
|
|
|
$this->assertEquals(['2019-11-01'], $result['pay_dates']);
|
2019-08-23 02:41:31 -05:00
|
|
|
$this->assertEquals(
|
|
|
|
[
|
|
|
|
['date' => '2018-01-02', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
2020-01-05 12:29:28 -06:00
|
|
|
// ['date' => '2019-11-01', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
2019-08-23 02:41:31 -05:00
|
|
|
['date' => '2018-01-09', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
|
|
|
['date' => '2018-01-16', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
|
|
|
['date' => '2018-01-21', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
|
|
|
['date' => '2018-01-30', 'transaction_group_id' => 1, 'transaction_journal_id' => 1,],
|
|
|
|
], $result['paid_dates']
|
|
|
|
);
|
2018-02-16 15:47:08 -06:00
|
|
|
}
|
|
|
|
|
2018-03-04 08:14:29 -06:00
|
|
|
}
|