I'm very new to tests. I have a webapp that stores books and informations about books.
If i call my route /store/
it trigger my store
methods and creating a new book into my database. This are the simplified methods:
Book.php
class file:
public function __construct() {
$this->bookService = new BookService();
}
public function store() {
$input = /* get post input values */
$this->createDatabaseEntry($input);
}
private function createDatabaseEntry($input) {
// Creating database entry
$book = /* bla bla */
$languages = $this->bookService->fetchLanguages($book->goodreads_id);
// And here i loop over the $languages and store them all in a extra table.
}
And here i have an other Service class BookService.php
:
public function fetchLanguages($goodreads_id) {
// Here i make an guzzle http call to a other service from goodreads.com
}
How do i test this without making a http request to goodreads? I need to verify the languages are in the database. I can work with fixtures for fetchLanguages()
. But how can i stub/mock (i don't know the correct term) this function?
I using Laravel and PHPUnit.
Aucun commentaire:
Enregistrer un commentaire