Some code cleanup and fixes.

This commit is contained in:
James Cole
2014-08-10 11:30:14 +02:00
parent c50a9b4b04
commit fbd056104a
27 changed files with 145 additions and 91 deletions

View File

@@ -163,7 +163,7 @@ class AccountControllerTest extends TestCase
public function testStoreFails()
{
$account = f::create('Account');
unset($account->id);
unset($account->name);
$this->_repository->shouldReceive('store')->andReturn($account);
$this->action('POST', 'AccountController@store');
$this->assertRedirectedToRoute('accounts.create');

View File

@@ -5,7 +5,8 @@ use Illuminate\Database\Eloquent\Collection;
use Mockery as m;
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
class BudgetControllerTest extends TestCase {
class BudgetControllerTest extends TestCase
{
protected $_repository;
protected $_user;
protected $_budgets;
@@ -77,7 +78,7 @@ class BudgetControllerTest extends TestCase {
Event::shouldReceive('fire')->once()->with('budgets.change');
$this->_repository->shouldReceive('destroy')->once()->andReturn(true);
$this->action('POST', 'BudgetController@destroy', [$budget->id,'from' => 'date']);
$this->action('POST', 'BudgetController@destroy', [$budget->id, 'from' => 'date']);
$this->assertRedirectedToRoute('budgets.index');
$this->assertSessionHas('success');
}
@@ -140,7 +141,6 @@ class BudgetControllerTest extends TestCase {
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
$this->session(['start' => new Carbon, 'end' => new Carbon]);
$this->_budgets->shouldReceive('organizeRepetitions')->once()->andReturn([]);
@@ -159,11 +159,10 @@ class BudgetControllerTest extends TestCase {
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
$this->session(['start' => new Carbon, 'end' => new Carbon]);
$this->_budgets->shouldReceive('outsideRepetitions')->once()->andReturn([]);
$this->action('GET', 'BudgetController@show', [$budget->id,'noenvelope' => 'true']);
$this->action('GET', 'BudgetController@show', [$budget->id, 'noenvelope' => 'true']);
$this->assertResponseOk();
}
@@ -178,11 +177,10 @@ class BudgetControllerTest extends TestCase {
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($budget->email);
$this->session(['start' => new Carbon, 'end' => new Carbon]);
// $this->_budgets->shouldReceive('show')->once()->andReturn([]);
$arr = [0 => ['limitrepetition' => null, 'limit' => null,'date' => '']];
$arr = [0 => ['limitrepetition' => null, 'limit' => null, 'date' => '']];
$this->_budgets->shouldReceive('organizeRepetition')->once()->andReturn($arr);
$this->action('GET', 'BudgetController@show', [$budget->id, 'rep' => '1']);
$this->assertResponseOk();
@@ -195,20 +193,21 @@ class BudgetControllerTest extends TestCase {
$this->action('POST', 'BudgetController@store');
$this->assertRedirectedToRoute('budgets.index.budget');
}
public function testStoreFromDate()
{
$budget = f::create('Budget');
$this->_repository->shouldReceive('store')->andReturn($budget);
$this->action('POST', 'BudgetController@store',['from' => 'date']);
$this->action('POST', 'BudgetController@store', ['from' => 'date']);
$this->assertRedirectedToRoute('budgets.index');
}
public function testStoreFails()
{
$budget = f::create('Budget');
unset($budget->id);
unset($budget->name);
$this->_repository->shouldReceive('store')->andReturn($budget);
$this->action('POST', 'BudgetController@store',['from'=>'budget']);
$this->action('POST', 'BudgetController@store', ['from' => 'budget']);
$this->assertRedirectedToRoute('budgets.create');
}
@@ -216,8 +215,8 @@ class BudgetControllerTest extends TestCase {
{
$budget = f::create('Budget');
$this->_repository->shouldReceive('store')->andReturn($budget);
$this->action('POST', 'BudgetController@store', ['from' => 'budget','create' => '1']);
$this->assertRedirectedToRoute('budgets.create',['from' => 'budget']);
$this->action('POST', 'BudgetController@store', ['from' => 'budget', 'create' => '1']);
$this->assertRedirectedToRoute('budgets.create', ['from' => 'budget']);
}
public function testUpdate()
@@ -243,7 +242,7 @@ class BudgetControllerTest extends TestCase {
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($budget->user_id);
$this->_repository->shouldReceive('update')->andReturn($budget);
$this->action('POST', 'BudgetController@update', [$budget->id,'from' => 'date']);
$this->action('POST', 'BudgetController@update', [$budget->id, 'from' => 'date']);
$this->assertRedirectedToRoute('budgets.index');
}

View File

@@ -118,8 +118,6 @@ class CategoryControllerTest extends TestCase
$this->session(['start' => new Carbon, 'end' => new Carbon]);
$this->_category->shouldReceive('journalsInRange')->once()->andReturn([]);
$this->action('GET', 'CategoryController@show', $category->id);
$this->assertResponseOk();
@@ -136,7 +134,7 @@ class CategoryControllerTest extends TestCase
public function testStoreFails()
{
$category = f::create('Category');
unset($category->id);
unset($category->name);
$this->_repository->shouldReceive('store')->andReturn($category);
$this->action('POST', 'CategoryController@store');
$this->assertRedirectedToRoute('categories.create');

View File

@@ -86,7 +86,7 @@ class ChartControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($account->user_id);
$this->_accounts->shouldReceive('findByName')->andReturn($account);
$this->_charts->shouldReceive('accountDailySummary')->once()->andReturn(['rows' => [],'sum' => 0]);
$this->_charts->shouldReceive('accountDailySummary')->once()->andReturn(['rows' => [], 'sum' => 0]);
$this->call('GET', 'chart/home/info/' . $account->name . '/01/08/2014');
$this->assertResponseOk();

View File

@@ -1,5 +1,6 @@
<?php
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
/**
* Class JsonControllerTest
*/

View File

@@ -126,6 +126,7 @@ class LimitControllerTest extends TestCase
$this->_limits->shouldReceive('store')->once()->andReturn($limit);
$this->action('POST', 'LimitController@store');
$this->assertRedirectedToRoute('budgets.index.budget');
$this->assertResponseStatus(302);
}
@@ -137,10 +138,12 @@ class LimitControllerTest extends TestCase
$limit->save();
$limitrepetition = f::create('LimitRepetition');
$limit->limitrepetitions()->save($limitrepetition);
unset($limit->id);
unset($limit->startdate);
unset($limit->component_id);
$this->_limits->shouldReceive('store')->once()->andReturn($limit);
$this->action('POST', 'LimitController@store', [$budget->id, 'from' => 'date']);
$this->action('POST', 'LimitController@store', $budget->id);
$this->assertResponseStatus(302);
}

View File

@@ -99,7 +99,7 @@ class PiggybankControllerTest extends TestCase
$two->account()->associate($aOne);
$three = f::create('Piggybank');
$three->account()->associate($aTwo);
$this->_piggybanks->shouldReceive('get')->andReturn([$one,$two,$three]);
$this->_piggybanks->shouldReceive('get')->andReturn([$one, $two, $three]);
$this->_piggybanks->shouldReceive('count')->andReturn(1);
$this->action('GET', 'PiggybankController@index');
$this->assertResponseOk();
@@ -131,7 +131,7 @@ class PiggybankControllerTest extends TestCase
public function testStoreFails()
{
$piggyBank = f::create('Piggybank');
unset($piggyBank->id);
unset($piggyBank->amount);
$this->_piggybanks->shouldReceive('store')->andReturn($piggyBank);
$this->action('POST', 'PiggybankController@store');
$this->assertResponseStatus(302);
@@ -141,7 +141,7 @@ class PiggybankControllerTest extends TestCase
{
$piggyBank = f::create('Piggybank');
$this->_piggybanks->shouldReceive('store')->andReturn($piggyBank);
$this->action('POST', 'PiggybankController@store',['create' => '1']);
$this->action('POST', 'PiggybankController@store', ['create' => '1']);
$this->assertResponseStatus(302);
}
@@ -163,6 +163,25 @@ class PiggybankControllerTest extends TestCase
$this->assertResponseStatus(302);
}
public function testUpdateFails()
{
$piggyBank = f::create('Piggybank');
unset($piggyBank->amount);
$this->_piggybanks->shouldReceive('update')->andReturn($piggyBank);
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
$piggyBank->account()->first()->user_id
);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('POST', 'PiggybankController@update', $piggyBank->id);
$this->assertResponseStatus(302);
}
public function testUpdateAmount()
{
$piggyBank = f::create('Piggybank');

View File

@@ -35,8 +35,8 @@ class PreferencesControllerTest extends TestCase
$viewRange->shouldReceive('getAttribute')->with('data')->andReturn('1M');
$this->_accounts->shouldReceive('getDefault')->andReturn([]);
$this->_helper->shouldReceive('get')->with('viewRange','1M')->andReturn($viewRange);
$this->_helper->shouldReceive('get')->with('frontpageAccounts',[])->andReturn([]);
$this->_helper->shouldReceive('get')->with('viewRange', '1M')->andReturn($viewRange);
$this->_helper->shouldReceive('get')->with('frontpageAccounts', [])->andReturn([]);
$this->action('GET', 'PreferencesController@index');
@@ -45,9 +45,9 @@ class PreferencesControllerTest extends TestCase
public function testPostIndex()
{
$this->_helper->shouldReceive('set')->with('frontpageAccounts',[1]);
$this->_helper->shouldReceive('set')->with('viewRange','1M');
$this->action('POST', 'PreferencesController@postIndex',['frontpageAccounts' => [1],'viewRange' => '1M']);
$this->_helper->shouldReceive('set')->with('frontpageAccounts', [1]);
$this->_helper->shouldReceive('set')->with('viewRange', '1M');
$this->action('POST', 'PreferencesController@postIndex', ['frontpageAccounts' => [1], 'viewRange' => '1M']);
$this->assertResponseStatus(302);
}
}

View File

@@ -92,7 +92,7 @@ class ProfileControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_user->shouldReceive('getAttribute')->with('password')->andReturn('Blablabla');
$this->action('POST', 'ProfileController@postChangePassword',['old' => '']);
$this->action('POST', 'ProfileController@postChangePassword', ['old' => '']);
$this->assertResponseOk();
}

View File

@@ -44,7 +44,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
$this->action('GET', 'RecurringController@delete',$recurringTransaction->id);
$this->action('GET', 'RecurringController@delete', $recurringTransaction->id);
$this->assertResponseOk();
}
@@ -59,7 +59,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_repository->shouldReceive('destroy')->andReturn(true);
$this->action('POST', 'RecurringController@destroy',$recurringTransaction->id);
$this->action('POST', 'RecurringController@destroy', $recurringTransaction->id);
$this->assertResponseStatus(302);
}
@@ -74,7 +74,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_repository->shouldReceive('destroy')->andReturn(false);
$this->action('POST', 'RecurringController@destroy',$recurringTransaction->id);
$this->action('POST', 'RecurringController@destroy', $recurringTransaction->id);
$this->assertResponseStatus(302);
}
@@ -88,7 +88,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
$this->action('GET', 'RecurringController@edit',$recurringTransaction->id);
$this->action('GET', 'RecurringController@edit', $recurringTransaction->id);
$this->assertResponseOk();
}
@@ -112,7 +112,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('GET', 'RecurringController@show',$recurringTransaction->id);
$this->action('GET', 'RecurringController@show', $recurringTransaction->id);
$this->assertResponseOk();
}
@@ -130,17 +130,18 @@ class RecurringControllerTest extends TestCase
$recurringTransaction = f::create('RecurringTransaction');
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
$this->action('POST', 'RecurringController@store',['create' => '1']);
$this->action('POST', 'RecurringController@store', ['create' => '1']);
$this->assertResponseStatus(302);
}
public function testStoreFails()
{
$recurringTransaction = f::create('RecurringTransaction');
unset($recurringTransaction->id);
unset($recurringTransaction->active);
unset($recurringTransaction->automatch);
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
$this->action('POST', 'RecurringController@store',['create' => '1']);
$this->action('POST', 'RecurringController@store', ['create' => '1']);
$this->assertResponseStatus(302);
}
@@ -155,7 +156,7 @@ class RecurringControllerTest extends TestCase
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('POST', 'RecurringController@update',$recurringTransaction->id);
$this->action('POST', 'RecurringController@update', $recurringTransaction->id);
$this->assertResponseOk();
}
}

View File

@@ -242,7 +242,7 @@ class TransactionControllerTest extends TestCase
public function testStoreFails()
{
$journal = f::create('TransactionJournal');
unset($journal->id);
unset($journal->description);
$this->_repository->shouldReceive('store')->andReturn($journal);