Tests for budget controller.

This commit is contained in:
James Cole
2014-08-02 15:23:29 +02:00
parent 913b5fd267
commit 30b589d040
8 changed files with 352 additions and 190 deletions

View File

@@ -12,9 +12,18 @@ use Carbon\Carbon;
interface BudgetRepositoryInterface
{
/**
* @param $data
*
* @return mixed
*/
public function getAsSelectList();
public function destroy(\Budget $budget);
/**
* @param $budgetId
*
* @return mixed
*/
public function find($budgetId);
/**
* @return mixed
@@ -22,11 +31,17 @@ interface BudgetRepositoryInterface
public function get();
/**
* @param $data
* @return mixed
*/
public function getAsSelectList();
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function update($data);
public function getWithRepetitionsInPeriod(Carbon $date, $range);
/**
* @param $data
@@ -40,21 +55,6 @@ interface BudgetRepositoryInterface
*
* @return mixed
*/
public function destroy($budgetId);
/**
* @param $budgetId
*
* @return mixed
*/
public function find($budgetId);
/**
* @param Carbon $date
* @param $range
*
* @return mixed
*/
public function getWithRepetitionsInPeriod(Carbon $date, $range);
public function update(\Budget $budget, $data);
}

View File

@@ -12,6 +12,13 @@ use Carbon\Carbon;
class EloquentBudgetRepository implements BudgetRepositoryInterface
{
public function destroy(\Budget $budget)
{
$budget->delete();
return true;
}
/**
* @param $budgetId
*
@@ -46,37 +53,6 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $set;
}
/**
* @param $data
*
* @return mixed
*/
public function update($data)
{
$budget = $this->find($data['id']);
if ($budget) {
// update account accordingly:
$budget->name = $data['name'];
if ($budget->validate()) {
$budget->save();
}
}
return $budget;
}
public function destroy($budgetId)
{
$budget = $this->find($budgetId);
if ($budget) {
$budget->delete();
return true;
}
return false;
}
/**
* @return array|mixed
*/
@@ -161,4 +137,20 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $budget;
}
/**
* @param $data
*
* @return mixed
*/
public function update(\Budget $budget, $data)
{
// update account accordingly:
$budget->name = $data['name'];
if ($budget->validate()) {
$budget->save();
}
return $budget;
}
}