Created
December 28, 2017 14:19
-
-
Save Anan5a/f443a05997ce64a33b43650c9955d23c 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 | |
//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