Skip to content

Primitives

Null

static function(Assert $assert) {
    $assert->null($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->not()
        ->null($someValue, 'Optional error message');
}

Booleans

static function(Assert $assert) {
    $assert->bool($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert->true($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert->false($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert->not()->bool($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert->not()->true($someValue, 'Optional error message');
}
static function(Assert $assert) {
    $assert->not()->false($someValue, 'Optional error message');
}

Resource

static function(Assert $assert) {
    $assert->resource($someValue);
}

resources are values return by fopen functions and such.

Numbers

static function(Assert $assert) {
    $assert->number($someValue);
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->int('Optional error message');
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->float('Optional error message');
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->greaterThan($someIntOrFloat, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->greaterThanOrEqual($someIntOrFloat, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->lessThan($someIntOrFloat, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->number($someValue)
        ->lessThanOrEqual($someIntOrFloat, 'Optional error message');
}

Strings

static function(Assert $assert) {
    $assert->string($someValue);
}
static function(Assert $assert) {
    $assert
        ->string($someValue)
        ->empty('Optional error message');
}
static function(Assert $assert) {
    $assert
        ->string($haystack)
        ->contains($needle, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->string($someValue)
        ->matches($regex, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->string($someValue)
        ->startsWith($prefix, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->string($someValue)
        ->endsWith($suffix, 'Optional error message');
}

You can add a call to ->not() after ->string() to inverse the following assertion.

You can chain multiple assertions on the same string like this:

static function(Assert $assert) {
    $assert
        ->string($someValue)
        ->startsWith($prefix, 'Optional error message')
        ->endsWith($suffix, 'Optional error message');
}

Arrays

static function(Assert $assert) {
    $assert->array($someValue);
}
static function(Assert $assert) {
    $assert
        ->array($someValue)
        ->hasKey($intOrString, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->array($someValue)
        ->not()
        ->hasKey($intOrString, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->array($array)
        ->contains($value, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->array($array)
        ->not()
        ->contains($value, 'Optional error message');
}
static function(Assert $assert) {
    $assert->count($count, $array, 'Optional error message');
}
static function(Assert $assert) {
    $assert
        ->not()
        ->count($count, $array, 'Optional error message');
}