diff --git a/docs/AdvancedUsage.md b/docs/AdvancedUsage.md index 9fd64570..828cbac1 100644 --- a/docs/AdvancedUsage.md +++ b/docs/AdvancedUsage.md @@ -344,9 +344,8 @@ class PageCest ## Before/After Attributes -You can control execution flow with `#[Before]` and `#[After]` attributes. You may move common actions -into protected (i.e. non-test) methods and invoke them before or after the test method by putting them into attributes. -When adding multiple `#[Before]` or `#[After]` attributes, methods are invoked in order from top to bottom. +You may move common actions into private/protected (i.e. non-test) methods and invoke them before or after the test method +by passing them as `#[Before]` and `#[After]` attributes. The referenced method needs to be in the same class as the public function. ```php amOnPage('/login'); $I->fillField('Username', 'miles'); @@ -367,21 +366,26 @@ class ModeratorCest { } #[Before('login')] - public function banUser(AcceptanceTester $I) + public function banUser(FunctionalTester $I): void { $I->amOnPage('/users/charlie-parker'); $I->see('Ban', '.button'); $I->click('Ban'); } - // you can specify multiple before and after methods: + // Multiple `#[Before]` or `#[After]` attributes are invoked in order from top to bottom: + #[Before('login')] + #[Before('cleanup')] + public function addUser(FunctionalTester $I): void + { + // ... + } + + // But you can also pass multiple methods in each attribute: #[Before('login', 'cleanup')] - #[After('logout', 'close')] - public function addUser(AcceptanceTester $I) + public function addUser(FunctionalTester $I): void { - $I->amOnPage('/users/charlie-parker'); - $I->see('Ban', '.button'); - $I->click('Ban'); + // ... } } ```