. */ 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)); } }