mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Improve transformer coverage.
This commit is contained in:
@@ -160,6 +160,26 @@ class RuleRepository implements RuleRepositoryInterface
|
|||||||
return $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
|
return $rule->ruleTriggers()->where('trigger_type', 'user_action')->first()->trigger_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getRuleActions(Rule $rule): Collection
|
||||||
|
{
|
||||||
|
return $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getRuleTriggers(Rule $rule): Collection
|
||||||
|
{
|
||||||
|
return $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Rule $rule
|
* @param Rule $rule
|
||||||
*
|
*
|
||||||
|
@@ -34,6 +34,20 @@ use Illuminate\Support\Collection;
|
|||||||
*/
|
*/
|
||||||
interface RuleRepositoryInterface
|
interface RuleRepositoryInterface
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getRuleActions(Rule $rule): Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Rule $rule
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getRuleTriggers(Rule $rule): Collection;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
|
@@ -38,6 +38,7 @@ class PreferenceTransformer extends AbstractTransformer
|
|||||||
/**
|
/**
|
||||||
* PreferenceTransformer constructor.
|
* PreferenceTransformer constructor.
|
||||||
*
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@@ -44,15 +44,30 @@ use Log;
|
|||||||
*/
|
*/
|
||||||
class RecurrenceTransformer extends AbstractTransformer
|
class RecurrenceTransformer extends AbstractTransformer
|
||||||
{
|
{
|
||||||
|
/** @var BillRepositoryInterface */
|
||||||
|
private $billRepos;
|
||||||
|
/** @var BudgetRepositoryInterface */
|
||||||
|
private $budgetRepos;
|
||||||
|
/** @var CategoryFactory */
|
||||||
|
private $factory;
|
||||||
|
/** @var PiggyBankRepositoryInterface */
|
||||||
|
private $piggyRepos;
|
||||||
/** @var RecurringRepositoryInterface */
|
/** @var RecurringRepositoryInterface */
|
||||||
protected $repository;
|
private $repository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RecurrenceTransformer constructor.
|
* RecurrenceTransformer constructor.
|
||||||
|
*
|
||||||
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->repository = app(RecurringRepositoryInterface::class);
|
$this->repository = app(RecurringRepositoryInterface::class);
|
||||||
|
$this->billRepos = app(BillRepositoryInterface::class);
|
||||||
|
$this->piggyRepos = app(PiggyBankRepositoryInterface::class);
|
||||||
|
$this->factory = app(CategoryFactory::class);
|
||||||
|
$this->budgetRepos = app(BudgetRepositoryInterface::class);
|
||||||
|
|
||||||
if ('testing' === config('app.env')) {
|
if ('testing' === config('app.env')) {
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
||||||
}
|
}
|
||||||
@@ -68,7 +83,14 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function transform(Recurrence $recurrence): array
|
public function transform(Recurrence $recurrence): array
|
||||||
{
|
{
|
||||||
|
Log::debug('Now in Recurrence::transform()');
|
||||||
$this->repository->setUser($recurrence->user);
|
$this->repository->setUser($recurrence->user);
|
||||||
|
$this->billRepos->setUser($recurrence->user);
|
||||||
|
$this->piggyRepos->setUser($recurrence->user);
|
||||||
|
$this->factory->setUser($recurrence->user);
|
||||||
|
$this->budgetRepos->setUser($recurrence->user);
|
||||||
|
|
||||||
|
$shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type));
|
||||||
|
|
||||||
// basic data.
|
// basic data.
|
||||||
$return = [
|
$return = [
|
||||||
@@ -76,7 +98,7 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
'created_at' => $recurrence->created_at->toAtomString(),
|
'created_at' => $recurrence->created_at->toAtomString(),
|
||||||
'updated_at' => $recurrence->updated_at->toAtomString(),
|
'updated_at' => $recurrence->updated_at->toAtomString(),
|
||||||
'transaction_type_id' => $recurrence->transaction_type_id,
|
'transaction_type_id' => $recurrence->transaction_type_id,
|
||||||
'transaction_type' => $recurrence->transactionType->type,
|
'transaction_type' => $shortType,
|
||||||
'title' => $recurrence->title,
|
'title' => $recurrence->title,
|
||||||
'description' => $recurrence->description,
|
'description' => $recurrence->description,
|
||||||
'first_date' => $recurrence->first_date->format('Y-m-d'),
|
'first_date' => $recurrence->first_date->format('Y-m-d'),
|
||||||
@@ -109,34 +131,28 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
private function getMeta(Recurrence $recurrence): array
|
private function getMeta(Recurrence $recurrence): array
|
||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
|
$collection = $recurrence->recurrenceMeta;
|
||||||
|
Log::debug(sprintf('Meta collection length = %d', $collection->count()));
|
||||||
/** @var RecurrenceMeta $recurrenceMeta */
|
/** @var RecurrenceMeta $recurrenceMeta */
|
||||||
foreach ($recurrence->recurrenceMeta as $recurrenceMeta) {
|
foreach ($collection as $recurrenceMeta) {
|
||||||
$recurrenceMetaArray = [
|
$recurrenceMetaArray = [
|
||||||
'name' => $recurrenceMeta->name,
|
'name' => $recurrenceMeta->name,
|
||||||
'value' => $recurrenceMeta->value,
|
'value' => $recurrenceMeta->value,
|
||||||
];
|
];
|
||||||
switch ($recurrenceMeta->name) {
|
switch ($recurrenceMeta->name) {
|
||||||
default:
|
|
||||||
throw new FireflyException(sprintf('Recurrence transformer cannot handle meta-field "%s"', $recurrenceMeta->name));
|
|
||||||
case 'tags':
|
case 'tags':
|
||||||
$recurrenceMetaArray['tags'] = explode(',', $recurrenceMeta->value);
|
$recurrenceMetaArray['tags'] = explode(',', $recurrenceMeta->value);
|
||||||
break;
|
break;
|
||||||
case 'notes':
|
|
||||||
break;
|
|
||||||
case 'bill_id':
|
case 'bill_id':
|
||||||
/** @var BillRepositoryInterface $repository */
|
$bill = $this->billRepos->find((int)$recurrenceMeta->value);
|
||||||
$repository = app(BillRepositoryInterface::class);
|
|
||||||
$bill = $repository->find((int)$recurrenceMeta->value);
|
|
||||||
if (null !== $bill) {
|
if (null !== $bill) {
|
||||||
$recurrenceMetaArray['bill_id'] = $bill->id;
|
$recurrenceMetaArray['bill_id'] = $bill->id;
|
||||||
$recurrenceMetaArray['bill_name'] = $bill->name;
|
$recurrenceMetaArray['bill_name'] = $bill->name;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'piggy_bank_id':
|
case 'piggy_bank_id':
|
||||||
/** @var PiggyBankRepositoryInterface $repository */
|
$piggy = $this->piggyRepos->findNull((int)$recurrenceMeta->value);
|
||||||
$repository = app(PiggyBankRepositoryInterface::class);
|
|
||||||
$piggy = $repository->findNull((int)$recurrenceMeta->value);
|
|
||||||
if (null !== $piggy) {
|
if (null !== $piggy) {
|
||||||
$recurrenceMetaArray['piggy_bank_id'] = $piggy->id;
|
$recurrenceMetaArray['piggy_bank_id'] = $piggy->id;
|
||||||
$recurrenceMetaArray['piggy_bank_name'] = $piggy->name;
|
$recurrenceMetaArray['piggy_bank_name'] = $piggy->name;
|
||||||
@@ -208,22 +224,15 @@ class RecurrenceTransformer extends AbstractTransformer
|
|||||||
'value' => $transactionMeta->value,
|
'value' => $transactionMeta->value,
|
||||||
];
|
];
|
||||||
switch ($transactionMeta->name) {
|
switch ($transactionMeta->name) {
|
||||||
default:
|
|
||||||
throw new FireflyException(sprintf('Recurrence transformer cannot handle transaction meta-field "%s"', $transactionMeta->name));
|
|
||||||
case 'category_name':
|
case 'category_name':
|
||||||
/** @var CategoryFactory $factory */
|
$category = $this->factory->findOrCreate(null, $transactionMeta->value);
|
||||||
$factory = app(CategoryFactory::class);
|
|
||||||
$factory->setUser($transaction->recurrence->user);
|
|
||||||
$category = $factory->findOrCreate(null, $transactionMeta->value);
|
|
||||||
if (null !== $category) {
|
if (null !== $category) {
|
||||||
$transactionMetaArray['category_id'] = $category->id;
|
$transactionMetaArray['category_id'] = $category->id;
|
||||||
$transactionMetaArray['category_name'] = $category->name;
|
$transactionMetaArray['category_name'] = $category->name;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'budget_id':
|
case 'budget_id':
|
||||||
/** @var BudgetRepositoryInterface $repository */
|
$budget = $this->budgetRepos->findNull((int)$transactionMeta->value);
|
||||||
$repository = app(BudgetRepositoryInterface::class);
|
|
||||||
$budget = $repository->findNull((int)$transactionMeta->value);
|
|
||||||
if (null !== $budget) {
|
if (null !== $budget) {
|
||||||
$transactionMetaArray['budget_id'] = $budget->id;
|
$transactionMetaArray['budget_id'] = $budget->id;
|
||||||
$transactionMetaArray['budget_name'] = $budget->name;
|
$transactionMetaArray['budget_name'] = $budget->name;
|
||||||
|
@@ -1,84 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* RuleActionTransformer.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 FireflyIII\Transformers;
|
|
||||||
|
|
||||||
|
|
||||||
use FireflyIII\Models\RuleAction;
|
|
||||||
use League\Fractal\TransformerAbstract;
|
|
||||||
use Log;
|
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class RuleActionTransformer
|
|
||||||
*/
|
|
||||||
class RuleActionTransformer extends TransformerAbstract
|
|
||||||
{
|
|
||||||
|
|
||||||
/** @var ParameterBag */
|
|
||||||
protected $parameters;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CurrencyTransformer constructor.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @param ParameterBag $parameters
|
|
||||||
*/
|
|
||||||
public function __construct(ParameterBag $parameters)
|
|
||||||
{
|
|
||||||
$this->parameters = $parameters;
|
|
||||||
if ('testing' === config('app.env')) {
|
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the rule action.
|
|
||||||
*
|
|
||||||
* @param RuleAction $ruleAction
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(RuleAction $ruleAction): array
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
'id' => (int)$ruleAction->id,
|
|
||||||
'created_at' => $ruleAction->created_at->toAtomString(),
|
|
||||||
'updated_at' => $ruleAction->updated_at->toAtomString(),
|
|
||||||
'type' => $ruleAction->action_type,
|
|
||||||
'value' => $ruleAction->action_value,
|
|
||||||
'order' => $ruleAction->order,
|
|
||||||
'active' => $ruleAction->active,
|
|
||||||
'stop_processing' => $ruleAction->stop_processing,
|
|
||||||
'links' => [
|
|
||||||
[
|
|
||||||
'rel' => 'self',
|
|
||||||
'uri' => '/rule_triggers/' . $ruleAction->id,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -34,7 +34,7 @@ use Symfony\Component\HttpFoundation\ParameterBag;
|
|||||||
class RuleGroupTransformer extends AbstractTransformer
|
class RuleGroupTransformer extends AbstractTransformer
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* CurrencyTransformer constructor.
|
* RuleGroupTransformer constructor.
|
||||||
*
|
*
|
||||||
* @codeCoverageIgnore
|
* @codeCoverageIgnore
|
||||||
*/
|
*/
|
||||||
|
@@ -27,15 +27,17 @@ namespace FireflyIII\Transformers;
|
|||||||
use FireflyIII\Models\Rule;
|
use FireflyIII\Models\Rule;
|
||||||
use FireflyIII\Models\RuleAction;
|
use FireflyIII\Models\RuleAction;
|
||||||
use FireflyIII\Models\RuleTrigger;
|
use FireflyIII\Models\RuleTrigger;
|
||||||
use League\Fractal\TransformerAbstract;
|
use FireflyIII\Repositories\Rule\RuleRepositoryInterface;
|
||||||
use Log;
|
use Log;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class RuleTransformer
|
* Class RuleTransformer
|
||||||
*/
|
*/
|
||||||
class RuleTransformer extends AbstractTransformer
|
class RuleTransformer extends AbstractTransformer
|
||||||
{
|
{
|
||||||
|
/** @var RuleRepositoryInterface */
|
||||||
|
private $ruleRepository;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CurrencyTransformer constructor.
|
* CurrencyTransformer constructor.
|
||||||
*
|
*
|
||||||
@@ -43,6 +45,7 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
$this->ruleRepository = app(RuleRepositoryInterface::class);
|
||||||
if ('testing' === config('app.env')) {
|
if ('testing' === config('app.env')) {
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
||||||
}
|
}
|
||||||
@@ -57,6 +60,8 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
*/
|
*/
|
||||||
public function transform(Rule $rule): array
|
public function transform(Rule $rule): array
|
||||||
{
|
{
|
||||||
|
$this->ruleRepository->setUser($rule->user);
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'id' => (int)$rule->id,
|
'id' => (int)$rule->id,
|
||||||
'created_at' => $rule->created_at->toAtomString(),
|
'created_at' => $rule->created_at->toAtomString(),
|
||||||
@@ -89,7 +94,7 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
private function actions(Rule $rule): array
|
private function actions(Rule $rule): array
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
$actions = $rule->ruleActions()->orderBy('order', 'ASC')->get();
|
$actions = $this->ruleRepository->getRuleActions($rule);
|
||||||
/** @var RuleAction $ruleAction */
|
/** @var RuleAction $ruleAction */
|
||||||
foreach ($actions as $ruleAction) {
|
foreach ($actions as $ruleAction) {
|
||||||
$result[] = [
|
$result[] = [
|
||||||
@@ -115,7 +120,7 @@ class RuleTransformer extends AbstractTransformer
|
|||||||
private function triggers(Rule $rule): array
|
private function triggers(Rule $rule): array
|
||||||
{
|
{
|
||||||
$result = [];
|
$result = [];
|
||||||
$triggers = $rule->ruleTriggers()->orderBy('order', 'ASC')->get();
|
$triggers = $this->ruleRepository->getRuleTriggers($rule);
|
||||||
/** @var RuleTrigger $ruleTrigger */
|
/** @var RuleTrigger $ruleTrigger */
|
||||||
foreach ($triggers as $ruleTrigger) {
|
foreach ($triggers as $ruleTrigger) {
|
||||||
$result[] = [
|
$result[] = [
|
||||||
|
@@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
/**
|
|
||||||
* RuleTriggerTransformer.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 FireflyIII\Transformers;
|
|
||||||
|
|
||||||
|
|
||||||
use FireflyIII\Models\RuleTrigger;
|
|
||||||
use League\Fractal\TransformerAbstract;
|
|
||||||
use Log;
|
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class RuleTriggerTransformer
|
|
||||||
*/
|
|
||||||
class RuleTriggerTransformer extends TransformerAbstract
|
|
||||||
{
|
|
||||||
/** @var ParameterBag */
|
|
||||||
protected $parameters;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* CurrencyTransformer constructor.
|
|
||||||
*
|
|
||||||
* @codeCoverageIgnore
|
|
||||||
*
|
|
||||||
* @param ParameterBag $parameters
|
|
||||||
*/
|
|
||||||
public function __construct(ParameterBag $parameters)
|
|
||||||
{
|
|
||||||
$this->parameters = $parameters;
|
|
||||||
if ('testing' === config('app.env')) {
|
|
||||||
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transform the rule trigger.
|
|
||||||
*
|
|
||||||
* @param RuleTrigger $ruleTrigger
|
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public function transform(RuleTrigger $ruleTrigger): array
|
|
||||||
{
|
|
||||||
$data = [
|
|
||||||
'id' => (int)$ruleTrigger->id,
|
|
||||||
'created_at' => $ruleTrigger->created_at->toAtomString(),
|
|
||||||
'updated_at' => $ruleTrigger->updated_at->toAtomString(),
|
|
||||||
'type' => $ruleTrigger->trigger_type,
|
|
||||||
'value' => $ruleTrigger->trigger_value,
|
|
||||||
'order' => $ruleTrigger->order,
|
|
||||||
'active' => $ruleTrigger->active,
|
|
||||||
'stop_processing' => $ruleTrigger->stop_processing,
|
|
||||||
'links' => [
|
|
||||||
[
|
|
||||||
'rel' => 'self',
|
|
||||||
'uri' => '/rule_triggers/' . $ruleTrigger->id,
|
|
||||||
],
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -289,6 +289,13 @@ return [
|
|||||||
'transfer' => ['Transfer'],
|
'transfer' => ['Transfer'],
|
||||||
'transfers' => ['Transfer'],
|
'transfers' => ['Transfer'],
|
||||||
],
|
],
|
||||||
|
'transactionTypesToShort' => [
|
||||||
|
'Withdrawal' => 'withdrawal',
|
||||||
|
'Deposit' => 'deposit',
|
||||||
|
'Transfer' => 'transfer',
|
||||||
|
'Opening balance' => 'opening-balance',
|
||||||
|
'Reconciliation' => 'reconciliation',
|
||||||
|
],
|
||||||
'transactionIconsByWhat' => [
|
'transactionIconsByWhat' => [
|
||||||
'expenses' => 'fa-long-arrow-left',
|
'expenses' => 'fa-long-arrow-left',
|
||||||
'withdrawal' => 'fa-long-arrow-left',
|
'withdrawal' => 'fa-long-arrow-left',
|
||||||
|
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Transformers\PiggyBankEventTransformer;
|
use FireflyIII\Transformers\PiggyBankEventTransformer;
|
||||||
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -39,6 +40,14 @@ use Tests\TestCase;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankEventTransformerTest extends TestCase
|
class PiggyBankEventTransformerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::info(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Basic test with no meta data.
|
* Basic test with no meta data.
|
||||||
*
|
*
|
||||||
|
@@ -29,6 +29,7 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|||||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||||
|
use Log;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
@@ -39,6 +40,15 @@ use Amount;
|
|||||||
*/
|
*/
|
||||||
class PiggyBankTransformerTest extends TestCase
|
class PiggyBankTransformerTest extends TestCase
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::info(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test basic transformer.
|
* Test basic transformer.
|
||||||
*
|
*
|
||||||
|
64
tests/Unit/Transformers/PreferenceTransformerTest.php
Normal file
64
tests/Unit/Transformers/PreferenceTransformerTest.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* PreferenceTransformerTest.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 FireflyIII\Models\Preference;
|
||||||
|
use FireflyIII\Transformers\PreferenceTransformer;
|
||||||
|
use Log;
|
||||||
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PreferenceTransformerTest
|
||||||
|
*/
|
||||||
|
class PreferenceTransformerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::info(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test basic tag transformer
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Transformers\PreferenceTransformer
|
||||||
|
*/
|
||||||
|
public function testBasic(): void
|
||||||
|
{
|
||||||
|
/** @var Preference $preference */
|
||||||
|
$preference = Preference::first();
|
||||||
|
$transformer = app(PreferenceTransformer::class);
|
||||||
|
$transformer->setParameters(new ParameterBag);
|
||||||
|
|
||||||
|
$result = $transformer->transform($preference);
|
||||||
|
|
||||||
|
$this->assertEquals($preference->name, $result['name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
131
tests/Unit/Transformers/RecurrenceTransformerTest.php
Normal file
131
tests/Unit/Transformers/RecurrenceTransformerTest.php
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
<?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\Models\Bill;
|
||||||
|
use FireflyIII\Models\Budget;
|
||||||
|
use FireflyIII\Models\Category;
|
||||||
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
use FireflyIII\Models\Recurrence;
|
||||||
|
use FireflyIII\Models\TransactionCurrency;
|
||||||
|
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;
|
||||||
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Class RecurrenceTransformerTest
|
||||||
|
*/
|
||||||
|
class RecurrenceTransformerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
Log::info(sprintf('Now in %s.', \get_class($this)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
$category = Category::first();
|
||||||
|
$budget = Budget::first();
|
||||||
|
$piggy = PiggyBank::first();
|
||||||
|
$bill = Bill::first();
|
||||||
|
$foreignCurrency = TransactionCurrency::find(2);
|
||||||
|
$ranges = [new Carbon];
|
||||||
|
// 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();
|
||||||
|
$factory->shouldReceive('findOrCreate')->atLeast()->once()->withArgs([null, 'House'])->andReturn($category);
|
||||||
|
$budgetRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([2])->andReturn($budget);
|
||||||
|
$piggyRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([1])->andReturn($piggy);
|
||||||
|
$billRepos->shouldReceive('find')->atLeast()->once()->withArgs([1])->andReturn($bill);
|
||||||
|
|
||||||
|
// basic transformation:
|
||||||
|
/** @var Recurrence $recurrence */
|
||||||
|
$recurrence = Recurrence::find(1);
|
||||||
|
$transformer = app(RecurrenceTransformer::class);
|
||||||
|
$transformer->setParameters(new ParameterBag);
|
||||||
|
|
||||||
|
$result = $transformer->transform($recurrence);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $result['id']);
|
||||||
|
$this->assertEquals('withdrawal', $result['transaction_type']);
|
||||||
|
$this->assertEquals(true, $result['apply_rules']);
|
||||||
|
$this->assertEquals(
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'value' => 'auto-generated',
|
||||||
|
'tags' => ['auto-generated'],
|
||||||
|
'name' => 'tags',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => 'piggy_bank_id',
|
||||||
|
'piggy_bank_id' => 1,
|
||||||
|
'piggy_bank_name' => 'New camera',
|
||||||
|
'value' => '1',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'bill_id' => 1,
|
||||||
|
'bill_name' => 'Rent',
|
||||||
|
'name' => 'bill_id',
|
||||||
|
'value' => '1',
|
||||||
|
|
||||||
|
],
|
||||||
|
]
|
||||||
|
, $result['meta']
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($foreignCurrency->code, $result['transactions'][0]['foreign_currency_code']);
|
||||||
|
$this->assertEquals('Rep descr', $result['recurrence_repetitions'][0]['description']);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
54
tests/Unit/Transformers/RuleGroupTransformerTest.php
Normal file
54
tests/Unit/Transformers/RuleGroupTransformerTest.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* RuleGroupTransformerTest.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 FireflyIII\Models\RuleGroup;
|
||||||
|
use FireflyIII\Transformers\RuleGroupTransformer;
|
||||||
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RuleGroupTransformerTest
|
||||||
|
*/
|
||||||
|
class RuleGroupTransformerTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test basic tag transformer
|
||||||
|
*
|
||||||
|
* @covers \FireflyIII\Transformers\RuleGroupTransformer
|
||||||
|
*/
|
||||||
|
public function testBasic(): void
|
||||||
|
{
|
||||||
|
/** @var RuleGroup $ruleGroup */
|
||||||
|
$ruleGroup = RuleGroup::first();
|
||||||
|
|
||||||
|
|
||||||
|
$transformer = app(RuleGroupTransformer::class);
|
||||||
|
$transformer->setParameters(new ParameterBag);
|
||||||
|
$result = $transformer->transform($ruleGroup);
|
||||||
|
$this->assertEquals($ruleGroup->title, $result['title']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
70
tests/Unit/Transformers/RuleTransformerTest.php
Normal file
70
tests/Unit/Transformers/RuleTransformerTest.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* RuleTransformerTest.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 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
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
/** @var RuleTrigger $ruleTrigger */
|
||||||
|
$ruleTrigger = RuleTrigger::first();
|
||||||
|
/** @var RuleAction $ruleAction */
|
||||||
|
$ruleAction = RuleAction::first();
|
||||||
|
// mock stuff
|
||||||
|
$repository->shouldReceive('setUser')->atLeast()->once();
|
||||||
|
$repository->shouldReceive('getRuleActions')->atLeast()->once()->andReturn(new Collection([$ruleAction]));
|
||||||
|
$repository->shouldReceive('getRuleTriggers')->atLeast()->once()->andReturn(new Collection([$ruleTrigger]));
|
||||||
|
|
||||||
|
$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']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user