Skip to content
Open
Show file tree
Hide file tree
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
60 changes: 60 additions & 0 deletions expectations.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ With the Pest expectation API, you have access to an extensive collection of ind
- [`toBeUrl()`](#expect-toBeUrl)
- [`toBeUuid()`](#expect-toBeUuid)
- [`toBeUlid()`](#expect-toBeUlid)
- [`toBeBase64()`](#expect-toBeBase64)
- [`toBeDomain()`](#expect-toBeDomain)
- [`toBeHexadecimal()`](#expect-toBeHexadecimal)
- [`toBeHostname()`](#expect-toBeHostname)
- [`toBeIpAddress()`](#expect-toBeIpAddress)
- [`toBeMacAddress()`](#expect-toBeMacAddress)

</div>

Expand Down Expand Up @@ -856,6 +862,60 @@ This expectation ensures that `$value` is a ULID:
expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid();
```

<a name="expect-toBeBase64"></a>
### `toBeBase64()`

This expectation ensures that `$value` is a valid base64-encoded string:

```php
expect('Zm9vYmFy')->toBeBase64();
```

<a name="expect-toBeDomain"></a>
### `toBeDomain()`

This expectation ensures that `$value` is a valid domain name:

```php
expect('example.com')->toBeDomain();
```

<a name="expect-toBeHexadecimal"></a>
### `toBeHexadecimal()`

This expectation ensures that `$value` is a valid hexadecimal string:

```php
expect('deadbeef')->toBeHexadecimal();
```

<a name="expect-toBeHostname"></a>
### `toBeHostname()`

This expectation ensures that `$value` is a valid hostname:

```php
expect('example.com')->toBeHostname();
```

<a name="expect-toBeIpAddress"></a>
### `toBeIpAddress()`

This expectation ensures that `$value` is a valid IP address:

```php
expect('192.168.1.1')->toBeIpAddress();
```

<a name="expect-toBeMacAddress"></a>
### `toBeMacAddress()`

This expectation ensures that `$value` is a valid MAC address:

```php
expect('00:1a:2b:3c:4d:5e')->toBeMacAddress();
```

<a name="expect-and"></a>
### `and($value)`

Expand Down
12 changes: 9 additions & 3 deletions pest5-now-available.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,22 @@ If you add new test files before updating the timings, your tests still run —
<a name="new-expectations"></a>
## New Expectations

Pest 5 also brings a couple of new additions to the expectation API. Sometimes you may wish to assert that a value is a well-formed email address or a valid ULID — two checks common enough that writing them by hand quickly becomes tedious.
Pest 5 also brings new additions to the expectation API. Sometimes you may wish to assert that a value is a well-formed email address, a valid IP address, or a ULID — checks common enough that writing them by hand quickly becomes tedious.

Thankfully, Pest now provides `toBeEmail()` and `toBeUlid()` for exactly these cases:
Thankfully, Pest now provides `toBeEmail()`, `toBeUlid()`, `toBeIpAddress()`, `toBeMacAddress()`, `toBeHostname()`, `toBeDomain()`, `toBeBase64()`, and `toBeHexadecimal()` for exactly these cases:

```php
expect('nuno@pestphp.com')->toBeEmail();
expect('01ARZ3NDEKTSV4RRFFQ69G5FAV')->toBeUlid();
expect('192.168.1.1')->toBeIpAddress();
expect('00:1a:2b:3c:4d:5e')->toBeMacAddress();
expect('example.com')->toBeHostname();
expect('example.co.uk')->toBeDomain();
expect('Zm9vYmFy')->toBeBase64();
expect('deadbeef')->toBeHexadecimal();
```

Of course, both expectations may be negated with `not`. To explore the full set of available matchers, check out the [Expectations documentation](/docs/expectations).
Of course, each of these expectations may be negated with `not`. To explore the full set of available matchers, check out the [Expectations documentation](/docs/expectations).

<a name="on-top-of-php-84--phpunit-13"></a>
## On Top of PHP 8.4 & PHPUnit 13
Expand Down