Covered category repository.

This commit is contained in:
James Cole 2015-05-09 13:14:02 +02:00
parent e0396b29e8
commit d1a4a83570

View File

@ -1,5 +1,8 @@
<?php
use Carbon\Carbon;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepository;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
@ -32,14 +35,13 @@ class CategoryRepositoryTest extends TestCase
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::countJournals
* @todo Implement testCountJournals().
*/
public function testCountJournals()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$result = $this->object->countJournals($category);
$this->assertEquals(0, $result);
}
/**
@ -48,129 +50,204 @@ class CategoryRepositoryTest extends TestCase
*/
public function testDestroy()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->object->destroy($category);
$count = Category::where('id', $category->id)->whereNull('deleted_at')->count();
$this->assertEquals(0, $count);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategories
* @todo Implement testGetCategories().
*/
public function testGetCategories()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$cat1 = FactoryMuffin::create('FireflyIII\Models\Category');
$cat2 = FactoryMuffin::create('FireflyIII\Models\Category');
$cat1->name = 'BBBBB';
$cat2->name = 'AAAAA';
$cat1->user_id = $user->id;
$cat2->user_id = $user->id;
$cat1->save();
$cat2->save();
$this->be($user);
$set = $this->object->getCategories();
$this->assertEquals('AAAAA', $set->first()->name);
$this->assertCount(2, $set);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpenses
* @todo Implement testGetCategoriesAndExpenses().
*/
public function testGetCategoriesAndExpenses()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
// some journals and categories:
for ($i = 0; $i < 5; $i++) {
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$journal->transaction_type_id = $type->id;
$category->user_id = $user->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
}
$this->be($user);
$set = $this->object->getCategoriesAndExpenses(new Carbon('2015-02-01'), new Carbon('2015-02-28'));
$this->assertCount(5, $set);
$this->assertEquals(0, $set->first()->sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getFirstActivityDate
* @todo Implement testGetFirstActivityDate().
*/
public function testGetFirstActivityDate()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$category->user_id = $user->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
$this->be($user);
$date = $this->object->getFirstActivityDate($category);
$this->assertEquals('2015-02-11', $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getFirstActivityDate
*/
public function testGetFirstActivityDateNull()
{
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$date = $this->object->getFirstActivityDate($category);
$this->assertEquals(Carbon::now()->format('Y-m-d'), $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getJournals
* @todo Implement testGetJournals().
*/
public function testGetJournals()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$set = $this->object->getJournals($category, 1);
$this->assertEquals(0, $set->count());
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getLatestActivity
* @todo Implement testGetLatestActivity().
*/
public function testGetLatestActivity()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$journal->user_id = $user->id;
$journal->date = new Carbon('2015-02-11');
$category->user_id = $user->id;
$category->transactionjournals()->save($journal);
$journal->save();
$category->save();
$this->be($user);
$date = $this->object->getLatestActivity($category);
$this->assertEquals('2015-02-11', $date->format('Y-m-d'));
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::getWithoutCategory
* @todo Implement testGetWithoutCategory().
*/
public function testGetWithoutCategory()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$this->be($user);
$set = $this->object->getWithoutCategory(new Carbon, new Carbon);
$this->assertCount(0, $set);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodSum
* @todo Implement testSpentInPeriodSum().
*/
public function testSpentInPeriodSum()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentInPeriodSum($category, new Carbon, new Carbon);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySum
* @todo Implement testSpentOnDaySum().
*/
public function testSpentOnDaySum()
{
// Remove the following lines when you implement this test.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$sum = $this->object->spentOnDaySum($category, new Carbon);
$this->assertEquals(0, $sum);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::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.'
);
$user = FactoryMuffin::create('FireflyIII\User');
$data = [
'name' => 'New category' . rand(1, 100),
'user' => $user->id
];
$newCategory = $this->object->store($data);
$this->assertEquals($data['name'], $newCategory->name);
}
/**
* @covers FireflyIII\Repositories\Category\CategoryRepository::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.'
);
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$data = [
'name' => 'New category' . rand(1, 100),
];
$newCategory = $this->object->update($category, $data);
$this->assertEquals($data['name'], $newCategory->name);
}
public function testgetLatestActivityNull()
{
/** @var Category $category */
$category = FactoryMuffin::create('FireflyIII\Models\Category');
$this->be($category->user);
$date = $this->object->getLatestActivity($category);
$this->assertNull($date);
}
}