firefly-iii/tests/Unit/Transformers/CategoryTransformerTest.php

107 lines
3.3 KiB
PHP
Raw Normal View History

2018-02-17 03:47:06 -06:00
<?php
/**
* CategoryTransformerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-02-17 03:47:06 -06:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-02-17 03:47:06 -06: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 03:47:06 -06:00
*
* This program is distributed in the hope that it will be useful,
2018-02-17 03:47:06 -06: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 03:47:06 -06: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 03:47:06 -06:00
*/
declare(strict_types=1);
namespace Tests\Unit\Transformers;
use Carbon\Carbon;
2018-02-17 03:47:06 -06:00
use FireflyIII\Models\Category;
2019-08-29 10:53:25 -05:00
use FireflyIII\Repositories\Category\OperationsRepositoryInterface;
2018-02-17 03:47:06 -06:00
use FireflyIII\Transformers\CategoryTransformer;
use Log;
2018-02-17 03:47:06 -06:00
use Symfony\Component\HttpFoundation\ParameterBag;
2019-08-29 10:53:25 -05:00
use Tests\Support\TestDataTrait;
2018-02-17 03:47:06 -06:00
use Tests\TestCase;
/**
* Class CategoryTransformerTest
2019-08-17 03:48:28 -05:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-02-17 03:47:06 -06:00
*/
class CategoryTransformerTest extends TestCase
{
2019-08-29 10:53:25 -05:00
use TestDataTrait;
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 13:05:20 -05:00
Log::info(sprintf('Now in %s.', get_class($this)));
}
2018-02-17 03:47:06 -06:00
/**
* Basic coverage
*
2018-08-09 13:17:15 -05:00
* @covers \FireflyIII\Transformers\CategoryTransformer
2018-02-17 03:47:06 -06:00
*/
2018-05-11 12:58:10 -05:00
public function testBasic(): void
2018-02-17 03:47:06 -06:00
{
2019-08-29 10:53:25 -05:00
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
$opsRepository->shouldReceive('setUser')->once();
/** @var Category $category */
$category = Category::first();
$transformer = app(CategoryTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($category);
$this->assertEquals($category->name, $result['name']);
$this->assertEquals([], $result['spent']);
$this->assertEquals([], $result['earned']);
}
/**
* Basic coverage
*
* @covers \FireflyIII\Transformers\CategoryTransformer
*/
public function testWithDates(): void
{
2019-08-29 10:53:25 -05:00
$opsRepository = $this->mock(OperationsRepositoryInterface::class);
$opsRepository->shouldReceive('setUser')->once();
$parameters = new ParameterBag;
$parameters->set('start', new Carbon('2018-01-01'));
$parameters->set('end', new Carbon('2018-01-31'));
2019-08-29 10:53:25 -05:00
$income = $this->categorySumIncome();
$expense = $this->categorySumExpenses();
$opsRepository->shouldReceive('sumIncome')
->atLeast()->once()->andReturn($income);
2019-08-29 10:53:25 -05:00
$opsRepository->shouldReceive('sumExpenses')
->atLeast()->once()->andReturn($expense);
/** @var Category $category */
$category = Category::first();
$transformer = app(CategoryTransformer::class);
$transformer->setParameters($parameters);
$result = $transformer->transform($category);
2018-02-17 03:47:06 -06:00
$this->assertEquals($category->name, $result['name']);
}
2018-03-04 08:14:29 -06:00
}