Created
June 5, 2017 13:40
-
-
Save mateusjatenee/4e704253a8b587981f6efc743b32568b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
class BookRepository | |
{ | |
protected $book; | |
public function __construct(Book $book) | |
{ | |
$this->book = $book; | |
} | |
public function getFlaggedBooks() | |
{ | |
return $this->book->flagged()->get(); | |
} | |
} | |
class BookRepositoryTest extends \TestCase | |
{ | |
public function setUp() | |
{ | |
parent::setUp(); | |
$this->repository = app(BookRepository::class); | |
} | |
/** @test */ | |
public function it_gets_flagged_books() | |
{ | |
// cria dois livros, um flagged e outro não | |
$book = factory(App\Book::class)->create(); | |
$flaggedBook = factory(App\Book::class)->create(['flagged' => 1]); | |
$books = $this->repository->getFlaggedBooks(); | |
// confirma que apenas o livro flagged foi retornado | |
$this->assertEquals(1, $books->count()); | |
$this->assertEquals($flaggedBook->fresh(), $books->first()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment