Skip to content

Commit 6494540

Browse files
oconnedkDaniel O'ConnellNaktibalda
authored
Document missing @example annotation (#662)
* Document the @example annotation for Unit tests * Document missing @example annotation Since [`@testWith`](Codeception/Codeception#6575) is not supported as of `5.0`, document the `@example` codeception annotation (note: annotation, not the attribute, which is already documented). * @example update for newer auto-generated docs * Correct the name of Examples attribute * Correct the name of Examples attribute Co-authored-by: Daniel O'Connell <daniel.oconnell@fitchlearning.com> Co-authored-by: Gintautas Miselis <gintautas@miselis.lt>
1 parent cf5c3c0 commit 6494540

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

docs/AdvancedUsage.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,32 @@ class EndpointCest
265265

266266
```
267267

268+
## Example Annotation
269+
270+
As well as the `\Codeception\Attribute\Examples` attribute, available for Cest tests, the `@example` attribute allows you to
271+
inject test parameters in place of an actual [DataProvider](#dataprovider-attribute) for Unit tests.
272+
273+
```php
274+
<?php
275+
namespace Tests\Unit;
276+
277+
class ExampleTest extends \Codeception\Test\Unit
278+
{
279+
/**
280+
* @param mixed $value
281+
* @example [3.14159]
282+
* @example ["a string"]
283+
* @example [["this", "is", "an", "array"]]
284+
* @example [{"associative": "array"}]
285+
*/
286+
public function testExample($value)
287+
{
288+
$this->assertNotEmpty($value, "Expected a value");
289+
}
290+
}
291+
```
292+
> `@testWith`: as of [Codeception 5.0](https://github.com/Codeception/Codeception/pull/6491), PHPUnit's `@testWith` is no longer supported. `@example` is a good, almost drop-in, replacement.
293+
268294
## DataProvider Attribute
269295

270296
You can also use the `@dataProvider` annotation for creating dynamic examples for [Cest classes](#Cest-Classes), using a **protected method** for providing example data:

guides/07-AdvancedUsage.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,32 @@ class EndpointCest
258258

259259
```
260260

261+
## Example Annotation
262+
263+
As well as the `\Codeception\Attribute\Examples` attribute, available for Cest tests, the `@example` attribute allows you to
264+
inject test parameters in place of an actual [DataProvider](#dataprovider-attribute) for Unit tests.
265+
266+
```php
267+
<?php
268+
namespace Tests\Unit;
269+
270+
class ExampleTest extends \Codeception\Test\Unit
271+
{
272+
/**
273+
* @param mixed $value
274+
* @example [3.14159]
275+
* @example ["a string"]
276+
* @example [["this", "is", "an", "array"]]
277+
* @example [{"associative": "array"}]
278+
*/
279+
public function testExample($value)
280+
{
281+
$this->assertNotEmpty($value, "Expected a value");
282+
}
283+
}
284+
```
285+
> `@testWith`: as of [Codeception 5.0](https://github.com/Codeception/Codeception/pull/6491), PHPUnit's `@testWith` is no longer supported. `@example` is a good, almost drop-in, replacement.
286+
261287
## DataProvider Attribute
262288

263289
You can also use the `@dataProvider` annotation for creating dynamic examples for [Cest classes](#Cest-Classes), using a **protected method** for providing example data:

0 commit comments

Comments
 (0)