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

78 lines
2.8 KiB
PHP
Raw Normal View History

2018-12-20 20:50:05 +01:00
<?php
/**
* RuleTransformerTest.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
2018-12-20 20:50:05 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-12-20 20:50:05 +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-12-20 20:50:05 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-12-20 20:50:05 +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-12-20 20:50:05 +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-12-20 20:50:05 +01:00
*/
declare(strict_types=1);
namespace Tests\Unit\Transformers;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
use FireflyIII\Transformers\RuleTransformer;
use Illuminate\Support\Collection;
use Symfony\Component\HttpFoundation\ParameterBag;
use Tests\TestCase;
/**
* Class RuleTransformerTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-12-20 20:50:05 +01:00
*/
class RuleTransformerTest extends TestCase
{
/**
* Test basic tag transformer
*
* @covers \FireflyIII\Transformers\RuleTransformer
*/
public function testBasic(): void
{
/** @var Rule $rule */
$rule = Rule::first();
$repository = $this->mock(RuleRepositoryInterface::class);
2018-12-20 20:50:05 +01:00
/** @var RuleTrigger $ruleTrigger */
2019-08-29 17:53:25 +02:00
$ruleTrigger = RuleTrigger::where('trigger_type', '!=', 'user_action')->first();
/** @var RuleTrigger $ruleTrigger */
$moment = RuleTrigger::where('trigger_type', '=', 'user_action')->first();
2018-12-20 20:50:05 +01:00
/** @var RuleAction $ruleAction */
$ruleAction = RuleAction::first();
2018-12-20 20:50:05 +01:00
// mock stuff
$repository->shouldReceive('setUser')->atLeast()->once();
$repository->shouldReceive('getRuleActions')->atLeast()->once()->andReturn(new Collection([$ruleAction]));
2019-08-29 17:53:25 +02:00
$repository->shouldReceive('getRuleTriggers')->atLeast()->once()->andReturn(new Collection([$moment]), new Collection([$ruleTrigger]));
2018-12-20 20:50:05 +01:00
$transformer = app(RuleTransformer::class);
$transformer->setParameters(new ParameterBag);
$result = $transformer->transform($rule);
$this->assertEquals($rule->title, $result['title']);
$this->assertEquals($ruleTrigger->trigger_type, $result['triggers'][0]['type']);
$this->assertEquals($ruleAction->action_type, $result['actions'][0]['type']);
}
}