mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-18 23:50:09 +00:00
Expand factory tests.
This commit is contained in:
134
tests/Unit/Factory/BillFactoryTest.php
Normal file
134
tests/Unit/Factory/BillFactoryTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?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 #' . rand(1, 1000),
|
||||
'match' => 'i,am,word' . rand(1, 1000),
|
||||
'amount_min' => '5',
|
||||
'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['match'], $bill->match);
|
||||
$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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' . rand(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));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user