Skip to content

Add "Examples" attribute example for associative keys #867

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
26 changes: 26 additions & 0 deletions docs/AdvancedUsage.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,32 @@ class EndpointCest

```

You can also use [named arguments](https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments) to get an example with associative keys.
```php
<?php

namespace Tests\Api;

use \Tests\Support\ApiTester;
use \Codeception\Attribute\Examples;
use \Codeception\Example;

class EndpointCest
{

#[Examples(url: '/api', expectedReponseCode: 200)]
#[Examples(url: '/api/protected', expectedReponseCode: 401)]
#[Examples(url: '/api/not-found-url', expectedReponseCode: 404)]
#[Examples(url: '/api/faulty', expectedReponseCode: 500)]
public function checkEndpoints(ApiTester $I, Example $example)
{
$I->sendGet($example['url']);
$I->seeResponseCodeIs($example['expectedReponseCode']);
}
}

```

## Example Annotation

As well as the `\Codeception\Attribute\Examples` attribute, available for Cest tests, the `@example` attribute allows you to
Expand Down