firefly-iii/tests/repositories/CurrencyRepositoryTest.php

115 lines
3.4 KiB
PHP
Raw Normal View History

2015-05-05 15:46:28 -05:00
<?php
use FireflyIII\Repositories\Currency\CurrencyRepository;
2015-05-09 08:11:12 -05:00
use League\FactoryMuffin\Facade as FactoryMuffin;
2015-05-05 15:46:28 -05:00
/**
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
*/
class CurrencyRepositoryTest extends TestCase
{
/**
* @var CurrencyRepository
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
$this->object = new CurrencyRepository;
parent::setUp();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
2015-05-06 11:09:45 -05:00
parent::tearDown();
2015-05-05 15:46:28 -05:00
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::countJournals
*/
public function testCountJournals()
{
2015-05-09 08:11:12 -05:00
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$count = $this->object->countJournals($currency);
$this->assertEquals(0, $count);
2015-05-05 15:46:28 -05:00
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::get
*/
public function testGet()
{
2015-05-09 08:11:12 -05:00
FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$set = $this->object->get();
2015-05-10 01:49:15 -05:00
$this->assertCount(3, $set); // EUR is already present.
2015-05-05 15:46:28 -05:00
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::getCurrencyByPreference
*/
public function testGetCurrencyByPreference()
{
2015-05-09 08:11:12 -05:00
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = $currency->code;
$preference->save();
$found = $this->object->getCurrencyByPreference($preference);
$this->assertEquals($currency->id, $found->id);
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::getCurrencyByPreference
*/
public function testGetCurrencyByPreferenceNull()
{
$first = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
$preference->data = 'ABC';
$preference->save();
$found = $this->object->getCurrencyByPreference($preference);
2015-05-10 02:26:44 -05:00
$this->assertEquals(1, $found->id); // EUR is first and will be set.
2015-05-05 15:46:28 -05:00
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::store
*/
public function testStore()
{
2015-05-09 08:11:12 -05:00
$data = [
'name' => 'Some Currency',
'code' => 'ABC',
'symbol' => 'S'
];
$currency = $this->object->store($data);
$this->assertEquals($data['name'], $currency->name);
2015-05-05 15:46:28 -05:00
}
/**
* @covers FireflyIII\Repositories\Currency\CurrencyRepository::update
*/
public function testUpdate()
{
2015-05-09 08:11:12 -05:00
$currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency');
$data = [
'name' => 'Some Currency',
'code' => 'ABC',
'symbol' => 'S'
];
$newCurrency = $this->object->update($currency, $data);
$this->assertEquals($data['name'], $newCurrency->name);
$this->assertEquals($currency->id, $newCurrency->id);
2015-05-05 15:46:28 -05:00
}
}