Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Update AdvancedUsage.md: Before/After improvements#888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
ThomasLandauer wants to merge2 commits intoCodeception:master
base:master
Choose a base branch
Loading
fromThomasLandauer:patch-2
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletionsdocs/AdvancedUsage.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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
<?php
Expand All@@ -356,9 +355,9 @@ use \Tests\Support\FunctionalTester;
use Codeception\Attribute\Before;
use Codeception\Attribute\After;

class ModeratorCest {

protected function login(AcceptanceTester $I)
finalclass ModeratorCest
{
protected function login(FunctionalTester $I): void
{
$I->amOnPage('/login');
$I->fillField('Username', 'miles');
Expand All@@ -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');
// ...
}
}
```
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp