Created
May 26, 2023 12:22
-
-
Save filipfilipovich/e583dc8af60b160090a61589e57eaff1 to your computer and use it in GitHub Desktop.
BookRepository test file
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 | |
use App\Models\Book; | |
use App\Repositories\BookRepository; | |
beforeEach(function () { | |
$this->mockParameters = ['author' => 'Max Minimal']; | |
$this->mockBooksCollection = Book::factory(5)->create($this->mockParameters); | |
$this->bookRepository = new BookRepository(); | |
}); | |
it('can find books', function () { | |
$this->mockParameters['title'] = 'Sonic the Hedgehog'; | |
$this->mockBooksCollection = $this->mockBooksCollection->add(Book::factory()->create($this->mockParameters)); | |
expect($this->bookRepository->findBy($this->mockParameters))->count()->toBeOne(); | |
})->group('books'); // Assign 'books' group to this test | |
it('can filter out books', function () { | |
$this->mockBooksCollection = $this->mockBooksCollection | |
->add(Book::factory()->create([ | |
'author' => $mockAuthor = 'George R. R. Martin', | |
'title' => 'A Game of Thrones' | |
]))->add(Book::factory()->create([ | |
'author' => 'J. K. Rowling', | |
'title' => $mockTitle = 'Harry Potter and the Chamber of Secrets' | |
])); | |
$this->mockParameters = [ | |
'author' => $mockAuthor, | |
'title' => $mockTitle | |
]; | |
expect($this->bookRepository->filterBy($this->mockParameters)) | |
->toHaveCount(2) | |
->first()->author->toBe($mockAuthor) | |
->last()->title->toBe($mockTitle); | |
})->group('books'); // Assign 'books' group to this test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment