hi
I have called static method from my controller
how should I test this method ?
controller code
$this->validate($this->request, ["title"=>"required|unique:posts,title"]);
$inputs = $this->request->except(["_token"]);
// If the visible status was not on then we set it to 1
if ($this->request->visible == "on")
$inputs["visible"] = 1;
// If there was thumbnail
$inputs["thumbnail"] = Thumbnail::make($inputs["thumbnail"]);
$post_id = $this->post->create($inputs)->id;
// return back on http request
if (!$this->request->ajax()){
return redirect(action('PostController@getCreate'))
->with(["msg"=>"post has been created."]);
}else{
return json_encode(["post_id"=>$post_id, "part"=>"create"]);
}
If I were you I'd write a test just for the thumbnail class itself - just to make sure it's doing what you think, catches the errors you can think of etc. Then the 'higher' test for your controller action only really needs to check the basics.
For that error - do you have a use App\Whatever\Thumbnail at the top of your .php file?
For that error ...
yeah, I use classmap in my composer
"classmap": [
"database",
"app/helpers/class"
]
and yeah my class is located in that directory app/helpers/class, Thumbnail.php
and I access it in my controller with use Thumbnail;
I think i'll not face any problem to test the Thumbnail class itself, but what I wanted to test is the full controller method, integration test which the static thumbnail::make method should be part of it.
I know that thumbnail class is working pretty fine but I want to test it in different situations .