FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add "Examples" attribute example for associative keys by sascha-egerer · Pull Request #867 · Codeception/codeception.github.com · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
26 changes: 26 additions & 0 deletions docs/AdvancedUsage.md
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
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

Back | FazBrowse Home | New Git URL