mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-09 15:43:19 -06:00
167 lines
4.9 KiB
PHP
167 lines
4.9 KiB
PHP
<?php
|
|
/**
|
|
* BillFactoryTest.php
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
*
|
|
* This file is part of Firefly III.
|
|
*
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Firefly III is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit\Factory;
|
|
|
|
|
|
use FireflyIII\Factory\BillFactory;
|
|
use Tests\TestCase;
|
|
|
|
/**
|
|
* Class BillFactoryTest
|
|
*/
|
|
class BillFactoryTest extends TestCase
|
|
{
|
|
|
|
/**
|
|
* Create basic bill with minimum data.
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
|
*/
|
|
public function testCreateBasic()
|
|
{
|
|
$data = [
|
|
'name' => 'Some new bill #' . random_int(1, 1000),
|
|
'amount_min' => '5',
|
|
'transaction_currency_id' => 1,
|
|
'amount_max' => '10',
|
|
'date' => '2018-01-01',
|
|
'repeat_freq' => 'monthly',
|
|
'skip' => 0,
|
|
'automatch' => true,
|
|
'active' => true,
|
|
'notes' => 'Hello!',
|
|
];
|
|
|
|
/** @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($data['repeat_freq'], $bill->repeat_freq);
|
|
$note = $bill->notes()->first();
|
|
$this->assertEquals($data['notes'], $note->text);
|
|
|
|
}
|
|
|
|
/**
|
|
* Create basic bill with minimum data.
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
* @covers \FireflyIII\Services\Internal\Support\BillServiceTrait
|
|
*/
|
|
public function testCreateEmptyNotes()
|
|
{
|
|
$data = [
|
|
'name' => 'Some new bill #' . random_int(1, 1000),
|
|
'amount_min' => '5',
|
|
'amount_max' => '10',
|
|
'date' => '2018-01-01',
|
|
'repeat_freq' => 'monthly',
|
|
'transaction_currency_id' => 1,
|
|
'skip' => 0,
|
|
'automatch' => true,
|
|
'active' => true,
|
|
'notes' => '',
|
|
];
|
|
|
|
/** @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($data['repeat_freq'], $bill->repeat_freq);
|
|
$this->assertEquals(0, $bill->notes()->count());
|
|
|
|
}
|
|
|
|
/**
|
|
* Find by ID
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
*
|
|
*/
|
|
public function testFindById()
|
|
{
|
|
$existing = $this->user()->piggyBanks()->first();
|
|
/** @var BillFactory $factory */
|
|
$factory = app(BillFactory::class);
|
|
$factory->setUser($this->user());
|
|
$piggy = $factory->find($existing->id, null);
|
|
$this->assertEquals($existing->id, $piggy->id);
|
|
}
|
|
|
|
/**
|
|
* Find by name
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
*
|
|
*/
|
|
public function testFindByName()
|
|
{
|
|
$existing = $this->user()->bills()->first();
|
|
/** @var BillFactory $factory */
|
|
$factory = app(BillFactory::class);
|
|
$factory->setUser($this->user());
|
|
$piggy = $factory->find(null, $existing->name);
|
|
|
|
$this->assertEquals($existing->id, $piggy->id);
|
|
}
|
|
|
|
/**
|
|
* Find by unknown name
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
*
|
|
*/
|
|
public function testFindByUnknownName()
|
|
{
|
|
/** @var BillFactory $factory */
|
|
$factory = app(BillFactory::class);
|
|
$factory->setUser($this->user());
|
|
$piggy = $factory->find(null, 'I dont exist' . random_int(1, 1000));
|
|
|
|
$this->assertNull($piggy);
|
|
}
|
|
|
|
/**
|
|
* Find NULL
|
|
*
|
|
* @covers \FireflyIII\Factory\BillFactory
|
|
*
|
|
*/
|
|
public function testFindNull()
|
|
{
|
|
/** @var BillFactory $factory */
|
|
$factory = app(BillFactory::class);
|
|
$factory->setUser($this->user());
|
|
$this->assertNull($factory->find(null, null));
|
|
}
|
|
|
|
}
|