Skip to content

Instantly share code, notes, and snippets.

@filipfilipovich
Created May 16, 2023 10:58
Show Gist options
  • Save filipfilipovich/d21c92f59cafd0a18d75f6a341a95207 to your computer and use it in GitHub Desktop.
Save filipfilipovich/d21c92f59cafd0a18d75f6a341a95207 to your computer and use it in GitHub Desktop.
Pest hooks example
<?php
beforeAll(function () {
// Executes first, before any of tests are run
// Eg. can be used to set up a testing database
});
beforeEach(function () {
$this->bookRepository = new BookRepository();
});
it('creates books', function () {
$book = $this->bookRepository->create();
expect($book)->toBeInstanceOf(Book::class);
});
afterEach(function () {
$this->bookRepository->reset();
});
afterAll(function () {
// Executes last, after all tests are done
// NOTE: $this object CAN NOT be used inside beforeAll() and afterAll() methods
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment