. */ declare(strict_types=1); namespace Tests\Unit\Factory; use FireflyIII\Factory\TransactionFactory; use Log; use Tests\TestCase; /** * Class TransactionFactoryTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class TransactionFactoryTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Factory\TransactionFactory */ public function testCreateNegative(): void { // data used in calls. $journal = $this->getRandomWithdrawal(); $account = $this->getRandomAsset(); $euro = $this->getEuro(); $amount = '10'; /** @var TransactionFactory $factory */ $factory = app(TransactionFactory::class); // set details: $factory->setUser($this->user()); $factory->setJournal($journal); $factory->setAccount($account); $factory->setCurrency($euro); $factory->setReconciled(false); // create negative $transaction = $factory->createNegative($amount, null); $this->assertEquals($transaction->account_id, $account->id); $this->assertEquals('-10.000000000000', $transaction->amount); $transaction->forceDelete(); } /** * @covers \FireflyIII\Factory\TransactionFactory */ public function testCreatePositive(): void { // data used in calls. $journal = $this->getRandomWithdrawal(); $account = $this->getRandomAsset(); $euro = $this->getEuro(); $amount = '10'; /** @var TransactionFactory $factory */ $factory = app(TransactionFactory::class); // set details: $factory->setUser($this->user()); $factory->setJournal($journal); $factory->setAccount($account); $factory->setCurrency($euro); $factory->setReconciled(false); // create positive $transaction = $factory->createPositive($amount, null); $this->assertEquals($transaction->account_id, $account->id); $this->assertEquals('10', $transaction->amount); $transaction->forceDelete(); } /** * @covers \FireflyIII\Factory\TransactionFactory */ public function testCreateNegativeForeign(): void { // data used in calls. $journal = $this->getRandomWithdrawal(); $account = $this->getRandomAsset(); $euro = $this->getEuro(); $dollar = $this->getDollar(); $amount = '10'; /** @var TransactionFactory $factory */ $factory = app(TransactionFactory::class); // set details: $factory->setUser($this->user()); $factory->setJournal($journal); $factory->setAccount($account); $factory->setCurrency($euro); $factory->setForeignCurrency($dollar); $factory->setReconciled(false); // create negative $transaction = $factory->createNegative($amount, $amount); $this->assertEquals($transaction->account_id, $account->id); $this->assertEquals('-10.000000000000', $transaction->amount); $this->assertEquals('-10.000000000000', $transaction->foreign_amount); $this->assertEquals($euro->id, $transaction->transaction_currency_id); $this->assertEquals($dollar->id, $transaction->foreign_currency_id); $transaction->forceDelete(); } /** * @covers \FireflyIII\Factory\TransactionFactory */ public function testCreatePositiveForeign(): void { // data used in calls. $journal = $this->getRandomWithdrawal(); $account = $this->getRandomAsset(); $euro = $this->getEuro(); $dollar = $this->getDollar(); $amount = '10'; /** @var TransactionFactory $factory */ $factory = app(TransactionFactory::class); // set details: $factory->setUser($this->user()); $factory->setJournal($journal); $factory->setAccount($account); $factory->setCurrency($euro); $factory->setForeignCurrency($dollar); $factory->setReconciled(false); // 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); $transaction->forceDelete(); } }