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

102 lines
3.1 KiB
PHP
Raw Normal View History

2018-03-01 20:54:50 +01:00
<?php
/**
* AccountFactoryTest.php
2020-02-16 13:59:55 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-03-01 20:54:50 +01:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-03-01 20:54:50 +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-03-01 20:54:50 +01:00
*
* This program is distributed in the hope that it will be useful,
2018-03-01 20:54:50 +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-03-01 20:54:50 +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-03-01 20:54:50 +01:00
*/
declare(strict_types=1);
namespace Tests\Unit\Factory;
2019-08-03 14:45:37 +02:00
use Amount;
2018-03-01 20:54:50 +01:00
use Carbon\Carbon;
2018-08-24 07:18:33 +02:00
use FireflyIII\Exceptions\FireflyException;
2018-03-01 20:54:50 +01:00
use FireflyIII\Factory\AccountFactory;
2019-06-16 13:16:46 +02:00
use FireflyIII\Factory\AccountMetaFactory;
2019-08-03 14:45:37 +02:00
use FireflyIII\Factory\TransactionCurrencyFactory;
2019-06-16 13:16:46 +02:00
use FireflyIII\Factory\TransactionGroupFactory;
2018-08-24 07:18:33 +02:00
use FireflyIII\Models\Account;
use FireflyIII\Models\AccountMeta;
2018-03-01 20:54:50 +01:00
use FireflyIII\Models\AccountType;
2019-08-29 17:53:25 +02:00
use FireflyIII\Models\Preference;
2019-06-16 13:16:46 +02:00
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2018-08-24 07:18:33 +02:00
use Log;
2019-06-16 13:16:46 +02:00
use Mockery;
2019-08-29 17:53:25 +02:00
use Preferences;
2018-03-01 20:54:50 +01:00
use Tests\TestCase;
/**
* Class AccountFactoryTest
*/
class AccountFactoryTest 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
/**
* Test minimal set of data to make factory work (asset account).
*
* @covers \FireflyIII\Factory\AccountFactory
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
2020-08-01 05:32:38 +02:00
* @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
2018-03-01 20:54:50 +01:00
*/
2020-08-01 05:34:32 +02:00
public function testCreateNoMockery(): void
2018-03-01 20:54:50 +01:00
{
2020-08-01 05:32:38 +02:00
// mock repositories
$data = [
2018-03-01 20:54:50 +01:00
'account_type_id' => null,
2019-06-16 13:16:46 +02:00
'account_type' => 'asset',
2018-03-01 20:54:50 +01:00
'iban' => null,
2019-06-16 13:16:46 +02:00
'name' => sprintf('Basic asset account #%d', $this->randomInt()),
'virtual_balance' => null,
2018-03-01 20:54:50 +01:00
'active' => true,
2019-06-16 13:16:46 +02:00
'account_role' => 'defaultAsset',
2018-03-01 20:54:50 +01:00
];
2018-03-30 22:40:20 +02:00
/** @var AccountFactory $factory */
$factory = app(AccountFactory::class);
$factory->setUser($this->user());
2019-06-16 13:16:46 +02:00
try {
$account = $factory->create($data);
} catch (FireflyException $e) {
2019-08-03 14:45:37 +02:00
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
2019-06-16 13:16:46 +02:00
$this->assertTrue(false, $e->getMessage());
return;
}
2018-03-30 22:40:20 +02:00
// assert stuff about account:
$this->assertEquals($account->name, $data['name']);
2019-08-29 17:53:25 +02:00
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
2018-03-30 22:40:20 +02:00
$this->assertEquals('', $account->iban);
$this->assertTrue($account->active);
2020-08-01 05:32:38 +02:00
$this->assertEquals(0, $account->order);
$this->assertNull($account->virtual_balance);
2019-08-29 17:53:25 +02:00
$account->forceDelete();
2018-03-01 20:54:50 +01:00
}
2018-03-04 15:14:29 +01:00
}