diff --git a/app/tests/BudgetTest.php b/app/tests/BudgetTest.php index 8abafbc67c..a9b6348253 100644 --- a/app/tests/BudgetTest.php +++ b/app/tests/BudgetTest.php @@ -31,11 +31,17 @@ class BudgetTest extends TestCase } + public function tearDown() + { + Mockery::close(); + } + /** * @covers \Budget * */ - public function testBudgetModel() { + public function testBudgetModel() + { // create budget: $budget = f::create('Budget'); @@ -46,17 +52,14 @@ class BudgetTest extends TestCase $budget->transactionjournals()->save($t1); $budget->transactionjournals()->save($t2); - $this->assertCount(2,$budget->transactionjournals()->get()); - $this->assertEquals($budget->id,$t1->budgets()->first()->id); + $this->assertCount(2, $budget->transactionjournals()->get()); + $this->assertEquals($budget->id, $t1->budgets()->first()->id); } - - public function tearDown() - { - Mockery::close(); - } - + /** + * @covers \BudgetController::create + */ public function testCreate() { // test config: @@ -78,7 +81,9 @@ class BudgetTest extends TestCase } - + /** + * @covers \BudgetController::delete + */ public function testDelete() { @@ -99,6 +104,9 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + /** + * @covers \BudgetController::destroy + */ public function testDestroy() { $budget = f::create('Budget'); @@ -121,6 +129,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('success'); } + /** + * @covers \BudgetController::destroy + */ public function testDestroyFromDate() { $budget = f::create('Budget'); @@ -143,7 +154,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('success'); } - + /** + * @covers \BudgetController::edit + */ public function testEdit() { $budget = f::create('Budget'); @@ -164,6 +177,9 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + /** + * @covers \BudgetController::indexByBudget + */ public function testIndexByBudget() { $this->_repository->shouldReceive('get')->once()->andReturn([]); @@ -179,6 +195,9 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + /** + * @covers \BudgetController::indexByDate + */ public function testIndexByDate() { $collection = new Collection(); @@ -196,6 +215,9 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + /** + * @covers \BudgetController::show + */ public function testShowDefault() { $budget = f::create('Budget'); @@ -222,6 +244,9 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + /** + * @covers \BudgetController::show + */ public function testShowOutsideEnvelope() { $budget = f::create('Budget'); @@ -250,6 +275,10 @@ class BudgetTest extends TestCase $this->assertResponseOk(); } + + /** + * @covers \BudgetController::show + */ public function testShowWithRepetition() { $budget = f::create('Budget'); @@ -285,6 +314,9 @@ class BudgetTest extends TestCase } + /** + * @covers \BudgetController::store + */ public function testStore() { $budget = f::create('Budget'); @@ -300,6 +332,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('success'); } + /** + * @covers \BudgetController::store + */ public function testStoreComingFromDate() { $budget = f::create('Budget'); @@ -315,6 +350,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('success'); } + /** + * @covers \BudgetController::store + */ public function testStoreFails() { $budget = f::create('Budget'); @@ -329,6 +367,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('error'); } + /** + * @covers \BudgetController::store + */ public function testStoreWithRecreation() { $budget = f::create('Budget'); @@ -344,6 +385,9 @@ class BudgetTest extends TestCase $this->assertSessionHas('success'); } + /** + * @covers \BudgetController::update + */ public function testUpdate() { $budget = f::create('Budget'); @@ -366,6 +410,9 @@ class BudgetTest extends TestCase } + /** + * @covers \BudgetController::update + */ public function testUpdateFails() { $budget = f::create('Budget'); @@ -381,11 +428,14 @@ class BudgetTest extends TestCase $this->_repository->shouldReceive('update')->andReturn($budget); $this->action('POST', 'BudgetController@update', [$budget->id]); - $this->assertRedirectedToRoute('budgets.edit',$budget->id); + $this->assertRedirectedToRoute('budgets.edit', $budget->id); $this->assertSessionHas('error'); } + /** + * @covers \BudgetController::update + */ public function testUpdateFromDate() { $budget = f::create('Budget'); diff --git a/app/tests/CategoryTest.php b/app/tests/CategoryTest.php index 46b035b9c1..3fe4e0f578 100644 --- a/app/tests/CategoryTest.php +++ b/app/tests/CategoryTest.php @@ -17,93 +17,145 @@ class CategoryTest extends TestCase protected $_user; protected $_category; + /** + * + */ public function setUp() { parent::setUp(); Artisan::call('migrate'); Artisan::call('db:seed'); $this->_repository = $this->mock('Firefly\Storage\Category\CategoryRepositoryInterface'); - $this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface'); - $this->_user = m::mock('User', 'Eloquent'); + $this->_category = $this->mock('Firefly\Helper\Controllers\CategoryInterface'); + $this->_user = m::mock('User', 'Eloquent'); } + /** + * + */ public function tearDown() { Mockery::close(); } + + /** + * @covers \CategoryController::create + */ 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->assertResponseOk(); } + /** + * @covers \CategoryController::delete + */ public function testDelete() { $category = f::create('Category'); - // for successful binding: - Auth::shouldReceive('user')->andReturn($this->_user); - Auth::shouldReceive('check')->andReturn(true); + // test the view: + View::shouldReceive('make')->with('categories.delete')->once()->andReturn(m::self()) + ->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('email')->once()->andReturn('some@email'); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); $this->action('GET', 'CategoryController@delete', $category->id); $this->assertResponseOk(); } + /** + * @covers \CategoryController::destroy + */ public function testDestroy() { $category = f::create('Category'); - // for successful binding: - Auth::shouldReceive('user')->andReturn($this->_user); - Auth::shouldReceive('check')->andReturn(true); + // 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('email')->andReturn('some@email'); + + // fire the repository: $this->_repository->shouldReceive('destroy')->once()->andReturn(true); + // fire and test: $this->action('POST', 'CategoryController@destroy', $category->id); $this->assertRedirectedToRoute('categories.index'); $this->assertSessionHas('success'); } + /** + * @covers \CategoryController::edit + */ public function testEdit() { $category = f::create('Category'); - // for successful binding. - Auth::shouldReceive('user')->andReturn($this->_user); - Auth::shouldReceive('check')->andReturn(true); + // for successful binding with the category to edit: + 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('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->assertResponseOk(); } + /** + * @covers \CategoryController::index + */ public function testIndex() { - $category = f::create('Category'); + $category = f::create('Category'); $collection = new Collection(); $collection->add($category); $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->assertResponseOk(); } + /** + * @covers \CategoryController::show + */ public function testShow() { $category = f::create('Category'); - // for successful binding. - Auth::shouldReceive('user')->andReturn($this->_user); - Auth::shouldReceive('check')->andReturn(true); + // for successful binding with the category to show: + 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('email')->once()->andReturn($category->email); + $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); // + $this->session(['start' => new Carbon, 'end' => new Carbon]);