Skip to content

Instantly share code, notes, and snippets.

@Anan5a
Created December 28, 2017 14:19
Show Gist options
  • Save Anan5a/f443a05997ce64a33b43650c9955d23c to your computer and use it in GitHub Desktop.
Save Anan5a/f443a05997ce64a33b43650c9955d23c to your computer and use it in GitHub Desktop.
<?php
//test method
public function test_store_should_save_new_books_in_database()
{
$this->post('/books',[
'title'=>'A story of rush',
'description'=>'A story of rush is a book of imagination. There\'s no existence of the book in real world!',
'author'=>'H.G XYZ',
'isbn'=>'16372916273',
'created_at'=>time(),
'updated_at'=>time()
]);
$this
->seeStatusCode(201)
->seeJson(['created'=>true])
->seeInDatabase('books',['title'=>'A story of rush']);
}
//Controller method
public function store(Request $request)
{
try{
$book = Book::create($request->all());
}catch(\Exception $e){
var_dump(($e->getMessage()));
}
return response()->json(['created'=>true],201);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment