mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-24 08:00:12 -06:00
Fix some tests, disable actions for the time being.
This commit is contained in:
parent
a6a83286b9
commit
723d1cffe2
@ -7,4 +7,4 @@ cp .ci/.env.ci ../.env
|
||||
wget --quiet https://raw.githubusercontent.com/firefly-iii/test-data/main/test_db.sqlite -o storage/database/test_db.sqlite
|
||||
|
||||
# run phpunit
|
||||
./vendor/bin/phpunit
|
||||
./vendor/bin/phpunit --configuration phpunit.coverage.xml
|
||||
|
13
.github/workflows/laravel.yml
vendored
13
.github/workflows/laravel.yml
vendored
@ -2,17 +2,8 @@ name: Firefly III
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
- feature/*
|
||||
- features/*
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
- develop
|
||||
- feature/*
|
||||
- features/*
|
||||
branches-ignore:
|
||||
- '**'
|
||||
|
||||
jobs:
|
||||
prepare:
|
||||
|
@ -85,7 +85,7 @@ trait AccountServiceTrait
|
||||
$fields = $this->validAssetFields;
|
||||
}
|
||||
if ($account->accountType->type === AccountType::ASSET && isset($data['account_role']) && 'ccAsset' === $data['account_role']) {
|
||||
$fields = $this->validCCFields;
|
||||
$fields = $this->validCCFields; // @codeCoverageIgnore
|
||||
}
|
||||
/** @var AccountMetaFactory $factory */
|
||||
$factory = app(AccountMetaFactory::class);
|
||||
@ -96,10 +96,10 @@ trait AccountServiceTrait
|
||||
|
||||
// convert boolean value:
|
||||
if (is_bool($data[$field]) && false === $data[$field]) {
|
||||
$data[$field] = 0;
|
||||
$data[$field] = 0; // @codeCoverageIgnore
|
||||
}
|
||||
if (is_bool($data[$field]) && true === $data[$field]) {
|
||||
$data[$field] = 1;
|
||||
$data[$field] = 1; // @codeCoverageIgnore
|
||||
}
|
||||
|
||||
$factory->crud($account, $field, (string)$data[$field]);
|
||||
@ -150,7 +150,7 @@ trait AccountServiceTrait
|
||||
{
|
||||
$data['opening_balance'] = (string)($data['opening_balance'] ?? '');
|
||||
if ('' !== $data['opening_balance'] && 0 === bccomp($data['opening_balance'], '0')) {
|
||||
$data['opening_balance'] = '';
|
||||
$data['opening_balance'] = ''; // @codeCoverageIgnore
|
||||
}
|
||||
if ('' !== $data['opening_balance'] && isset($data['opening_balance'], $data['opening_balance_date'])) {
|
||||
Log::debug('Array has valid opening balance data.');
|
||||
@ -171,12 +171,18 @@ trait AccountServiceTrait
|
||||
*/
|
||||
public function isEmptyOBData(array $data): bool
|
||||
{
|
||||
if (!isset($data['opening_balance']) && !isset($data['opening_balance_date'])) {
|
||||
if (!array_key_exists('opening_balance', $data) &&
|
||||
!array_key_exists('opening_balance_date', $data)
|
||||
) {
|
||||
// not set, so false.
|
||||
return false;
|
||||
}
|
||||
// if isset, but is empty:
|
||||
if ('' === $data['opening_balance'] && '' === $data['opening_balance_date']) {
|
||||
if (
|
||||
(array_key_exists('opening_balance', $data) && '' === $data['opening_balance'])
|
||||
||
|
||||
(array_key_exists('opening_balance_date', $data) && '' === $data['opening_balance_date'])
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -211,9 +217,11 @@ trait AccountServiceTrait
|
||||
$sourceId = $account->id;
|
||||
}
|
||||
if (0 === bccomp($amount, '0')) {
|
||||
// @codeCoverageIgnoreStart
|
||||
Log::debug('Amount is zero, so will not make an OB group.');
|
||||
|
||||
return null;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
$amount = app('steam')->positive($amount);
|
||||
$submission = [
|
||||
@ -327,7 +335,6 @@ trait AccountServiceTrait
|
||||
* @param array $data
|
||||
*
|
||||
* @return TransactionGroup|null
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
protected function updateOBGroup(Account $account, array $data): ?TransactionGroup
|
||||
{
|
||||
|
@ -24,7 +24,13 @@ declare(strict_types=1);
|
||||
namespace Tests\Traits;
|
||||
|
||||
|
||||
use DB;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\User;
|
||||
|
||||
/**
|
||||
@ -48,6 +54,46 @@ trait CollectsValues
|
||||
return User::where('email', 'no_admin@firefly')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionJournal
|
||||
*/
|
||||
public function getRandomWithdrawal(): TransactionJournal
|
||||
{
|
||||
return $this->getRandomJournal(TransactionType::WITHDRAWAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
* @return TransactionJournal
|
||||
* @throws FireflyException
|
||||
*/
|
||||
private function getRandomJournal(string $type): TransactionJournal
|
||||
{
|
||||
$query = DB::table('transactions')
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_journals.user_id', $this->user()->id)
|
||||
->whereNull('transaction_journals.deleted_at')
|
||||
->whereNull('transactions.deleted_at')
|
||||
->where('transaction_types.type', $type)
|
||||
->groupBy('transactions.transaction_journal_id')
|
||||
->having('ct', '=', 2)
|
||||
->inRandomOrder()->take(1);
|
||||
$result = $query->get(
|
||||
[
|
||||
'transactions.transaction_journal_id',
|
||||
'transaction_journals.transaction_type_id',
|
||||
DB::raw('COUNT(transaction_journal_id) as ct'),
|
||||
]
|
||||
)->first();
|
||||
if (null === $result) {
|
||||
throw new FireflyException(sprintf('Cannot find suitable %s to use.', $type));
|
||||
}
|
||||
|
||||
return TransactionJournal::find((int)$result->transaction_journal_id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
@ -55,4 +101,45 @@ trait CollectsValues
|
||||
{
|
||||
return TransactionCurrency::whereCode('EUR')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function getDollar(): TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::whereCode('USD')->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null $except
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
public function getRandomAsset(?int $except = null): Account
|
||||
{
|
||||
return $this->getRandomAccount(AccountType::ASSET, $except);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*
|
||||
* @param int|null $except
|
||||
*
|
||||
* @return Account
|
||||
*/
|
||||
private function getRandomAccount(string $type, ?int $except): Account
|
||||
{
|
||||
$query = Account::
|
||||
leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
|
||||
->whereNull('accounts.deleted_at')
|
||||
->where('accounts.user_id', $this->user()->id)
|
||||
->where('account_types.type', $type)
|
||||
->inRandomOrder()->take(1);
|
||||
if (null !== $except) {
|
||||
$query->where('accounts.id', '!=', $except);
|
||||
}
|
||||
return $query->first(['accounts.*']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user