From 506ef7b0b944c75f942a86c05e474d6a97b72e90 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 9 May 2015 15:11:12 +0200 Subject: [PATCH] Covered currency repository. --- tests/repositories/CurrencyRepositoryTest.php | 72 ++++++++++++------- 1 file changed, 47 insertions(+), 25 deletions(-) diff --git a/tests/repositories/CurrencyRepositoryTest.php b/tests/repositories/CurrencyRepositoryTest.php index 756991dd3d..221ea6ec15 100644 --- a/tests/repositories/CurrencyRepositoryTest.php +++ b/tests/repositories/CurrencyRepositoryTest.php @@ -1,5 +1,6 @@ markTestIncomplete( - 'This test has not been implemented yet.' - ); + $currency = FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + $count = $this->object->countJournals($currency); + $this->assertEquals(0, $count); } /** * @covers FireflyIII\Repositories\Currency\CurrencyRepository::get - * @todo Implement testGet(). */ public function testGet() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + FactoryMuffin::create('FireflyIII\Models\TransactionCurrency'); + + $set = $this->object->get(); + $this->assertCount(2, $set); } /** * @covers FireflyIII\Repositories\Currency\CurrencyRepository::getCurrencyByPreference - * @todo Implement testGetCurrencyByPreference(). */ public function testGetCurrencyByPreference() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $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); + $this->assertEquals($first->id, $found->id); } /** * @covers FireflyIII\Repositories\Currency\CurrencyRepository::store - * @todo Implement testStore(). */ public function testStore() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $data = [ + 'name' => 'Some Currency', + 'code' => 'ABC', + 'symbol' => 'S' + ]; + + $currency = $this->object->store($data); + $this->assertEquals($data['name'], $currency->name); } /** * @covers FireflyIII\Repositories\Currency\CurrencyRepository::update - * @todo Implement testUpdate(). */ public function testUpdate() { - // Remove the following lines when you implement this test. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $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); } }