mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More new tests.
This commit is contained in:
@@ -145,14 +145,20 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
|||||||
/**
|
/**
|
||||||
* Set all piggy banks to order 0.
|
* Set all piggy banks to order 0.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function reset()
|
public function reset()
|
||||||
{
|
{
|
||||||
DB::table('piggy_banks')
|
// split query to make it work in sqlite:
|
||||||
->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.id')
|
$set = PiggyBank::
|
||||||
->where('accounts.user_id', Auth::user()->id)
|
leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.id')
|
||||||
->update(['order' => 0, 'piggy_banks.updated_at' => DB::Raw('NOW()')]);
|
->where('accounts.user_id', Auth::user()->id)->get(['piggy_banks.*']);
|
||||||
|
foreach ($set as $e) {
|
||||||
|
$e->order = 0;
|
||||||
|
$e->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Models\PiggyBank;
|
||||||
|
use FireflyIII\Models\PiggyBankRepetition;
|
||||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepository;
|
use FireflyIII\Repositories\PiggyBank\PiggyBankRepository;
|
||||||
|
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,62 +36,98 @@ class PiggyBankRepositoryTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::calculateParts
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::calculateParts
|
||||||
* @todo Implement testCalculateParts().
|
|
||||||
*/
|
*/
|
||||||
public function testCalculateParts()
|
public function testCalculateParts()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
/** @var PiggyBankRepetition $repetition */
|
||||||
$this->markTestIncomplete(
|
$repetition = FactoryMuffin::create('FireflyIII\Models\PiggyBankRepetition');
|
||||||
'This test has not been implemented yet.'
|
$repetition->startdate = new Carbon('2014-01-01');
|
||||||
);
|
$repetition->targetdate = new Carbon('2014-12-31');
|
||||||
|
$repetition->save();
|
||||||
|
|
||||||
|
$parts = $this->object->calculateParts($repetition);
|
||||||
|
|
||||||
|
$this->assertCount(1, $parts);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::calculateParts
|
||||||
|
*/
|
||||||
|
public function testCalculatePartsWithReminder()
|
||||||
|
{
|
||||||
|
/** @var PiggyBankRepetition $repetition */
|
||||||
|
$repetition = FactoryMuffin::create('FireflyIII\Models\PiggyBankRepetition');
|
||||||
|
/** @var PiggyBank $piggyBank */
|
||||||
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
|
$piggyBank->startdate = new Carbon('2014-01-01');
|
||||||
|
$piggyBank->targetdate = new Carbon('2014-12-31');
|
||||||
|
$piggyBank->remind_me = 1;
|
||||||
|
$piggyBank->reminder = 'monthly';
|
||||||
|
$repetition->startdate = new Carbon('2014-01-01');
|
||||||
|
$repetition->targetdate = new Carbon('2014-12-31');
|
||||||
|
$repetition->piggy_bank_id = $piggyBank->id;
|
||||||
|
$repetition->save();
|
||||||
|
$piggyBank->save();
|
||||||
|
|
||||||
|
$parts = $this->object->calculateParts($repetition);
|
||||||
|
$this->assertCount(12, $parts);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::createEvent
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::createEvent
|
||||||
* @todo Implement testCreateEvent().
|
|
||||||
*/
|
*/
|
||||||
public function testCreateEvent()
|
public function testCreateEvent()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$this->object->createEvent($piggyBank, 100);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertCount(1, $piggyBank->piggybankevents()->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::createPiggyBankPart
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::createPiggyBankPart
|
||||||
* @todo Implement testCreatePiggyBankPart().
|
|
||||||
*/
|
*/
|
||||||
public function testCreatePiggyBankPart()
|
public function testCreatePiggyBankPart()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$repetition = FactoryMuffin::create('FireflyIII\Models\PiggyBankRepetition');
|
||||||
$this->markTestIncomplete(
|
$data = [
|
||||||
'This test has not been implemented yet.'
|
'repetition' => $repetition,
|
||||||
);
|
'amountPerBar' => 100,
|
||||||
|
'currentAmount' => 100,
|
||||||
|
'cumulativeAmount' => 100,
|
||||||
|
'startDate' => new Carbon,
|
||||||
|
'targetDate' => new Carbon,
|
||||||
|
];
|
||||||
|
$part = $this->object->createPiggyBankPart($data);
|
||||||
|
$this->assertEquals($data['amountPerBar'], $part->getAmountPerBar());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::destroy
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::destroy
|
||||||
* @todo Implement testDestroy().
|
|
||||||
*/
|
*/
|
||||||
public function testDestroy()
|
public function testDestroy()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
$this->object->destroy($piggyBank);
|
||||||
);
|
|
||||||
|
$this->assertCount(0, PiggyBank::where('id', $piggyBank->id)->whereNull('deleted_at')->get());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEventSummarySet
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEventSummarySet
|
||||||
* @todo Implement testGetEventSummarySet().
|
|
||||||
*/
|
*/
|
||||||
public function testGetEventSummarySet()
|
public function testGetEventSummarySet()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$set = $this->object->getEventSummarySet($piggyBank);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertCount(0, $set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,46 +136,51 @@ class PiggyBankRepositoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testGetEvents()
|
public function testGetEvents()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$set = $this->object->getEvents($piggyBank);
|
||||||
'This test has not been implemented yet.'
|
|
||||||
);
|
$this->assertCount(0, $set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getPiggyBanks
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getPiggyBanks
|
||||||
* @todo Implement testGetPiggyBanks().
|
|
||||||
*/
|
*/
|
||||||
public function testGetPiggyBanks()
|
public function testGetPiggyBanks()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$this->be($piggyBank->account->user);
|
||||||
'This test has not been implemented yet.'
|
$set = $this->object->getPiggyBanks();
|
||||||
);
|
|
||||||
|
$this->assertCount(1, $set);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::reset
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::reset
|
||||||
* @todo Implement testReset().
|
|
||||||
*/
|
*/
|
||||||
public function testReset()
|
public function testReset()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$piggyBank->order = 4;
|
||||||
'This test has not been implemented yet.'
|
$piggyBank->save();
|
||||||
);
|
$this->be($piggyBank->account->user);
|
||||||
|
$this->object->reset();
|
||||||
|
|
||||||
|
$this->assertCount(1, PiggyBank::where('order', 0)->get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::setOrder
|
* @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::setOrder
|
||||||
* @todo Implement testSetOrder().
|
|
||||||
*/
|
*/
|
||||||
public function testSetOrder()
|
public function testSetOrder()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
$piggyBank->order = 4;
|
||||||
'This test has not been implemented yet.'
|
$this->be($piggyBank->account->user);
|
||||||
);
|
$piggyBank->save();
|
||||||
|
|
||||||
|
$this->object->setOrder($piggyBank->id, 3);
|
||||||
|
$newPiggy = PiggyBank::find($piggyBank->id);
|
||||||
|
$this->assertEquals(3, $newPiggy->order);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -144,10 +189,21 @@ class PiggyBankRepositoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
$data = [
|
||||||
);
|
'remind_me' => 1,
|
||||||
|
'account_id' => $account->id,
|
||||||
|
'name' => 'Some piggy',
|
||||||
|
'targetamount' => 100,
|
||||||
|
'reminder_skip' => 0,
|
||||||
|
'order' => 1,
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$piggyBank = $this->object->store($data);
|
||||||
|
|
||||||
|
$this->assertEquals(1, $piggyBank->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,9 +212,21 @@ class PiggyBankRepositoryTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
// Remove the following lines when you implement this test.
|
$piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank');
|
||||||
$this->markTestIncomplete(
|
|
||||||
'This test has not been implemented yet.'
|
$data = [
|
||||||
);
|
'name' => 'Update piggy ' . rand(1, 100),
|
||||||
|
'account_id' => $piggyBank->account_id,
|
||||||
|
'targetamount' => 101,
|
||||||
|
'targetdate' => new Carbon,
|
||||||
|
'reminder' => null,
|
||||||
|
'startdate' => new Carbon,
|
||||||
|
'remind_me' => '1'
|
||||||
|
];
|
||||||
|
|
||||||
|
$new = $this->object->update($piggyBank, $data);
|
||||||
|
|
||||||
|
$this->assertEquals($data['name'], $new->name);
|
||||||
|
$this->assertEquals($piggyBank->id, $new->id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user