vendredi 27 mars 2015

Testing methods and controllers with Laravel 5 [phpunit]

I am tring to make test for my project, could someone show me example how to write tests or give me some good video course to learn testing.


In my example I am tring to test this part:



public function getProjectsForUser(){
if(Auth::user() -> admin_id == NULL){
$this->id = Auth::user() -> id;
}else{
$this->id = Auth::user() -> admin_id;
}
$projects = User::findOrFail(Auth::user() -> id)->projects()->where('admin_id', '=', $this->id)->get();

$role = User::findOrFail(Auth::user() -> id)->roles;

$users = User::where('admin_id', '=', $this->id)->lists('name','id');

return array('projects' => $projects,'users' => $users,'roles' => $role );
}


It was my model Project.php


Here is my PorojectController:



public function project(Project $projects){
$this -> projects = $projects ->getProjectsForUser();
return view('projects',$this -> projects);
}


Here is my test to check if user logged...



public function testHome()
{
$this->be(User::find(1));
$response = $this->call('GET', '/projects');
//CHECK IF AUTH USER
$this->assertTrue($response->isOk());

}


Now I need to check if I get right values inside array, for $project, $role, $users.


Aucun commentaire:

Enregistrer un commentaire