object = new PiggyBankRepository; parent::setUp(); } /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. */ public function tearDown() { parent::tearDown(); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::calculateParts */ public function testCalculateParts() { /** @var PiggyBankRepetition $repetition */ $repetition = FactoryMuffin::create('FireflyIII\Models\PiggyBankRepetition'); $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 */ public function testCreateEvent() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $this->object->createEvent($piggyBank, 100); $this->assertCount(1, $piggyBank->piggybankevents()->get()); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::createPiggyBankPart */ public function testCreatePiggyBankPart() { $repetition = FactoryMuffin::create('FireflyIII\Models\PiggyBankRepetition'); $data = [ '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 */ public function testDestroy() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $this->object->destroy($piggyBank); $this->assertCount(0, PiggyBank::where('id', $piggyBank->id)->whereNull('deleted_at')->get()); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEventSummarySet */ public function testGetEventSummarySet() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $set = $this->object->getEventSummarySet($piggyBank); $this->assertCount(0, $set); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getEvents * @todo Implement testGetEvents(). */ public function testGetEvents() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $set = $this->object->getEvents($piggyBank); $this->assertCount(0, $set); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::getPiggyBanks */ public function testGetPiggyBanks() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $this->be($piggyBank->account->user); $set = $this->object->getPiggyBanks(); $this->assertCount(1, $set); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::reset */ public function testReset() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $piggyBank->order = 4; $piggyBank->save(); $this->be($piggyBank->account->user); $this->object->reset(); $this->assertCount(1, PiggyBank::where('order', 0)->get()); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::setOrder */ public function testSetOrder() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $piggyBank->order = 4; $this->be($piggyBank->account->user); $piggyBank->save(); $this->object->setOrder($piggyBank->id, 3); $newPiggy = PiggyBank::find($piggyBank->id); $this->assertEquals(3, $newPiggy->order); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::store * @todo Implement testStore(). */ public function testStore() { $account = FactoryMuffin::create('FireflyIII\Models\Account'); $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); } /** * @covers FireflyIII\Repositories\PiggyBank\PiggyBankRepository::update * @todo Implement testUpdate(). */ public function testUpdate() { $piggyBank = FactoryMuffin::create('FireflyIII\Models\PiggyBank'); $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); } }