Last active
June 7, 2016 20:20
-
-
Save jakelacey2012/1e57962dc9ee9fee17512c00380832a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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