Skip to content

Instantly share code, notes, and snippets.

@mateusjatenee
Created June 5, 2017 13:40
Show Gist options
  • Save mateusjatenee/4e704253a8b587981f6efc743b32568b to your computer and use it in GitHub Desktop.
Save mateusjatenee/4e704253a8b587981f6efc743b32568b to your computer and use it in GitHub Desktop.
<?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