Mar 7, 2016
0
Level 1
How to test function store with PhpSpec
I have just studied phpSpec, I have a function store with validate and saving on database. But I don't know how to test it. Can you help to write test it with PhpSpec? Thanks alot Here is my function:
public function store(Request $request)
{
$validator = Validator::make($request->all(), [
'name' => 'required',
'alias' => 'regex:/^[a-z0-9\-]+/|unique:article_categories',
'image' => 'string',
'description' => 'string',
'parent_id' => 'numeric',
'order' => 'numeric',
'status' => 'numeric',
]);
if ($validator->fails()) {
return response()->json($validator->errors());
}
$category = Category::create($request->all());
return response()->json($category);
}
Please or to participate in this conversation.