From 12d10b87e0c512d8d3637fbff6e5c380f45b4879 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 5 Jun 2025 18:01:20 +0200 Subject: [PATCH 1/2] Update AdvancedUsage.md: Before/After improvments Page: https://codeception.com/docs/AdvancedUsage#BeforeAfter-Attributes This is the most important change: > The referenced method needs to be in the same class as the public function. I took the info from here: https://github.com/Codeception/Codeception/blob/main/src/Codeception/Subscriber/BeforeAfterTest.php#L49 - please doublecheck. --- docs/AdvancedUsage.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/docs/AdvancedUsage.md b/docs/AdvancedUsage.md index 9fd64570e..91fcc5c8b 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 passed 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'); + // ... } } ``` From 6b8964ba65a17d240ea8b5b3979ac0b456a133dc Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Thu, 5 Jun 2025 18:02:24 +0200 Subject: [PATCH 2/2] Update AdvancedUsage.md --- docs/AdvancedUsage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/AdvancedUsage.md b/docs/AdvancedUsage.md index 91fcc5c8b..828cbac1e 100644 --- a/docs/AdvancedUsage.md +++ b/docs/AdvancedUsage.md @@ -345,7 +345,7 @@ class PageCest ## Before/After Attributes You may move common actions into private/protected (i.e. non-test) methods and invoke them before or after the test method -by passed them as `#[Before]` and `#[After]` attributes. The referenced method needs to be in the same class as the public function. +by passing them as `#[Before]` and `#[After]` attributes. The referenced method needs to be in the same class as the public function. ```php pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy