mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Covered category repository.
This commit is contained in:
parent
e0396b29e8
commit
d1a4a83570
@ -1,5 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\Category;
|
||||||
use FireflyIII\Repositories\Category\CategoryRepository;
|
use FireflyIII\Repositories\Category\CategoryRepository;
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generated by PHPUnit_SkeletonGenerator on 2015-05-05 at 19:19:32.
|
* 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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::countJournals
|
||||||
* @todo Implement testCountJournals().
|
|
||||||
*/
|
*/
|
||||||
public function testCountJournals()
|
public function testCountJournals()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
$this->markTestIncomplete(
|
$result = $this->object->countJournals($category);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertEquals(0, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,129 +50,204 @@ class CategoryRepositoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
$this->markTestIncomplete(
|
$this->object->destroy($category);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$count = Category::where('id', $category->id)->whereNull('deleted_at')->count();
|
||||||
|
$this->assertEquals(0, $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategories
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategories
|
||||||
* @todo Implement testGetCategories().
|
|
||||||
*/
|
*/
|
||||||
public function testGetCategories()
|
public function testGetCategories()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$cat1 = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
'This test has not been implemented yet.'
|
$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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getCategoriesAndExpenses
|
||||||
* @todo Implement testGetCategoriesAndExpenses().
|
|
||||||
*/
|
*/
|
||||||
public function testGetCategoriesAndExpenses()
|
public function testGetCategoriesAndExpenses()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$type = FactoryMuffin::create('FireflyIII\Models\TransactionType');
|
||||||
'This test has not been implemented yet.'
|
// 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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getFirstActivityDate
|
||||||
* @todo Implement testGetFirstActivityDate().
|
|
||||||
*/
|
*/
|
||||||
public function testGetFirstActivityDate()
|
public function testGetFirstActivityDate()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
'This test has not been implemented yet.'
|
/** @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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getJournals
|
||||||
* @todo Implement testGetJournals().
|
|
||||||
*/
|
*/
|
||||||
public function testGetJournals()
|
public function testGetJournals()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
|
||||||
$this->markTestIncomplete(
|
/** @var Category $category */
|
||||||
'This test has not been implemented yet.'
|
$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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getLatestActivity
|
||||||
* @todo Implement testGetLatestActivity().
|
|
||||||
*/
|
*/
|
||||||
public function testGetLatestActivity()
|
public function testGetLatestActivity()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal');
|
||||||
'This test has not been implemented yet.'
|
/** @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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::getWithoutCategory
|
||||||
* @todo Implement testGetWithoutCategory().
|
|
||||||
*/
|
*/
|
||||||
public function testGetWithoutCategory()
|
public function testGetWithoutCategory()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$this->be($user);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$set = $this->object->getWithoutCategory(new Carbon, new Carbon);
|
||||||
|
$this->assertCount(0, $set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodSum
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentInPeriodSum
|
||||||
* @todo Implement testSpentInPeriodSum().
|
|
||||||
*/
|
*/
|
||||||
public function testSpentInPeriodSum()
|
public function testSpentInPeriodSum()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
$this->markTestIncomplete(
|
$sum = $this->object->spentInPeriodSum($category, new Carbon, new Carbon);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertEquals(0, $sum);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySum
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::spentOnDaySum
|
||||||
* @todo Implement testSpentOnDaySum().
|
|
||||||
*/
|
*/
|
||||||
public function testSpentOnDaySum()
|
public function testSpentOnDaySum()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
$this->markTestIncomplete(
|
$sum = $this->object->spentOnDaySum($category, new Carbon);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertEquals(0, $sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\Category\CategoryRepository::store
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::store
|
||||||
* @todo Implement testStore().
|
|
||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
$this->markTestIncomplete(
|
$data = [
|
||||||
'This test has not been implemented yet.'
|
'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
|
* @covers FireflyIII\Repositories\Category\CategoryRepository::update
|
||||||
* @todo Implement testUpdate().
|
|
||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$category = FactoryMuffin::create('FireflyIII\Models\Category');
|
||||||
$this->markTestIncomplete(
|
$data = [
|
||||||
'This test has not been implemented yet.'
|
'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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user