jpkleemans / phpunit-expect
PHPUnit 的 BDD 风格断言
Requires (Dev)
- phpunit/phpunit: ^5.2
This package is auto-updated.
Last update: 2024-09-17 02:51:10 UTC
README
PHPUnit 的 BDD 风格断言
用法
$number = 10; // Simple expectation expect($number)->toBe(10); // Negative expectation expect($number)->notToBeOfType('string'); // Chained expectations expect($number) ->toBeOfType('int') ->toBeGreaterThan(5) ->toBeLessThan(20);
安装
使用 Composer
composer require jpkleemans/phpunit-expect --dev
或者如果您已全局安装了 PHPUnit
composer global require jpkleemans/phpunit-expect
期望
toBe
期望两个变量具有相同的类型和值。在对象上使用时,断言两个变量引用的是同一个对象。
notToBe
期望两个变量不具有相同的类型和值。在对象上使用时,断言两个变量不引用同一个对象。
toEqual
期望两个变量相等。
notToEqual
期望两个变量不相等。
toHaveKey
期望数组具有指定的键。
notToHaveKey
期望数组不包含指定的键。
toHaveSubset
期望数组包含指定的子集。
toContain
期望一个 haystack 包含一个 needle。
notToContain
期望一个 haystack 不包含一个 needle。
toContainOnly
期望一个 haystack 只包含特定类型的值。
notToContainOnly
期望一个 haystack 不只包含特定类型的值。
toContainOnlyInstancesOf
期望一个 haystack 只包含指定类名的实例。
toHaveCount
期望数组、Countable 或 Traversable 的元素数量。
notToHaveCount
期望数组、Countable 或 Traversable 的元素数量。
toBeEmpty
期望变量为空。
notToBeEmpty
期望变量不为空。
toBeGreaterThan
期望一个值大于另一个值。
toBeGreaterThanOrEqualTo
期望一个值大于或等于另一个值。
toBeLessThan
期望一个值小于另一个值。
toBeLessThanOrEqualTo
期望一个值小于或等于另一个值。
toEqualFile
期望一个文件或字符串的内容与另一个文件的内容相等。
notToEqualFile
期望一个文件或字符串的内容与另一个文件的内容不相等。
toExist
期望文件存在。
notToExist
期望文件不存在。
toBeTrue
期望条件为真。
notToBeTrue
期望条件不为真。
toBeFalse
期望条件为假。
notToBeFalse
期望条件不为假。
toBeNull
期望变量为 null。
notToBeNull
期望变量不为 null。
toBeFinite
期望变量为有限。
toBeInfinite
期望变量为无限。
toBeNan
期望变量为 nan。
toHaveAttribute
期望一个类或对象具有指定的属性。
notToHaveAttribute
期望一个类或对象不具有指定的属性。
toHaveStaticAttribute
期望一个类具有指定的静态属性。
notToHaveStaticAttribute
期望一个类不具有指定的静态属性。
toBeInstanceOf
期望变量是给定类型。
notToBeInstanceOf
期望变量不是给定类型。
toBeOfType
期望变量是给定类型。
notToBeOfType
期望变量不是给定类型。
toMatchRegExp
期望一个字符串匹配给定的正则表达式。
notToMatchRegExp
期望一个字符串不匹配给定的正则表达式。
toHaveSameSizeAs
断言两个数组(或Countable
或Traversable
对象)的大小相同。
notToHaveSameSizeAs
断言两个数组(或Countable
或Traversable
对象)的大小不同。
toMatchFormat
期望一个字符串匹配给定的格式字符串。
notToMatchFormat
期望一个字符串不匹配给定的格式字符串。
toMatchFormatFile
期望一个字符串匹配给定的格式文件。
notToMatchFormatFile
期望一个字符串不匹配给定的格式字符串。
toStartWith
期望一个字符串以给定的前缀开头。
notToStartWith
期望一个字符串不以给定的前缀开头。
toEndWith
期望一个字符串以给定的后缀结尾。
notToEndWith
期望一个字符串不以给定的后缀结尾。
toEqualXmlFile
期望两个XML文件或文档相等。
notToEqualXmlFile
期望两个XML文件或文档不相等。
toEqualXml
期望两个XML文档相等。
notToEqualXml
期望两个XML文档不相等。
toHaveSameXMLStructureAs
期望DOMElement的层次结构匹配。
toBeJson
期望一个字符串是有效的JSON字符串。
toEqualJson
期望两个给定的JSON编码对象或数组相等。
notToEqualJson
期望两个给定的JSON编码对象或数组不相等。
toEqualJsonFile
期望生成的JSON编码对象与给定的文件或JSON字符串的内容相等。
notToEqualJsonFile
期望生成的JSON编码对象与给定的文件或JSON字符串的内容不相等。