mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
More unit tests.
This commit is contained in:
parent
584f7ced84
commit
778a42bcc0
@ -148,14 +148,4 @@ class PiggyBank extends Eloquent
|
|||||||
{
|
{
|
||||||
return $this->morphMany('Reminder', 'remindersable');
|
return $this->morphMany('Reminder', 'remindersable');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
||||||
*/
|
|
||||||
public function transactions()
|
|
||||||
{
|
|
||||||
return $this->hasMany('Transaction');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -38,7 +38,7 @@ class PiggyBankRepetition extends Eloquent
|
|||||||
*/
|
*/
|
||||||
public function scopeStarts(Builder $query, Carbon $date)
|
public function scopeStarts(Builder $query, Carbon $date)
|
||||||
{
|
{
|
||||||
$query->where('startdate', $date->format('Y-m-d'));
|
$query->where('startdate', $date->format('Y-m-d 00:00:00'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +47,7 @@ class PiggyBankRepetition extends Eloquent
|
|||||||
*/
|
*/
|
||||||
public function scopeTargets(Builder $query, Carbon $date)
|
public function scopeTargets(Builder $query, Carbon $date)
|
||||||
{
|
{
|
||||||
$query->where('targetdate', $date->format('Y-m-d'));
|
$query->where('targetdate', $date->format('Y-m-d 00:00:00'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,16 +12,6 @@ class Reminder extends Eloquent
|
|||||||
|
|
||||||
protected $table = 'reminders';
|
protected $table = 'reminders';
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function getDataAttribute($value)
|
|
||||||
{
|
|
||||||
return json_decode($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -49,15 +39,7 @@ class Reminder extends Eloquent
|
|||||||
*/
|
*/
|
||||||
public function scopeDateIs($query, Carbon $start, Carbon $end)
|
public function scopeDateIs($query, Carbon $start, Carbon $end)
|
||||||
{
|
{
|
||||||
return $query->where('startdate', $start->format('Y-m-d'))->where('enddate', $end->format('Y-m-d'));
|
return $query->where('startdate', $start->format('Y-m-d 00:00:00'))->where('enddate', $end->format('Y-m-d 00:00:00'));
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*/
|
|
||||||
public function setDataAttribute($value)
|
|
||||||
{
|
|
||||||
$this->attributes['data'] = json_encode($value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,15 +26,6 @@ class Transaction extends Eloquent
|
|||||||
return $this->belongsTo('Account');
|
return $this->belongsTo('Account');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
||||||
*/
|
|
||||||
public function piggyBank()
|
|
||||||
{
|
|
||||||
return $this->belongsTo('PiggyBank');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Builder $query
|
* @param Builder $query
|
||||||
* @param Account $account
|
* @param Account $account
|
||||||
|
@ -26,14 +26,12 @@ class TestCase extends Illuminate\Foundation\Testing\TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
// reset database?
|
|
||||||
$this->prepareForTests();
|
$this->prepareForTests();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public function setupBeforeClass()
|
static public function setupBeforeClass()
|
||||||
{
|
{
|
||||||
//League\FactoryMuffin\Facade::loadFactories(__DIR__ . '/factories');
|
|
||||||
f::loadFactories(__DIR__ . '/factories');
|
f::loadFactories(__DIR__ . '/factories');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
28
app/tests/factories/PiggyBank.php
Normal file
28
app/tests/factories/PiggyBank.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
League\FactoryMuffin\Facade::define(
|
||||||
|
'PiggyBank', [
|
||||||
|
'account_id' => 'factory|Account',
|
||||||
|
'name' => 'word',
|
||||||
|
'targetamount' => 'numberBetween|10;400',
|
||||||
|
'startdate' => 'date|Y-m-d',
|
||||||
|
'targetdate' => 'date|Y-m-d',
|
||||||
|
'repeats' => 'boolean',
|
||||||
|
'rep_length' => function () {
|
||||||
|
$set = ['day', 'week', 'quarter', 'month', 'year'];
|
||||||
|
|
||||||
|
return $set[rand(0, count($set) - 1)];
|
||||||
|
},
|
||||||
|
'rep_every' => 'numberBetween:0,3',
|
||||||
|
'rep_times' => 'numberBetween:0,3',
|
||||||
|
'reminder' => function () {
|
||||||
|
$set = ['day', 'week', 'quarter', 'month', 'year'];
|
||||||
|
|
||||||
|
return $set[rand(0, count($set) - 1)];
|
||||||
|
},
|
||||||
|
'reminder_skip' => 'numberBetween:0,3',
|
||||||
|
'remind_me' => 'boolean',
|
||||||
|
'order' => 'numberBetween:0,10',
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
11
app/tests/factories/PiggyBankRepetition.php
Normal file
11
app/tests/factories/PiggyBankRepetition.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
League\FactoryMuffin\Facade::define(
|
||||||
|
'PiggyBankRepetition', [
|
||||||
|
'piggy_bank_id' => 'factory|PiggyBank',
|
||||||
|
'startdate' => 'date|Y-m-d',
|
||||||
|
'targetdate' => 'date|Y-m-d',
|
||||||
|
'currentamount' => 'numberBetween:0,100',
|
||||||
|
|
||||||
|
]
|
||||||
|
);
|
13
app/tests/factories/Reminder.php
Normal file
13
app/tests/factories/Reminder.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
League\FactoryMuffin\Facade::define(
|
||||||
|
'Reminder', [
|
||||||
|
'user_id' => 'factory|User',
|
||||||
|
'startdate' => 'date|Y-m-d',
|
||||||
|
'enddate' => 'date|Y-m-d',
|
||||||
|
'active' => 'boolean',
|
||||||
|
'notnow' => 'boolean',
|
||||||
|
'remindersable_id' => 0,
|
||||||
|
'remindersable_type' => '',
|
||||||
|
]
|
||||||
|
);
|
@ -2,7 +2,7 @@
|
|||||||
use League\FactoryMuffin\Facade as f;
|
use League\FactoryMuffin\Facade as f;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AccountTypeTest
|
* Class BudgetTest
|
||||||
*/
|
*/
|
||||||
class BudgetTest extends TestCase
|
class BudgetTest extends TestCase
|
||||||
{
|
{
|
||||||
|
29
tests/unit/PiggyBankRepetitionTest.php
Normal file
29
tests/unit/PiggyBankRepetitionTest.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
use League\FactoryMuffin\Facade as f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PiggyBankRepetitionTest
|
||||||
|
*/
|
||||||
|
class PiggyBankRepetitionTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPiggyBankRepetitionScope()
|
||||||
|
{
|
||||||
|
$repetition = f::create('PiggyBankRepetition');
|
||||||
|
$start = clone $repetition->startdate;
|
||||||
|
$target = clone $repetition->targetdate;
|
||||||
|
|
||||||
|
$this->assertCount(1, PiggyBankRepetition::starts($start)->get());
|
||||||
|
$this->assertCount(1, PiggyBankRepetition::targets($target)->get());
|
||||||
|
}
|
||||||
|
}
|
27
tests/unit/PiggyBankTest.php
Normal file
27
tests/unit/PiggyBankTest.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
use League\FactoryMuffin\Facade as f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class PiggyBankTest
|
||||||
|
*/
|
||||||
|
class PiggyBankTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPiggyBankReminders()
|
||||||
|
{
|
||||||
|
$reminder = f::create('Reminder');
|
||||||
|
$piggyBank = f::create('PiggyBank');
|
||||||
|
$piggyBank->reminders()->save($reminder);
|
||||||
|
$this->assertCount(1, $piggyBank->reminders()->get());
|
||||||
|
}
|
||||||
|
}
|
38
tests/unit/ReminderTest.php
Normal file
38
tests/unit/ReminderTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
use League\FactoryMuffin\Facade as f;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ReminderTest
|
||||||
|
*/
|
||||||
|
class ReminderTest extends TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tearDown()
|
||||||
|
{
|
||||||
|
parent::tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testDateIs()
|
||||||
|
{
|
||||||
|
$reminder = f::create('Reminder');
|
||||||
|
$start = clone $reminder->startdate;
|
||||||
|
$end = clone $reminder->enddate;
|
||||||
|
$this->assertCount(1, Reminder::dateIs($start, $end)->get());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUser()
|
||||||
|
{
|
||||||
|
$user = f::create('User');
|
||||||
|
$reminder = f::create('Reminder');
|
||||||
|
$reminder->user_id = $user->id;
|
||||||
|
$reminder->save();
|
||||||
|
|
||||||
|
$this->assertEquals($reminder->user->id, $user->id);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user