Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Dgame authored Apr 4, 2018
1 parent f8a1a10 commit 93e29b5
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ensure('foo')->isString()->isNotEqualTo('bar');

### pattern
```php
ensure('test@foo')->isString()->match('#^[a-z]+@\w{3}$#i');
ensure('test@foo')->isString()->matches('#^[a-z]+@\w{3}$#i');
ensure('FooBar')->isString()->beginsWith('Fo');
ensure('FooBar')->isString()->endsWith('ar');
```
Expand Down Expand Up @@ -142,20 +142,31 @@ You can also specify your own Exception messages:
ensure(1 === 1)->isTrue()->orThrow('You will never see this error');
```


# Enforcement

If you want to enforce that some condition is true, use `enforce`:
```php
enforce(true)->orThrow('That is not true...');
```

# Assurance
If you don't specify a Throwable, an `AssertionError` will be used:
```php
enforce(0); // throws AssertionError
```

# Expectations

If you want to assure that some condition is true, you could use the PHP `assert` function. Sadly, PHP assertions are disabled in production mode, but `assure` is not:
Bind expectations to your values and offer default values if the expectation don't apply.
You can either use `else` or `then` to evaluate if an Throwable was thrown. The usage of `else` or `then` will disregard and invalidate the Throwable internally:

```php
assure(0);
$this->assertEquals('foo', ensure(42)->isEven()->then('foo'));
$this->assertEquals(23, ensure(42)->isOdd()->else(23));
```

Will throw an AssertionError as a correctly configured `assert` would do.
also you can use `either ... or` to set values for both outcomes:

```php
$this->assertTrue(ensure(42)->isOdd()->either(false)->or(true));
$this->assertFalse(ensure(23)->isOdd()->either(false)->or(true));
```

0 comments on commit 93e29b5

Please sign in to comment.