Bunch of new tests.

This commit is contained in:
James Cole 2014-08-09 13:21:24 +02:00
parent b898f906c3
commit 8eae1750c1
7 changed files with 295 additions and 29 deletions

View File

@ -6,6 +6,7 @@ class ReportController extends BaseController
public function index()
{
}
}

View File

@ -1,36 +1,37 @@
<?php
use Carbon\Carbon;
use LaravelBook\Ardent\Ardent;
/**
* RecurringTransaction
*
* @property integer $id
* @property integer $id
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon $updated_at
* @property integer $user_id
* @property string $name
* @property string $match
* @property float $amount_max
* @property float $amount_min
* @property integer $user_id
* @property string $name
* @property string $match
* @property float $amount_max
* @property float $amount_min
* @property \Carbon\Carbon $date
* @property boolean $active
* @property boolean $automatch
* @property string $repeat_freq
* @property integer $skip
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereId($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereName($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereMatch($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMax($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMin($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereDate($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereActive($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAutomatch($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereRepeatFreq($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereSkip($value)
* @property boolean $active
* @property boolean $automatch
* @property string $repeat_freq
* @property integer $skip
* @property-read \User $user
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereId($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereCreatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUpdatedAt($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereUserId($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereName($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereMatch($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMax($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAmountMin($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereDate($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereActive($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereAutomatch($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereRepeatFreq($value)
* @method static \Illuminate\Database\Query\Builder|\RecurringTransaction whereSkip($value)
*/
class RecurringTransaction extends Ardent
{
@ -49,12 +50,23 @@ class RecurringTransaction extends Ardent
'skip' => 'required|between:0,31',
];
public static $factory
= [
'user_id' => 'factory|User',
'name' => 'string',
'data' => 'string'
public static function factory()
{
$date = new Carbon;
return [
'user_id' => 'factory|User',
'name' => 'string',
'match' => 'string',
'amount_max' => 100,
'amount_min' => 50,
'date' => $date,
'active' => 1,
'automatch' => 1,
'repeat_freq' => 'monthly',
'skip' => 0,
];
}
public function getDates()
{

View File

@ -156,6 +156,9 @@ Route::group(['before' => 'auth'], function () {
Route::get('/recurring/edit/{recurring}',['uses' => 'RecurringController@edit','as' => 'recurring.edit']);
Route::get('/recurring/delete/{recurring}',['uses' => 'RecurringController@delete','as' => 'recurring.delete']);
// report controller:
Route::get('/reports',['uses' => 'ReportController@index','as' => 'reports.index']);
// transaction controller:
Route::get('/transactions/create/{what}', ['uses' => 'TransactionController@create', 'as' => 'transactions.create'])->where(['what' => 'withdrawal|deposit|transfer']);
Route::get('/transaction/show/{tj}',['uses' => 'TransactionController@show','as' => 'transactions.show']);

View File

@ -0,0 +1,53 @@
<?php
use Mockery as m;
/**
* Class PreferencesControllerTest
*/
class PreferencesControllerTest extends TestCase
{
protected $_user;
protected $_helper;
protected $_accounts;
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
$this->_user = m::mock('User', 'Eloquent');
$this->_helper = $this->mock('Firefly\Helper\Preferences\PreferencesHelperInterface');
$this->_accounts = $this->mock('Firefly\Storage\Account\AccountRepositoryInterface');
}
public function tearDown()
{
m::close();
}
public function testIndex()
{
$viewRange = $this->mock('Preference');
$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->action('GET', 'PreferencesController@index');
$this->assertResponseOk();
}
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->assertResponseStatus(302);
}
}

View File

@ -0,0 +1,161 @@
<?php
use Mockery as m;
use Zizaco\FactoryMuff\Facade\FactoryMuff as f;
/**
* Class RecurringControllerTest
*/
class RecurringControllerTest extends TestCase
{
protected $_user;
protected $_repository;
public function setUp()
{
parent::setUp();
Artisan::call('migrate');
Artisan::call('db:seed');
$this->_user = m::mock('User', 'Eloquent');
$this->_repository = $this->mock(
'Firefly\Storage\RecurringTransaction\RecurringTransactionRepositoryInterface'
);
}
public function tearDown()
{
m::close();
}
public function testCreate()
{
$this->action('GET', 'RecurringController@create');
$this->assertResponseOk();
}
public function testDelete()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$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@delete',$recurringTransaction->id);
$this->assertResponseOk();
}
public function testDestroy()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_repository->shouldReceive('destroy')->andReturn(true);
$this->action('POST', 'RecurringController@destroy',$recurringTransaction->id);
$this->assertResponseStatus(302);
}
public function testDestroyFails()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($recurringTransaction->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->_repository->shouldReceive('destroy')->andReturn(false);
$this->action('POST', 'RecurringController@destroy',$recurringTransaction->id);
$this->assertResponseStatus(302);
}
public function testEdit()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$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->assertResponseOk();
}
public function testIndex()
{
$this->_repository->shouldReceive('get')->andReturn([]);
$this->action('GET', 'RecurringController@index');
$this->assertResponseOk();
}
public function testShow()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('GET', 'RecurringController@show',$recurringTransaction->id);
$this->assertResponseOk();
}
public function testStore()
{
$recurringTransaction = f::create('RecurringTransaction');
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
$this->action('POST', 'RecurringController@store');
$this->assertResponseStatus(302);
}
public function testStoreRedirect()
{
$recurringTransaction = f::create('RecurringTransaction');
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
$this->action('POST', 'RecurringController@store',['create' => '1']);
$this->assertResponseStatus(302);
}
public function testStoreFails()
{
$recurringTransaction = f::create('RecurringTransaction');
unset($recurringTransaction->id);
$this->_repository->shouldReceive('store')->andReturn($recurringTransaction);
$this->action('POST', 'RecurringController@store',['create' => '1']);
$this->assertResponseStatus(302);
}
public function testUpdate()
{
$recurringTransaction = f::create('RecurringTransaction');
// for binding
Auth::shouldReceive('user')->andReturn($this->_user);
Auth::shouldReceive('check')->andReturn(true);
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('POST', 'RecurringController@update',$recurringTransaction->id);
$this->assertResponseOk();
}
}

View File

@ -0,0 +1,27 @@
<?php
use Mockery as m;
/**
* Class ReportControllerTest
*/
class ReportControllerTest extends TestCase
{
public function setUp()
{
parent::setUp();
}
public function tearDown()
{
m::close();
}
public function testIndex()
{
$this->action('GET', 'ReportController@index');
$this->assertResponseOk();
}
}

View File

@ -0,0 +1,9 @@
<?php
class UserControllerTest extends TestCase
{
public function testJemoeder()
{
$this->assertTrue(true);
}
}