Skip to content

Instantly share code, notes, and snippets.

@jakelacey2012
Last active June 7, 2016 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakelacey2012/1e57962dc9ee9fee17512c00380832a1 to your computer and use it in GitHub Desktop.
Save jakelacey2012/1e57962dc9ee9fee17512c00380832a1 to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Task;
class TaskTest extends TestCase
{
use DatabaseMigrations;
const DATABASE = 'tasks';
const TASKNAME = 'Jake\'s tasks';
/**
* We insert a task into the database
* and see if we can fetch it.
*
* @return void
*/
public function testInsertTask()
{
$this->insertTaskDirect();
$this->seeTaskInDatabase();
}
/**
* Submit the form expecting it
* to create a task.
*
* @return void
*/
public function testSubmitTask()
{
$this->createTaskThroughForm()
->seePageIs();
$this->see(self::TASKNAME);
$this->seeTaskInDatabase();
}
/**
* Helper function to see task directly
* database
* @return void.
*/
private function seeTaskInDatabase()
{
$this->seeInDatabase(self::DATABASE,[
'id' => 1,
'name' => self::TASKNAME,
]);
}
/**
* Helper function to insert the
* task directly into the database.
*
* @return void.
*/
private function insertTaskDirect()
{
$task = new Task;
$task->name = self::TASKNAME;
$task->save();
}
/**
* helper function to create task
* through the form.
* @return [type] [description]
*/
private function createTaskThroughForm()
{
$this->visit('/')
->type(self::TASKNAME, 'name')
->press('Add Task');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment