Created
May 16, 2023 10:58
-
-
Save filipfilipovich/d21c92f59cafd0a18d75f6a341a95207 to your computer and use it in GitHub Desktop.
Pest hooks example
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 | |
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