BDD-style assertions for PHPUnit
$number = 10;
// Simple expectation
expect($number)->toBe(10);
// Negative expectation
expect($number)->notToBeOfType('string');
// Chained expectations
expect($number)
->toBeOfType('int')
->toBeGreaterThan(5)
->toBeLessThan(20);
With Composer:
composer require jpkleemans/phpunit-expect --dev
Or if you've installed PHPUnit globally:
composer global require jpkleemans/phpunit-expect
Expect that two variables have the same type and value. Used on objects, it asserts that two variables reference the same object.
Expect that two variables do not have the same type and value. Used on objects, it asserts that two variables do not reference the same object.
Expect that two variables are equal.
Expect that two variables are not equal.
Expect that an array has a specified key.
Expect that an array does not have a specified key.
Expect that an array has a specified subset.
Expect that a haystack contains a needle.
Expect that a haystack does not contain a needle.
Expect that a haystack contains only values of a given type.
Expect that a haystack does not contain only values of a given type.
Expect that a haystack contains only instances of a given classname
Expect the number of elements of an array, Countable or Traversable.
Expect the number of elements of an array, Countable or Traversable.
Expect that a variable is empty.
Expect that a variable is not empty.
Expect that a value is greater than another value.
Expect that a value is greater than or equal to another value.
Expect that a value is smaller than another value.
Expect that a value is smaller than or equal to another value.
Expect that the contents of one file or a string is equal to the contents of another file.
Expect that the contents of one file or a string is not equal to the contents of another file.
Expect that a file exists.
Expect that a file does not exist.
Expect that a condition is true.
Expect that a condition is not true.
Expect that a condition is false.
Expect that a condition is not false.
Expect that a variable is null.
Expect that a variable is not null.
Expect that a variable is finite.
Expect that a variable is infinite.
Expect that a variable is nan.
Expect that a class or an object has a specified attribute.
Expect that a class or an object does not have a specified attribute.
Expect that a class has a specified static attribute.
Expect that a class does not have a specified static attribute.
Expect that a variable is of a given type.
Expect that a variable is not of a given type.
Expect that a variable is of a given type.
Expect that a variable is not of a given type.
Expect that a string matches a given regular expression.
Expect that a string does not match a given regular expression.
Assert that the size of two arrays (or Countable
or Traversable
objects) is the same.
Assert that the size of two arrays (or Countable
or Traversable
objects) is not the same.
Expect that a string matches a given format string.
Expect that a string does not match a given format string.
Expect that a string matches a given format file.
Expect that a string does not match a given format string.
Expect that a string starts with a given prefix.
Expect that a string starts not with a given prefix.
Expect that a string ends with a given suffix.
Expect that a string ends not with a given suffix.
Expect that two XML files or documents are equal.
Expect that two XML files or documents are not equal.
Expect that two XML documents are equal.
Expect that two XML documents are not equal.
Expect that a hierarchy of DOMElements matches.
Expect that a string is a valid JSON string.
Expect that two given JSON encoded objects or arrays are equal.
Expect that two given JSON encoded objects or arrays are not equal.
Expect that the generated JSON encoded object and the content of the given file or JSON string are equal.
Expect that the generated JSON encoded object and the content of the given file or JSON string are not equal.