Files
firefly-iii/tests/Unit/Transformers/BudgetTransformerTest.php

122 lines
3.5 KiB
PHP
Raw Normal View History

2018-02-17 10:47:06 +01:00
<?php
/**
* BudgetTransformerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-02-17 10:47:06 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-02-17 10:47:06 +01: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-17 10:47:06 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-02-17 10:47:06 +01:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-02-17 10:47:06 +01: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-17 10:47:06 +01:00
*/
declare(strict_types=1);
namespace Tests\Unit\Transformers;
use Carbon\Carbon;
2018-02-17 10:47:06 +01:00
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
2018-02-17 10:47:06 +01:00
use FireflyIII\Transformers\BudgetTransformer;
use Log;
2018-02-17 10:47:06 +01:00
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
/**
* Class BudgetTransformerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-02-17 10:47:06 +01:00
*/
class BudgetTransformerTest extends TestCase
{
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
2018-02-17 10:47:06 +01:00
/**
* Basic coverage
*
2018-08-09 20:17:15 +02:00
* @covers \FireflyIII\Transformers\BudgetTransformer
2018-02-17 10:47:06 +01:00
*/
2018-05-11 19:58:10 +02:00
public function testBasic(): void
2018-02-17 10:47:06 +01:00
{
// mocks and prep:
$repository = $this->mock(BudgetRepositoryInterface::class);
$parameters = new ParameterBag;
$budget = Budget::first();
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($parameters);
// mocks
$repository->shouldReceive('setUser')->once();
// action
$result = $transformer->transform($budget);
$this->assertEquals($budget->id, $result['id']);
$this->assertEquals((bool)$budget->active, $result['active']);
$this->assertEquals([], $result['spent']);
}
/**
* Basic coverage
*
* @covers \FireflyIII\Transformers\BudgetTransformer
*/
public function testSpentArray(): void
{
// mocks and prep:
$repository = $this->mock(BudgetRepositoryInterface::class);
$parameters = new ParameterBag;
2018-02-17 10:47:06 +01:00
// set parameters
$parameters->set('start', new Carbon('2018-01-01'));
$parameters->set('end', new Carbon('2018-01-31'));
$budget = Budget::first();
$transformer = app(BudgetTransformer::class);
$transformer->setParameters($parameters);
// spent data
$spent = [
2018-02-17 10:47:06 +01:00
[
'currency_id' => 1,
'currency_code' => 'AKC',
'currency_symbol' => 'x',
'currency_decimal_places' => 2,
'amount' => 1000,
],
];
// mocks
$repository->shouldReceive('setUser')->once();
$repository->shouldReceive('spentInPeriodMc')->atLeast()->once()->andReturn($spent);
// action
$result = $transformer->transform($budget);
$this->assertEquals($budget->id, $result['id']);
$this->assertEquals((bool)$budget->active, $result['active']);
$this->assertEquals($spent, $result['spent']);
2018-02-17 10:47:06 +01:00
}
2018-03-04 15:14:29 +01:00
}