Some tests fixed. But messy! [skip ci]

This commit is contained in:
James Cole
2014-09-03 21:12:51 +02:00
parent 9136b50e3c
commit 07e6b33095
2 changed files with 132 additions and 30 deletions

View File

@@ -31,11 +31,17 @@ class BudgetTest extends TestCase
} }
public function tearDown()
{
Mockery::close();
}
/** /**
* @covers \Budget * @covers \Budget
* *
*/ */
public function testBudgetModel() { public function testBudgetModel()
{
// create budget: // create budget:
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -46,17 +52,14 @@ class BudgetTest extends TestCase
$budget->transactionjournals()->save($t1); $budget->transactionjournals()->save($t1);
$budget->transactionjournals()->save($t2); $budget->transactionjournals()->save($t2);
$this->assertCount(2,$budget->transactionjournals()->get()); $this->assertCount(2, $budget->transactionjournals()->get());
$this->assertEquals($budget->id,$t1->budgets()->first()->id); $this->assertEquals($budget->id, $t1->budgets()->first()->id);
} }
/**
public function tearDown() * @covers \BudgetController::create
{ */
Mockery::close();
}
public function testCreate() public function testCreate()
{ {
// test config: // test config:
@@ -78,7 +81,9 @@ class BudgetTest extends TestCase
} }
/**
* @covers \BudgetController::delete
*/
public function testDelete() public function testDelete()
{ {
@@ -99,6 +104,9 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::destroy
*/
public function testDestroy() public function testDestroy()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -121,6 +129,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \BudgetController::destroy
*/
public function testDestroyFromDate() public function testDestroyFromDate()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -143,7 +154,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \BudgetController::edit
*/
public function testEdit() public function testEdit()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -164,6 +177,9 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::indexByBudget
*/
public function testIndexByBudget() public function testIndexByBudget()
{ {
$this->_repository->shouldReceive('get')->once()->andReturn([]); $this->_repository->shouldReceive('get')->once()->andReturn([]);
@@ -179,6 +195,9 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::indexByDate
*/
public function testIndexByDate() public function testIndexByDate()
{ {
$collection = new Collection(); $collection = new Collection();
@@ -196,6 +215,9 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::show
*/
public function testShowDefault() public function testShowDefault()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -222,6 +244,9 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::show
*/
public function testShowOutsideEnvelope() public function testShowOutsideEnvelope()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -250,6 +275,10 @@ class BudgetTest extends TestCase
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \BudgetController::show
*/
public function testShowWithRepetition() public function testShowWithRepetition()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -285,6 +314,9 @@ class BudgetTest extends TestCase
} }
/**
* @covers \BudgetController::store
*/
public function testStore() public function testStore()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -300,6 +332,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \BudgetController::store
*/
public function testStoreComingFromDate() public function testStoreComingFromDate()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -315,6 +350,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \BudgetController::store
*/
public function testStoreFails() public function testStoreFails()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -329,6 +367,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('error'); $this->assertSessionHas('error');
} }
/**
* @covers \BudgetController::store
*/
public function testStoreWithRecreation() public function testStoreWithRecreation()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -344,6 +385,9 @@ class BudgetTest extends TestCase
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \BudgetController::update
*/
public function testUpdate() public function testUpdate()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -366,6 +410,9 @@ class BudgetTest extends TestCase
} }
/**
* @covers \BudgetController::update
*/
public function testUpdateFails() public function testUpdateFails()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');
@@ -381,11 +428,14 @@ class BudgetTest extends TestCase
$this->_repository->shouldReceive('update')->andReturn($budget); $this->_repository->shouldReceive('update')->andReturn($budget);
$this->action('POST', 'BudgetController@update', [$budget->id]); $this->action('POST', 'BudgetController@update', [$budget->id]);
$this->assertRedirectedToRoute('budgets.edit',$budget->id); $this->assertRedirectedToRoute('budgets.edit', $budget->id);
$this->assertSessionHas('error'); $this->assertSessionHas('error');
} }
/**
* @covers \BudgetController::update
*/
public function testUpdateFromDate() public function testUpdateFromDate()
{ {
$budget = f::create('Budget'); $budget = f::create('Budget');

View File

@@ -17,93 +17,145 @@ class CategoryTest extends TestCase
protected $_user; protected $_user;
protected $_category; protected $_category;
/**
*
*/
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();
Artisan::call('migrate'); Artisan::call('migrate');
Artisan::call('db:seed'); Artisan::call('db:seed');
$this->_repository = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface'); $this->_repository = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface');
$this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface'); $this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface');
$this->_user = m::mock('User', 'Eloquent'); $this->_user = m::mock('User', 'Eloquent');
} }
/**
*
*/
public function tearDown() public function tearDown()
{ {
Mockery::close(); Mockery::close();
} }
/**
* @covers \CategoryController::create
*/
public function testCreate() public function testCreate()
{ {
// test the view:
View::shouldReceive('make')->with('categories.create')->once()->andReturn(m::self())
->shouldReceive('with')->with('title', 'Create a new category')->once();
$this->action('GET', 'CategoryController@create'); $this->action('GET', 'CategoryController@create');
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \CategoryController::delete
*/
public function testDelete() public function testDelete()
{ {
$category = f::create('Category'); $category = f::create('Category');
// for successful binding: // test the view:
Auth::shouldReceive('user')->andReturn($this->_user); View::shouldReceive('make')->with('categories.delete')->once()->andReturn(m::self())
Auth::shouldReceive('check')->andReturn(true); ->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self())
->shouldReceive('with')->with('title', 'Delete category "' . $category->name . '"')->once();
// for successful binding with the category to delete:
Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
$this->action('GET', 'CategoryController@delete', $category->id); $this->action('GET', 'CategoryController@delete', $category->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \CategoryController::destroy
*/
public function testDestroy() public function testDestroy()
{ {
$category = f::create('Category'); $category = f::create('Category');
// for successful binding: // for successful binding with the category to delete:
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
// fire the repository:
$this->_repository->shouldReceive('destroy')->once()->andReturn(true); $this->_repository->shouldReceive('destroy')->once()->andReturn(true);
// fire and test:
$this->action('POST', 'CategoryController@destroy', $category->id); $this->action('POST', 'CategoryController@destroy', $category->id);
$this->assertRedirectedToRoute('categories.index'); $this->assertRedirectedToRoute('categories.index');
$this->assertSessionHas('success'); $this->assertSessionHas('success');
} }
/**
* @covers \CategoryController::edit
*/
public function testEdit() public function testEdit()
{ {
$category = f::create('Category'); $category = f::create('Category');
// for successful binding. // for successful binding with the category to edit:
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
// test the view:
View::shouldReceive('make')->with('categories.edit')->once()->andReturn(m::self())
->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self())
->shouldReceive('with')->with('title', 'Edit category "' . $category->name . '"')->once();
$this->action('GET', 'CategoryController@edit', $category->id); $this->action('GET', 'CategoryController@edit', $category->id);
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \CategoryController::index
*/
public function testIndex() public function testIndex()
{ {
$category = f::create('Category'); $category = f::create('Category');
$collection = new Collection(); $collection = new Collection();
$collection->add($category); $collection->add($category);
$this->_repository->shouldReceive('get')->with()->once()->andReturn($collection); $this->_repository->shouldReceive('get')->with()->once()->andReturn($collection);
View::shouldReceive('make')->with('categories.index')->once()->andReturn(m::self())
->shouldReceive('with')->with('categories', $collection)->once()->andReturn(m::self())
->shouldReceive('with')->with('title', 'All your categories')->once();
$this->action('GET', 'CategoryController@index'); $this->action('GET', 'CategoryController@index');
$this->assertResponseOk(); $this->assertResponseOk();
} }
/**
* @covers \CategoryController::show
*/
public function testShow() public function testShow()
{ {
$category = f::create('Category'); $category = f::create('Category');
// for successful binding. // for successful binding with the category to show:
Auth::shouldReceive('user')->andReturn($this->_user); Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3);
Auth::shouldReceive('check')->andReturn(true); Auth::shouldReceive('check')->andReturn(true)->between(1, 2);
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id);
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($category->email); $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); //
$this->session(['start' => new Carbon, 'end' => new Carbon]); $this->session(['start' => new Carbon, 'end' => new Carbon]);