Files
firefly-iii/tests/Unit/Factory/TransactionFactoryTest.php

179 lines
5.4 KiB
PHP
Raw Normal View History

2018-03-01 20:54:50 +01:00
<?php
/**
* TransactionFactoryTest.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\Factory;
use FireflyIII\Factory\TransactionFactory;
2018-08-24 07:18:33 +02:00
use Log;
2018-03-01 20:54:50 +01:00
use Tests\TestCase;
/**
* Class TransactionFactoryTest
2019-08-17 10:48:28 +02:00
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
2018-03-01 20:54:50 +01:00
*/
class TransactionFactoryTest extends TestCase
{
2018-08-24 07:18:33 +02:00
/**
*
*/
public function setUp(): void
{
parent::setUp();
2019-04-09 20:05:20 +02:00
Log::info(sprintf('Now in %s.', get_class($this)));
2018-08-24 07:18:33 +02:00
}
2018-03-01 20:54:50 +01:00
/**
* @covers \FireflyIII\Factory\TransactionFactory
*/
2019-06-16 13:16:46 +02:00
public function testCreateNegative(): void
2018-03-01 20:54:50 +01:00
{
2019-03-18 16:52:49 +01:00
// data used in calls.
$journal = $this->getRandomWithdrawal();
$account = $this->getRandomAsset();
2019-06-16 13:16:46 +02:00
$euro = $this->getEuro();
2019-03-18 16:52:49 +01:00
$amount = '10';
2018-03-01 20:54:50 +01:00
/** @var TransactionFactory $factory */
$factory = app(TransactionFactory::class);
2019-06-16 13:16:46 +02:00
// set details:
2018-03-01 20:54:50 +01:00
$factory->setUser($this->user());
2019-03-18 16:52:49 +01:00
$factory->setJournal($journal);
2019-06-16 13:16:46 +02:00
$factory->setAccount($account);
$factory->setCurrency($euro);
$factory->setReconciled(false);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
// create negative
$transaction = $factory->createNegative($amount, null);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
$this->assertEquals($transaction->account_id, $account->id);
2019-08-29 17:53:25 +02:00
$this->assertEquals('-10.000000000000', $transaction->amount);
2019-06-16 13:16:46 +02:00
$transaction->forceDelete();
2018-03-01 20:54:50 +01:00
}
2018-08-24 07:18:33 +02:00
/**
* @covers \FireflyIII\Factory\TransactionFactory
*/
2019-06-16 13:16:46 +02:00
public function testCreatePositive(): void
2018-08-24 07:18:33 +02:00
{
2019-03-18 16:52:49 +01:00
// data used in calls.
$journal = $this->getRandomWithdrawal();
2019-06-16 13:16:46 +02:00
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$amount = '10';
2018-08-24 07:18:33 +02:00
/** @var TransactionFactory $factory */
$factory = app(TransactionFactory::class);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
// set details:
2018-03-01 20:54:50 +01:00
$factory->setUser($this->user());
2019-03-18 16:52:49 +01:00
$factory->setJournal($journal);
2019-06-16 13:16:46 +02:00
$factory->setAccount($account);
$factory->setCurrency($euro);
$factory->setReconciled(false);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
// create positive
$transaction = $factory->createPositive($amount, null);
2018-08-24 07:18:33 +02:00
2019-06-16 13:16:46 +02:00
$this->assertEquals($transaction->account_id, $account->id);
$this->assertEquals('10', $transaction->amount);
$transaction->forceDelete();
2019-03-18 16:52:49 +01:00
}
/**
* @covers \FireflyIII\Factory\TransactionFactory
*/
2019-06-16 13:16:46 +02:00
public function testCreateNegativeForeign(): void
2019-03-18 16:52:49 +01:00
{
// data used in calls.
$journal = $this->getRandomWithdrawal();
2019-06-16 13:16:46 +02:00
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$dollar = $this->getDollar();
$amount = '10';
2018-08-24 07:18:33 +02:00
2019-03-18 16:52:49 +01:00
/** @var TransactionFactory $factory */
$factory = app(TransactionFactory::class);
2018-08-24 07:18:33 +02:00
2019-06-16 13:16:46 +02:00
// set details:
2018-08-24 07:18:33 +02:00
$factory->setUser($this->user());
2019-03-18 16:52:49 +01:00
$factory->setJournal($journal);
2019-06-16 13:16:46 +02:00
$factory->setAccount($account);
$factory->setCurrency($euro);
$factory->setForeignCurrency($dollar);
$factory->setReconciled(false);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
// create negative
$transaction = $factory->createNegative($amount, $amount);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
$this->assertEquals($transaction->account_id, $account->id);
2019-08-29 17:53:25 +02:00
$this->assertEquals('-10.000000000000', $transaction->amount);
$this->assertEquals('-10.000000000000', $transaction->foreign_amount);
2019-06-16 13:16:46 +02:00
$this->assertEquals($euro->id, $transaction->transaction_currency_id);
$this->assertEquals($dollar->id, $transaction->foreign_currency_id);
$transaction->forceDelete();
2019-03-18 16:52:49 +01:00
}
/**
* @covers \FireflyIII\Factory\TransactionFactory
*/
2019-06-16 13:16:46 +02:00
public function testCreatePositiveForeign(): void
2019-03-18 16:52:49 +01:00
{
// data used in calls.
$journal = $this->getRandomWithdrawal();
2019-06-16 13:16:46 +02:00
$account = $this->getRandomAsset();
$euro = $this->getEuro();
$dollar = $this->getDollar();
$amount = '10';
2018-08-24 07:18:33 +02:00
2019-03-18 16:52:49 +01:00
/** @var TransactionFactory $factory */
$factory = app(TransactionFactory::class);
2019-06-16 13:16:46 +02:00
// set details:
2018-03-01 20:54:50 +01:00
$factory->setUser($this->user());
2019-06-16 13:16:46 +02:00
$factory->setJournal($journal);
$factory->setAccount($account);
$factory->setCurrency($euro);
$factory->setForeignCurrency($dollar);
$factory->setReconciled(false);
2018-03-01 20:54:50 +01:00
2019-06-16 13:16:46 +02:00
// create positive
$transaction = $factory->createPositive($amount, $amount);
$this->assertEquals($transaction->account_id, $account->id);
$this->assertEquals('10', $transaction->amount);
$this->assertEquals('10', $transaction->foreign_amount);
$this->assertEquals($euro->id, $transaction->transaction_currency_id);
$this->assertEquals($dollar->id, $transaction->foreign_currency_id);
2019-03-18 16:52:49 +01:00
2019-06-16 13:16:46 +02:00
$transaction->forceDelete();
2018-03-01 20:54:50 +01:00
}
2018-03-04 15:14:29 +01:00
}