Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyBel authored Jan 31, 2023
1 parent 5663521 commit 0a5501e
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,39 @@ The recommended way to install PhpInvariant is through Composer

# Quick start example
1. Create a folder `invariants`
2. Create class SimpleTest inside this folder
2. Create Test class inside this folder
3. Run command `vendor/bin/phpinvariant run --dir=invariants`

# How to write invariant test
Rules:
1. Сlass name must end with 'Test'
1. Class must extends `BaseInvariantTest`
1. Each public method with a name 'test...' will be launched

## Generators
Generators generate random data for invariants checking. To use a generator for a variable write the attribute for variable

## Finish conditions
These conditions are used to determine when to end the test execution. To determine finish condition write the attribute for test method

## Example

```php
class SimpleTest extends BaseInvariantTest
{
#[FinishCount(10)]
public function testDivision(#[IntegerGenerator(99, 101)] int $x)
public function testDivision(#[IntegerGenerator(50, 101)] int $x)
{
// fail when $x=101
$this->assertTrue($x < 100);
}
}
```
3. Run command `vendor/bin/phpinvariant run --dir=invariants`
Explanation:
* `#[FinishCount(10)]` - run test 10 times
* `#[IntegerGenerator(50, 101)] int $x` - randomly generate integer `$x` in [50, 101]




# Documentation

0 comments on commit 0a5501e

Please sign in to comment.