mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-20 00:20:03 +00:00
Improve test coverage.
This commit is contained in:
@@ -37,6 +37,7 @@ use FireflyIII\Factory\TransactionTypeFactory;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -45,6 +46,15 @@ use Tests\TestCase;
|
||||
class TransactionJournalFactoryTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::debug(sprintf('Now in %s.', \get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\TransactionJournalFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
|
||||
@@ -106,6 +116,71 @@ class TransactionJournalFactoryTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Factory\TransactionJournalFactory
|
||||
* @covers \FireflyIII\Services\Internal\Support\JournalServiceTrait
|
||||
*/
|
||||
public function testCreateBasicEmptyAmount(): void
|
||||
{
|
||||
// mock used classes:
|
||||
$type = TransactionType::find(1);
|
||||
$euro = TransactionCurrency::find(1);
|
||||
$billFactory = $this->mock(BillFactory::class);
|
||||
$tagFactory = $this->mock(TagFactory::class);
|
||||
$metaFactory = $this->mock(TransactionJournalMetaFactory::class);
|
||||
$typeFactory = $this->mock(TransactionTypeFactory::class);
|
||||
$transactionFactory = $this->mock(TransactionFactory::class);
|
||||
$piggyFactory = $this->mock(PiggyBankFactory::class);
|
||||
$eventFactory = $this->mock(PiggyBankEventFactory::class);
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
|
||||
// mock stuff:
|
||||
$typeFactory->shouldReceive('find')->andReturn($type);
|
||||
$currencyRepos->shouldReceive('find')->andReturn($euro);
|
||||
|
||||
$metaFactory->shouldReceive('updateOrCreate');
|
||||
|
||||
// mock factories:
|
||||
$transactionFactory->shouldReceive('setUser')->once();
|
||||
$billFactory->shouldReceive('setUser')->once();
|
||||
$piggyFactory->shouldReceive('setUser')->once();
|
||||
$tagFactory->shouldReceive('setUser')->once();
|
||||
|
||||
$transactionFactory->shouldReceive('createPair')->once();
|
||||
$billFactory->shouldReceive('find')->andReturn(null);
|
||||
$piggyFactory->shouldReceive('find')->andReturn(null);
|
||||
$data = [
|
||||
'type' => 'withdrawal',
|
||||
'user' => $this->user()->id,
|
||||
'description' => 'I are journal',
|
||||
'date' => new Carbon('2018-01-01'),
|
||||
'bill_id' => null,
|
||||
'bill_name' => null,
|
||||
'piggy_bank_id' => null,
|
||||
'piggy_bank_name' => null,
|
||||
'notes' => 'Hello',
|
||||
'tags' => [],
|
||||
'transactions' => [
|
||||
[
|
||||
'amount' => '',
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
/** @var TransactionJournalFactory $factory */
|
||||
$factory = app(TransactionJournalFactory::class);
|
||||
$factory->setUser($this->user());
|
||||
try {
|
||||
$journal = $factory->create($data);
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
$this->assertEquals($data['description'], $journal->description);
|
||||
$this->assertEquals('2018-01-01', $journal->date->format('Y-m-d'));
|
||||
$this->assertEquals(1, $journal->notes()->count());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Same but with added meta data
|
||||
|
||||
Reference in New Issue
Block a user