mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Fix some tests, disable actions for the time being.
This commit is contained in:
@@ -98,6 +98,52 @@ class AccountFactoryTest extends TestCase
|
||||
$account->forceDelete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test minimal set of data to make factory work (asset account).
|
||||
*
|
||||
* @covers \FireflyIII\Factory\AccountFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
|
||||
* @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
|
||||
*/
|
||||
public function testCreateAssetLocation(): void
|
||||
{
|
||||
$data = [
|
||||
'account_type_id' => null,
|
||||
'account_type' => 'asset',
|
||||
'iban' => null,
|
||||
'name' => sprintf('Basic asset account #%d', $this->randomInt()),
|
||||
'virtual_balance' => null,
|
||||
'active' => true,
|
||||
'account_role' => 'defaultAsset',
|
||||
'store_location' => true,
|
||||
];
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$account = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// assert stuff about account:
|
||||
$this->assertEquals($account->name, $data['name']);
|
||||
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
|
||||
$this->assertEquals('', $account->iban);
|
||||
$this->assertTrue($account->active);
|
||||
$this->assertEquals(0, $account->order);
|
||||
$this->assertNull($account->virtual_balance);
|
||||
$this->assertCount(1, $account->locations()->get());
|
||||
|
||||
$account->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit invalid IBAN, so assume NULL on final result.
|
||||
*
|
||||
@@ -229,6 +275,97 @@ class AccountFactoryTest extends TestCase
|
||||
|
||||
$account->forceDelete();
|
||||
}
|
||||
/**
|
||||
* Create asset, include opening balance.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\AccountFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
|
||||
* @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
|
||||
*/
|
||||
public function testCreateAssetNegOb(): void
|
||||
{
|
||||
$data = [
|
||||
'account_type_id' => null,
|
||||
'account_type' => 'asset',
|
||||
'iban' => null,
|
||||
'name' => sprintf('Basic asset account #%d', $this->randomInt()),
|
||||
'virtual_balance' => null,
|
||||
'active' => true,
|
||||
'account_role' => 'defaultAsset',
|
||||
'opening_balance' => '-1234.56',
|
||||
'opening_balance_date' => today(),
|
||||
];
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$account = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// assert stuff about account:
|
||||
$this->assertEquals($account->name, $data['name']);
|
||||
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
|
||||
$this->assertEquals('', $account->iban);
|
||||
$this->assertTrue($account->active);
|
||||
$this->assertEquals(0, $account->order);
|
||||
$this->assertNull($account->virtual_balance);
|
||||
$this->assertCount(1, $account->transactions()->get());
|
||||
|
||||
$account->forceDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create asset, include opening balance.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\AccountFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\AccountServiceTrait
|
||||
* @covers \FireflyIII\Services\Internal\Support\LocationServiceTrait
|
||||
*/
|
||||
public function testCreateAssetZeroOb(): void
|
||||
{
|
||||
$data = [
|
||||
'account_type_id' => null,
|
||||
'account_type' => 'asset',
|
||||
'iban' => null,
|
||||
'name' => sprintf('Basic asset account #%d', $this->randomInt()),
|
||||
'virtual_balance' => null,
|
||||
'active' => true,
|
||||
'account_role' => 'defaultAsset',
|
||||
'opening_balance' => '0',
|
||||
'opening_balance_date' => today(),
|
||||
];
|
||||
|
||||
/** @var AccountFactory $factory */
|
||||
$factory = app(AccountFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$account = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
Log::error($e->getMessage());
|
||||
Log::error($e->getTraceAsString());
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// assert stuff about account:
|
||||
$this->assertEquals($account->name, $data['name']);
|
||||
$this->assertEquals(AccountType::ASSET, $account->accountType->type);
|
||||
$this->assertEquals('', $account->iban);
|
||||
$this->assertTrue($account->active);
|
||||
$this->assertEquals(0, $account->order);
|
||||
$this->assertNull($account->virtual_balance);
|
||||
$this->assertCount(0, $account->transactions()->get());
|
||||
|
||||
$account->forceDelete();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -32,9 +32,6 @@ use Tests\TestCase;
|
||||
/**
|
||||
*
|
||||
* Class AccountMetaFactoryTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class AccountMetaFactoryTest extends TestCase
|
||||
{
|
||||
@@ -43,9 +40,6 @@ class AccountMetaFactoryTest extends TestCase
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::markTestIncomplete('Incomplete for refactor.');
|
||||
|
||||
return;
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
@@ -55,6 +49,7 @@ class AccountMetaFactoryTest extends TestCase
|
||||
*/
|
||||
public function testCreate(): void
|
||||
{
|
||||
// make new account, or get one from DB?
|
||||
$account = $this->getRandomAsset();
|
||||
$data = [
|
||||
'account_id' => $account->id,
|
||||
|
@@ -34,9 +34,6 @@ use Tests\TestCase;
|
||||
/**
|
||||
*
|
||||
* Class AttachmentFactoryTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class AttachmentFactoryTest extends TestCase
|
||||
{
|
||||
@@ -46,9 +43,6 @@ class AttachmentFactoryTest extends TestCase
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::markTestIncomplete('Incomplete for refactor.');
|
||||
|
||||
return;
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
@@ -85,12 +79,12 @@ class AttachmentFactoryTest extends TestCase
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\AttachmentFactory
|
||||
*/
|
||||
public function testCreateTransaction(): void
|
||||
public function testCreateWithTransaction(): void
|
||||
{
|
||||
|
||||
$journal = $this->getRandomWithdrawal();
|
||||
$journal = $this->getRandomWithdrawal();
|
||||
$transaction = $journal->transactions()->first();
|
||||
$data = [
|
||||
$data = [
|
||||
'model_id' => $transaction->id,
|
||||
'model' => Transaction::class,
|
||||
'filename' => 'testfile.pdf',
|
||||
@@ -107,40 +101,8 @@ class AttachmentFactoryTest extends TestCase
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($data['title'], $result->title);
|
||||
$this->assertEquals($result->attachable_id, $journal->id);
|
||||
$this->assertEquals(1, $result->notes()->count());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\AttachmentFactory
|
||||
*/
|
||||
public function testCreateTransactionAppendModel(): void
|
||||
{
|
||||
|
||||
$journal = $this->getRandomWithdrawal();
|
||||
$transaction = $journal->transactions()->first();
|
||||
$data = [
|
||||
'model_id' => $transaction->id,
|
||||
'model' => 'Transaction',
|
||||
'filename' => 'testfile.pdf',
|
||||
'title' => 'File name',
|
||||
'notes' => 'Some notes',
|
||||
];
|
||||
|
||||
/** @var AttachmentFactory $factory */
|
||||
$factory = app(AttachmentFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$result = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($data['title'], $result->title);
|
||||
$this->assertEquals($result->attachable_id, $journal->id);
|
||||
$this->assertEquals(1, $result->notes()->count());
|
||||
$this->assertEquals($journal->id, $result->attachable_id);
|
||||
|
||||
|
||||
}
|
||||
|
@@ -24,17 +24,14 @@ declare(strict_types=1);
|
||||
namespace Tests\Unit\Factory;
|
||||
|
||||
|
||||
use Amount;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\BillFactory;
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\ObjectGroup;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class BillFactoryTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
*/
|
||||
class BillFactoryTest extends TestCase
|
||||
{
|
||||
@@ -43,24 +40,17 @@ class BillFactoryTest extends TestCase
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
self::markTestIncomplete('Incomplete for refactor.');
|
||||
|
||||
return;
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create basic bill with minimum data.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
*/
|
||||
public function testCreateBasic(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$euro = $this->getEuro();
|
||||
$data = [
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'currency_id' => 1,
|
||||
@@ -74,13 +64,14 @@ class BillFactoryTest extends TestCase
|
||||
'notes' => 'Hello!',
|
||||
];
|
||||
|
||||
$currencyFactory->shouldReceive('find')->atLeast()->once()
|
||||
->withArgs([1, ''])->andReturn($euro);
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
$bill = $factory->create($data);
|
||||
try {
|
||||
$bill = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($data['name'], $bill->name);
|
||||
$this->assertEquals($data['amount_min'], $bill->amount_min);
|
||||
@@ -92,56 +83,117 @@ class BillFactoryTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Create basic bill with minimum data.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
*/
|
||||
public function testCreateDifferentCurrency(): void
|
||||
public function testCreateQueryException(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$dollar = $this->getDollar();
|
||||
$data = [
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'currency_code' => $dollar->code,
|
||||
'currency_id' => 1,
|
||||
'currency_code' => '',
|
||||
'amount_max' => '10',
|
||||
'date' => '2018-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'automatch' => true,
|
||||
'active' => true,
|
||||
'active' => 'I AM A STRING',
|
||||
'notes' => 'Hello!',
|
||||
];
|
||||
|
||||
$currencyFactory->shouldReceive('find')->atLeast()->once()
|
||||
->withArgs([0, $dollar->code])->andReturn($dollar);
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
$bill = $factory->create($data);
|
||||
|
||||
$this->assertEquals($data['name'], $bill->name);
|
||||
$this->assertEquals($data['amount_min'], $bill->amount_min);
|
||||
$this->assertEquals($dollar->id, $bill->transaction_currency_id);
|
||||
$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
|
||||
$note = $bill->notes()->first();
|
||||
$this->assertEquals($data['notes'], $note->text);
|
||||
|
||||
try {
|
||||
$factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertEquals('400000: Could not store bill.', $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create basic bill with minimum data.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
* @covers \FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups
|
||||
*/
|
||||
public function testCreateObjectGroup(): void
|
||||
{
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'amount_max' => '10',
|
||||
'date' => '2018-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'object_group' => 'Test',
|
||||
'automatch' => true,
|
||||
'active' => 1,
|
||||
'notes' => 'Hello!',
|
||||
];
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$bill = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertFalse(true, $e->getMessage());
|
||||
return;
|
||||
}
|
||||
$this->assertCount(1, $bill->objectGroups()->get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
* @covers \FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups
|
||||
*/
|
||||
public function testCreateObjectGroupById(): void
|
||||
{
|
||||
$group = ObjectGroup::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'title' => sprintf('Random object group #%d', $this->randomInt()),
|
||||
'order' => 1,
|
||||
]
|
||||
);
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'currency_id' => 1,
|
||||
'amount_max' => '10',
|
||||
'date' => '2018-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'object_group_id' => $group->id,
|
||||
'automatch' => true,
|
||||
'active' => 1,
|
||||
'notes' => 'Hello!',
|
||||
];
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$bill = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertFalse(true, $e->getMessage());
|
||||
return;
|
||||
}
|
||||
$this->assertCount(1, $bill->objectGroups()->get());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
*/
|
||||
public function testCreateEmptyNotes(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$euro = $this->getEuro();
|
||||
$data = [
|
||||
$euro = $this->getEuro();
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'amount_max' => '10',
|
||||
@@ -155,14 +207,14 @@ class BillFactoryTest extends TestCase
|
||||
'notes' => '',
|
||||
];
|
||||
|
||||
$currencyFactory->shouldReceive('find')->atLeast()->once()
|
||||
->withArgs([1, ''])->andReturn($euro);
|
||||
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
$bill = $factory->create($data);
|
||||
try {
|
||||
$bill = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
|
||||
$this->assertEquals($data['name'], $bill->name);
|
||||
$this->assertEquals($euro->id, $bill->transaction_currency_id);
|
||||
@@ -172,48 +224,6 @@ class BillFactoryTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Create basic bill with minimum data.
|
||||
*
|
||||
* @covers \FireflyIII\Factory\BillFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
||||
*/
|
||||
public function testCreateNoCurrency(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$dollar = $this->getDollar();
|
||||
$data = [
|
||||
'name' => sprintf('Some new bill #%d', $this->randomInt()),
|
||||
'amount_min' => '5',
|
||||
'amount_max' => '10',
|
||||
'date' => '2018-01-01',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'automatch' => true,
|
||||
'active' => true,
|
||||
'notes' => 'Hello!',
|
||||
];
|
||||
|
||||
$currencyFactory->shouldReceive('find')->atLeast()->once()
|
||||
->withArgs([0, ''])->andReturnNull();
|
||||
|
||||
Amount::shouldReceive('getDefaultCurrencyByUser')->atLeast()->once()->andReturn($dollar);
|
||||
|
||||
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
$bill = $factory->create($data);
|
||||
|
||||
$this->assertEquals($data['name'], $bill->name);
|
||||
$this->assertEquals($data['amount_min'], $bill->amount_min);
|
||||
$this->assertEquals($dollar->id, $bill->transaction_currency_id);
|
||||
$this->assertEquals($data['repeat_freq'], $bill->repeat_freq);
|
||||
$note = $bill->notes()->first();
|
||||
$this->assertEquals($data['notes'], $note->text);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Find by ID
|
||||
*
|
||||
@@ -222,8 +232,7 @@ class BillFactoryTest extends TestCase
|
||||
*/
|
||||
public function testFindById(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$existing = $this->user()->piggyBanks()->first();
|
||||
$existing = $this->user()->piggyBanks()->first();
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
@@ -239,8 +248,7 @@ class BillFactoryTest extends TestCase
|
||||
*/
|
||||
public function testFindByName(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
$existing = $this->user()->bills()->first();
|
||||
$existing = $this->user()->bills()->first();
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
@@ -257,7 +265,6 @@ class BillFactoryTest extends TestCase
|
||||
*/
|
||||
public function testFindByUnknownName(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
@@ -274,7 +281,6 @@ class BillFactoryTest extends TestCase
|
||||
*/
|
||||
public function testFindNull(): void
|
||||
{
|
||||
$currencyFactory = $this->mock(TransactionCurrencyFactory::class);
|
||||
/** @var BillFactory $factory */
|
||||
$factory = app(BillFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
|
Reference in New Issue
Block a user