2018-12-20 13:50:05 -06:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* RecurrenceTransformerTest.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\Factory\CategoryFactory;
|
|
|
|
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
|
|
|
use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;
|
|
|
|
use FireflyIII\Transformers\RecurrenceTransformer;
|
|
|
|
use Log;
|
2019-08-03 03:50:43 -05:00
|
|
|
use Mockery;
|
2018-12-20 13:50:05 -06:00
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Class RecurrenceTransformerTest
|
2019-08-17 03:48:28 -05:00
|
|
|
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
|
|
|
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
2018-12-20 13:50:05 -06:00
|
|
|
*/
|
|
|
|
class RecurrenceTransformerTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
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-20 13:50:05 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-08-03 03:50:43 -05:00
|
|
|
* @covers \FireflyIII\Transformers\RecurrenceTransformer
|
2018-12-20 13:50:05 -06:00
|
|
|
*/
|
|
|
|
public function testBasic(): void
|
|
|
|
{
|
|
|
|
$recurrenceRepos = $this->mock(RecurringRepositoryInterface::class);
|
|
|
|
$billRepos = $this->mock(BillRepositoryInterface::class);
|
|
|
|
$piggyRepos = $this->mock(PiggyBankRepositoryInterface::class);
|
|
|
|
$factory = $this->mock(CategoryFactory::class);
|
|
|
|
$budgetRepos = $this->mock(BudgetRepositoryInterface::class);
|
2019-08-03 03:50:43 -05:00
|
|
|
$category = $this->getRandomCategory();
|
|
|
|
$budget = $this->getRandomBudget();
|
|
|
|
$piggy = $this->getRandomPiggyBank();
|
|
|
|
$bill = $this->getRandomBill();
|
2018-12-20 13:50:05 -06:00
|
|
|
$ranges = [new Carbon];
|
2019-08-03 03:50:43 -05:00
|
|
|
$recurrence = $this->getRandomRecurrence();
|
2018-12-20 13:50:05 -06:00
|
|
|
// mock calls:
|
|
|
|
$recurrenceRepos->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$piggyRepos->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$factory->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
$budgetRepos->shouldReceive('setUser')->atLeast()->once();
|
|
|
|
|
|
|
|
// default calls:
|
|
|
|
$recurrenceRepos->shouldReceive('getNoteText')->once()->andReturn('Hi there');
|
|
|
|
$recurrenceRepos->shouldReceive('repetitionDescription')->once()->andReturn('Rep descr');
|
|
|
|
$recurrenceRepos->shouldReceive('getXOccurrences')->andReturn($ranges)->atLeast()->once();
|
2019-08-03 03:50:43 -05:00
|
|
|
$factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null,Mockery::any()])->andReturn($category);
|
2019-08-03 07:45:37 -05:00
|
|
|
$budgetRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($budget);
|
2019-08-09 11:06:43 -05:00
|
|
|
$piggyRepos->shouldReceive('findNull')->andReturn($piggy);
|
2019-08-03 07:45:37 -05:00
|
|
|
$billRepos->shouldReceive('find')->andReturn($bill);
|
2018-12-20 13:50:05 -06:00
|
|
|
|
|
|
|
// basic transformation:
|
2019-08-03 03:50:43 -05:00
|
|
|
|
2018-12-20 13:50:05 -06:00
|
|
|
$transformer = app(RecurrenceTransformer::class);
|
|
|
|
$transformer->setParameters(new ParameterBag);
|
|
|
|
|
|
|
|
$result = $transformer->transform($recurrence);
|
|
|
|
|
2019-08-03 03:50:43 -05:00
|
|
|
$this->assertEquals($recurrence->id, $result['id']);
|
2019-08-04 04:12:24 -05:00
|
|
|
//$this->assertEquals('deposit', $result['transaction_type']);
|
2018-12-20 13:50:05 -06:00
|
|
|
$this->assertEquals(true, $result['apply_rules']);
|
|
|
|
$this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-12-31 00:48:23 -06:00
|
|
|
}
|