CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 纪念品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与其中
    • 问题 (Github)
    • 面包店
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 通讯
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • 帮助和支持
    • 论坛
    • Stack Overflow
    • IRC
    • Slack
    • 付费支持
CakePHP

C CakePHP 5.1 Chiffon API

  • 项目
    • CakePHP
      • CakePHP
      • Chronos
      • Elastic Search
      • 队列
  • 版本
    • 5.1
      • 5.1
      • 5.0
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

命名空间

  • 全局
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
      • Constraint
      • Fixture
      • Stub
    • Utility
    • Validation
    • View

类 TestCase

Cake TestCase 类

抽象
命名空间: Cake\TestSuite

属性摘要

  • $_configure protected
    数组

    在测试结束时要恢复的配置值。

  • $_tableLocator protected
    Cake\ORM\Locator\LocatorInterface|null

    表定位器实例

  • $appPluginsToLoad protected
    数组

    在创建应用程序实例后要加载的插件 ContainerStubTrait::creatApp()

  • $defaultTable protected
    字符串|null

    此对象的默认表别名。

  • $fixtureStrategy protected
    Cake\TestSuite\Fixture\FixtureStrategyInterface|null
  • $fixtures protected
    列表<字符串>

    此测试用例使用的夹具。

方法摘要

  • __construct() public
  • _assertAttributes() protected

    检查作为 assertTags() 检查的一部分的属性。

  • _getTableClassName() protected

    获取表的类名。

  • _normalizePath() protected

    规范化用于比较的路径。

  • addFixture() protected

    将夹具添加到此测试用例。

  • addToAssertionCount() public
  • any() protected

    返回一个匹配器,当方法被执行零次或多次时匹配。

  • anything() public static
  • arrayHasKey() public static
  • assertArrayHasKey() public static

    断言数组具有指定的键。

  • assertArrayIsEqualToArrayIgnoringListOfKeys() public static

    断言两个数组相等,同时忽略键列表。

  • assertArrayIsEqualToArrayOnlyConsideringListOfKeys() public static

    断言两个数组相等,同时仅考虑键列表。

  • assertArrayIsIdenticalToArrayIgnoringListOfKeys() public static

    断言两个数组相等,同时忽略键列表。

  • assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() public static

    断言两个数组完全相同,同时仅考虑键列表。

  • assertArrayNotHasKey() public static

    断言数组不具有指定的键。

  • assertContains() public static

    断言干草堆包含一根针。

  • assertContainsEquals() public static
  • assertContainsOnly() public static

    断言干草堆仅包含给定类型的值。

  • assertContainsOnlyInstancesOf() public static

    断言干草堆仅包含给定类名的实例。

  • assertCount() public static

    断言数组、可计数或可遍历的元素数量。

  • assertDirectoryDoesNotExist() public static

    断言目录不存在。

  • assertDirectoryExists() public static

    断言目录存在。

  • assertDirectoryIsNotReadable() public static

    断言目录存在并且不可读。

  • assertDirectoryIsNotWritable() public static

    断言目录存在并且不可写。

  • assertDirectoryIsReadable() public static

    断言目录存在并且可读。

  • assertDirectoryIsWritable() public static

    断言目录存在并且可写。

  • assertDoesNotMatchRegularExpression() public static

    断言字符串与给定的正则表达式不匹配。

  • assertEmpty() public static

    断言变量为空。

  • assertEquals() public static

    断言两个变量相等。

  • assertEqualsCanonicalizing() public static

    断言两个变量相等(规范化)。

  • assertEqualsIgnoringCase() public static

    断言两个变量相等(不区分大小写)。

  • assertEqualsSql() public

    断言字符串与 SQL 匹配,其中去除了特定于数据库的字符,如引号。

  • assertEqualsWithDelta() public static

    断言两个变量相等(带有增量)。

  • assertEventFired() public

    断言全局事件已触发。您必须在事件管理器中跟踪事件才能使此断言起作用

  • assertEventFiredWith() public

    断言事件已触发并带有数据

  • assertFalse() public static

    断言条件为假。

  • assertFileDoesNotExist() public static

    断言文件不存在。

  • assertFileEquals() public static

    断言一个文件的内容等于另一个文件的内容。

  • assertFileEqualsCanonicalizing() public static

    断言一个文件的内容等于另一个文件的内容(规范化)。

  • assertFileEqualsIgnoringCase() public static

    断言一个文件的内容等于另一个文件的内容(不区分大小写)。

  • assertFileExists() public static

    断言文件存在。

  • assertFileIsNotReadable() public static

    断言文件存在并且不可读。

  • assertFileIsNotWritable() public static

    断言文件存在并且不可写。

  • assertFileIsReadable() public static

    断言文件存在并且可读。

  • assertFileIsWritable() public static

    断言文件存在并且可写。

  • assertFileMatchesFormat() public static

    断言字符串与给定的格式字符串匹配。

  • assertFileMatchesFormatFile() public static

    断言字符串与给定的格式字符串匹配。

  • assertFileNotEquals() public static

    断言一个文件的内容不等于另一个文件的内容。

  • assertFileNotEqualsCanonicalizing() public static

    断言一个文件的内容不等于另一个文件的内容(规范化)。

  • assertFileNotEqualsIgnoringCase() public static

    断言一个文件的内容不等于另一个文件的内容(不区分大小写)。

  • assertFinite() public static

    断言变量是有限的。

  • assertGreaterThan() public static

    断言一个值大于另一个值。

  • assertGreaterThanOrEqual() public static

    断言一个值大于或等于另一个值。

  • assertHtml() public

    断言 HTML 标签。

  • assertInfinite() public static

    断言变量是无限的。

  • assertInstanceOf() public static

    断言变量是给定类型的。

  • assertIsArray() public static

    断言变量是数组类型。

  • assertIsBool() public static

    断言变量是布尔类型。

  • assertIsCallable() public static

    断言变量是可调用类型。

  • assertIsClosedResource() public static

    断言变量是资源类型并且已关闭。

  • assertIsFloat() public static

    断言变量是浮点类型。

  • assertIsInt() public static

    断言变量是整型。

  • assertIsIterable() public static

    断言变量是可迭代类型。

  • assertIsList() public static
  • assertIsNotArray() public static

    断言变量不是数组类型。

  • assertIsNotBool() public static

    断言变量不是布尔类型。

  • assertIsNotCallable() public static

    断言变量不是可调用类型。

  • assertIsNotClosedResource() public static

    断言变量不是资源类型。

  • assertIsNotFloat() public static

    断言变量不是浮点类型。

  • assertIsNotInt() public static

    断言变量不是整型。

  • assertIsNotIterable() public static

    断言变量不是可迭代类型。

  • assertIsNotNumeric() public static

    断言变量不是数值类型。

  • assertIsNotObject() public static

    断言变量不是对象类型。

  • assertIsNotReadable() public static

    断言文件/目录存在且不可读。

  • assertIsNotResource() public static

    断言变量不是资源类型。

  • assertIsNotScalar() public static

    断言变量不是标量类型。

  • assertIsNotString() public static

    断言变量不是字符串类型。

  • assertIsNotWritable() public static

    断言文件/目录存在且不可写。

  • assertIsNumeric() public static

    断言变量是数值类型。

  • assertIsObject() public static

    断言变量是对象类型。

  • assertIsReadable() public static

    断言文件/目录可读。

  • assertIsResource() public static

    断言变量是资源类型。

  • assertIsScalar() public static

    断言变量是标量类型。

  • assertIsString() public static

    断言变量是字符串类型。

  • assertIsWritable() public static

    断言文件/目录存在且可写。

  • assertJson() public static

    断言字符串是有效的 JSON 字符串。

  • assertJsonFileEqualsJsonFile() public static

    断言两个 JSON 文件相等。

  • assertJsonFileNotEqualsJsonFile() public static

    断言两个 JSON 文件不相等。

  • assertJsonStringEqualsJsonFile() public static

    断言生成的 JSON 编码对象和给定文件的内容相等。

  • assertJsonStringEqualsJsonString() public static

    断言两个给定的 JSON 编码对象或数组相等。

  • assertJsonStringNotEqualsJsonFile() public static

    断言生成的 JSON 编码对象和给定文件的内容不相等。

  • assertJsonStringNotEqualsJsonString() public static

    断言两个给定的 JSON 编码对象或数组不相等。

  • assertLessThan() public static

    断言一个值小于另一个值。

  • assertLessThanOrEqual() public static

    断言一个值小于或等于另一个值。

  • assertMatchesRegularExpression() public static

    断言字符串匹配给定的正则表达式。

  • assertNan() public static

    断言变量是 NaN。

  • assertNotContains() public static

    断言干草堆不包含针。

  • assertNotContainsEquals() public static
  • assertNotContainsOnly() public static

    断言干草堆不只包含给定类型的值。

  • assertNotCount() public static

    断言数组、可计数或可遍历的元素数量。

  • assertNotEmpty() public static

    断言变量不为空。

  • assertNotEquals() public static

    断言两个变量不相等。

  • assertNotEqualsCanonicalizing() public static

    断言两个变量不相等(规范化)。

  • assertNotEqualsIgnoringCase() public static

    断言两个变量不相等(忽略大小写)。

  • assertNotEqualsWithDelta() public static

    断言两个变量不相等(带 delta)。

  • assertNotFalse() public static

    断言条件不为假。

  • assertNotInstanceOf() public static

    断言变量不是给定类型的。

  • assertNotNull() public static

    断言变量不为 null。

  • assertNotSame() public static

    断言两个变量的类型和值不同。在对象上使用时,它断言两个变量不引用同一个对象。

  • assertNotSameSize() public static

    断言两个数组(或 Countable 或 Traversable 对象)的大小不同。

  • assertNotTrue() public static

    断言条件不为真。

  • assertNotWithinRange() protected static

    兼容性函数,用于测试值是否不在可接受的范围内。

  • assertNull() public static

    断言变量为 null。

  • assertObjectEquals() public static
  • assertObjectHasProperty() public static

    断言对象具有指定的属性。

  • assertObjectNotEquals() public static
  • assertObjectNotHasProperty() public static

    断言对象没有指定的属性。

  • assertPathEquals() protected static

    兼容性函数,用于测试路径。

  • assertPostConditions() protected

    执行测试用例所有测试共享的断言。

  • assertPreConditions() protected

    执行测试用例所有测试共享的断言。

  • assertRegExpSql() public

    用于将正则表达式模式与具有引号标识符的查询进行比较的断言。它接受用字符 < 和 > 引用的查询。如果第三个参数设置为 true,它将改变模式以同时接受引用的和未引用的查询

  • assertSame() public static

    断言两个变量具有相同的类型和值。在对象上使用时,它断言两个变量引用同一个对象。

  • assertSameSize() public static

    断言两个数组(或 Countable 或 Traversable 对象)的大小相同。

  • assertStringContainsString() public static
  • assertStringContainsStringIgnoringCase() public static
  • assertStringContainsStringIgnoringLineEndings() public static
  • assertStringEndsNotWith() public static

    断言字符串不以给定的后缀结尾。

  • assertStringEndsWith() public static

    断言字符串以给定的后缀结尾。

  • assertStringEqualsFile() public static

    断言字符串的内容等于文件的内容。

  • assertStringEqualsFileCanonicalizing() public static

    断言字符串的内容等于文件的内容(规范化)。

  • assertStringEqualsFileIgnoringCase() public static

    断言字符串的内容等于文件的内容(不区分大小写)。

  • assertStringEqualsStringIgnoringLineEndings() public static

    断言两个字符串除了换行符外都相等。

  • assertStringMatchesFormat() public static

    断言字符串与给定的格式字符串匹配。

  • assertStringMatchesFormatFile() public static

    断言字符串与给定的格式文件匹配。

  • assertStringNotContainsString() public static
  • assertStringNotContainsStringIgnoringCase() public static
  • assertStringNotEqualsFile() public static

    断言字符串的内容不等于文件的内容。

  • assertStringNotEqualsFileCanonicalizing() public static

    断言字符串的内容不等于文件的内容(规范化)。

  • assertStringNotEqualsFileIgnoringCase() public static

    断言字符串的内容不等于文件的内容(不区分大小写)。

  • assertStringNotMatchesFormat() public static deprecated

    断言字符串与给定的格式字符串不匹配。

  • assertStringNotMatchesFormatFile() public static deprecated

    断言字符串与给定的格式字符串不匹配。

  • assertStringStartsNotWith() public static

    断言字符串不以给定的前缀开头。

  • assertStringStartsWith() public static

    断言字符串以给定的前缀开头。

  • assertTextContains() public

    断言字符串包含另一个字符串,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextEndsNotWith() public

    断言字符串不以给定的前缀结尾,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextEndsWith() public

    断言字符串以给定的前缀结尾,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextEquals() public

    断言文本相等,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextNotContains() public

    断言文本不包含另一个文本,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextNotEquals() public

    断言文本相等,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextStartsNotWith() public

    断言字符串不以给定的前缀开头,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertTextStartsWith() public

    断言字符串以给定的前缀开头,忽略换行符的差异。对于跨平台测试文本块很有用。

  • assertThat() public static

    评估 PHPUnit\Framework\Constraint 匹配器对象。

  • assertTrue() public static

    断言条件为真。

  • assertWithinRange() protected static

    兼容性函数,用于测试值是否在可接受范围内。

  • assertXmlFileEqualsXmlFile() public static

    断言两个 XML 文件相等。

  • assertXmlFileNotEqualsXmlFile() public static

    断言两个 XML 文件不相等。

  • assertXmlStringEqualsXmlFile() public static

    断言两个 XML 文档相等。

  • assertXmlStringEqualsXmlString() public static

    断言两个 XML 文档相等。

  • assertXmlStringNotEqualsXmlFile() public static

    断言两个 XML 文档不相等。

  • assertXmlStringNotEqualsXmlString() public static

    断言两个 XML 文档不相等。

  • atLeast() protected

    返回一个匹配器,当方法至少执行 N 次时匹配。

  • atLeastOnce() protected

    返回一个匹配器,当方法至少执行一次时匹配。

  • atMost() protected

    返回一个匹配器,当方法最多执行 N 次时匹配。

  • callback() public static
  • captureError() public

    捕获来自 $callable 的错误,以便您可以对错误进行断言。

  • clearPlugins() public

    从全局插件集合中清除所有插件。

  • containsEqual() public static
  • containsIdentical() public static
  • containsOnly() public static
  • containsOnlyInstancesOf() public static
  • count() public
  • countOf() public static
  • createConfiguredMock() protected

    为指定的接口或类创建(并配置)一个模拟对象。

  • createConfiguredStub() protected static

    为指定的接口或类创建(并配置)一个测试桩。

  • createMock() protected

    为指定的接口或类创建模拟对象。

  • createMockForIntersectionOfInterfaces() protected
  • createPartialMock() protected

    为指定的接口或类创建部分模拟对象。

  • createStub() protected static

    为指定的接口或类创建测试桩。

  • createStubForIntersectionOfInterfaces() protected static
  • createTestProxy() protected deprecated

    为指定的类创建测试代理。

  • dataName() public
  • dataSetAsString() public
  • dataSetAsStringWithData() public
  • dependencyInput() public
  • deprecated() public

    用于检查弃用方法的辅助方法

  • directoryExists() public static
  • doesNotPerformAssertions() public
  • equalTo() public static
  • equalToCanonicalizing() public static
  • equalToIgnoringCase() public static
  • equalToWithDelta() public static
  • exactly() protected

    返回一个匹配器,当方法恰好执行 $count 次时匹配。

  • expectDeprecationMessageMatches() public
  • expectErrorHandlerMessageMatches() protected
  • expectErrorMessageMatches() public
  • expectException() protected
  • expectExceptionCode() protected
  • expectExceptionMessage() protected
  • expectExceptionMessageMatches() protected
  • expectExceptionObject() protected

    为测试代码中要引发的异常设置一个期望。预期异常类、预期异常消息和预期异常代码的信息从给定的异常对象中检索。

  • expectNotToPerformAssertions() protected
  • expectNoticeMessageMatches() public
  • expectOutputRegex() protected
  • expectOutputString() protected
  • expectUserDeprecationMessage() protected
  • expectUserDeprecationMessageMatches() protected
  • expectWarningMessageMatches() public
  • expectsOutput() public
  • fail() public static

    使用给定的消息使测试失败。

  • fetchTable() public

    获取表格实例的便利方法。

  • fileExists() public static
  • getActualOutputForAssertion() protected
  • getCount() public static

    返回当前断言计数。

  • getFixtureStrategy() protected

    返回这些测试使用的fixture策略。

  • getFixtures() public

    获取此测试应使用的fixture。

  • getMockBuilder() protected

    返回一个构建器对象,使用流畅接口创建模拟对象。

  • getMockForAbstractClass() protected deprecated

    为指定的抽象类创建一个模拟对象,其中该类所有抽象方法都已模拟。具体方法默认不会被模拟。要模拟具体方法,请使用第 7 个参数($mockedMethods)。

  • getMockForModel() public

    模拟一个模型,维护fixture和表关联

  • getMockForTrait() protected deprecated

    为指定的特征创建一个模拟对象,其中该特征所有抽象方法都已模拟。可以通过$mockedMethods参数指定要模拟的具体方法。

  • getMockFromWsdl() protected deprecated

    根据给定的 WSDL 文件创建模拟对象。

  • getObjectForTrait() protected deprecated

    创建一个使用指定特征的对象。

  • getTableLocator() public

    获取表定位器。

  • greaterThan() public static
  • greaterThanOrEqual() public static
  • groups() public
  • hasDependencyInput() public
  • hasUnexpectedOutput() public
  • identicalTo() public static
  • iniSet() protected deprecated

    此方法是 ini_set() 函数的包装器,它会在测试运行后自动将修改后的 php.ini 设置重置为其原始值。

  • isEmpty() public static
  • isFalse() public static
  • isFinite() public static
  • isInfinite() public static
  • isInstanceOf() public static
  • isJson() public static
  • isList() public static
  • isNan() public static
  • isNull() public static
  • isReadable() public static
  • isTrue() public static
  • isType() public static
  • isWritable() public static
  • lessThan() public static
  • lessThanOrEqual() public static
  • loadPlugins() public

    将插件加载到模拟应用程序中。

  • loadRoutes() public

    加载应用程序的路由。

  • logicalAnd() public static
  • logicalNot() public static
  • logicalOr() public static
  • logicalXor() public static
  • markTestIncomplete() public static

    将测试标记为不完整。

  • markTestSkipped() public static

    将测试标记为跳过。

  • matches() public static
  • matchesRegularExpression() public static
  • name() public
  • nameWithDataSet() public
  • never() protected

    返回一个匹配器,当方法从未执行时匹配。

  • numberOfAssertionsPerformed() public
  • objectEquals() public static
  • onConsecutiveCalls() protected deprecated
  • onNotSuccessfulTest() protected

    当测试方法未成功执行时调用此方法。

  • once() protected

    返回一个匹配器,当方法正好执行一次时匹配。

  • output() public
  • providedData() public
  • provides() public
  • registerComparator() protected
  • registerFailureType() protected
  • registerMockObject() public
  • removePlugins() public

    从全局插件集合中删除插件。

  • requires() public
  • resetCount() public static

    重置断言计数器。

  • result() public
  • returnArgument() protected deprecated
  • returnCallback() protected deprecated
  • returnSelf() protected deprecated
  • returnValue() protected deprecated
  • returnValueMap() protected deprecated
  • run() public
  • runBare() public
  • runTest() protected
  • setAppNamespace() public static

    设置应用程序命名空间

  • setBackupGlobals() public
  • setBackupGlobalsExcludeList() public
  • setBackupStaticProperties() public
  • setBackupStaticPropertiesExcludeList() public
  • setData() public
  • setDependencies() public
  • setDependencyInput() public
  • setGroups() public
  • setInIsolation() public
  • setLocale() protected deprecated

    此方法是 setlocale() 函数的包装器,它会在测试运行后自动将语言环境重置为其原始值。

  • setPreserveGlobalState() public
  • setResult() public
  • setRunClassInSeparateProcess() public
  • setRunTestInSeparateProcess() public
  • setTableLocator() public

    设置表定位器。

  • setUp() protected

    设置测试用例,备份静态对象值以便可以恢复。具体而言,如果 Configure 和 App 中的路径尚未备份,则会备份其内容。

  • setUpBeforeClass() public static

    此方法在运行此测试类的第一个测试之前调用。

  • setupFixtures() protected

    初始化并加载任何使用的fixture。

  • size() public
  • skipIf() public

    覆盖 SimpleTestCase::skipIf 以提供布尔返回值

  • skipUnless() protected

    用于跳过的兼容性函数。

  • sortId() public
  • status() public
  • stringContains() public static
  • stringEndsWith() public static
  • stringEqualsStringIgnoringLineEndings() public static
  • stringStartsWith() public static
  • tearDown() protected

    拆卸任何静态对象更改并恢复它们。

  • tearDownAfterClass() public static

    此方法在运行此测试类的最后一个测试后调用。

  • teardownFixtures() protected

    卸载任何使用的fixture。

  • throwException() protected
  • toString() public

    返回测试用例的字符串表示形式。

  • transformException() protected
  • usesDataProvider() public
  • valueObjectForEvents() public
  • wasPrepared() public
  • withConsecutive() public static
  • withErrorReporting() public

    需要使用 error_reporting() 的测试的辅助方法

方法详情

__construct() ¶ public

__construct(non-empty-string $name)
参数
non-empty-string $name

_assertAttributes() ¶ protected

_assertAttributes(array<string, mixed> $assertions, string $string, bool $fullDebug = false, array|string $regex = ''): string|false

检查作为 assertTags() 检查的一部分的属性。

参数
array<string, mixed> $assertions

要运行的断言。

string $string

要检查的 HTML 字符串。

bool $fullDebug optional

是否应使用更详细的输出。

array|string $regex optional

来自assertHtml的完整正则表达式

返回
string|false

_getTableClassName() ¶ protected

_getTableClassName(string $alias, array<string, mixed> $options): class-stringCake\ORM\Table>

获取表的类名。

参数
string $alias

要获取模拟对象的模型。

array<string, mixed> $options

模拟对象构造函数的配置数据。

返回
class-stringCake\ORM\Table>
抛出
Cake\ORM\Exception\MissingTableClassException

_normalizePath() ¶ protected

_normalizePath(string $path): string

规范化用于比较的路径。

参数
string $path

用 "/" 斜杠分隔的路径。

返回
string

addFixture() ¶ protected

addFixture(string $fixture): $this

将夹具添加到此测试用例。

示例

  • core.Tags
  • app.MyRecords
  • plugin.MyPluginName.MyModelName

在测试用例的 {@link getFixtures()} 方法中使用此方法来构建固定装置列表。

参数
string $fixture

Fixture

返回
$this

addToAssertionCount() ¶ public

addToAssertionCount(int $count): void
参数
int $count
返回
void

any() ¶ protected

any(): AnyInvokedCountMatcher

返回一个匹配器,当方法被执行零次或多次时匹配。

返回
AnyInvokedCountMatcher

anything() ¶ public static

anything(): IsAnything
返回
IsAnything

arrayHasKey() ¶ public static

arrayHasKey(int|string $key): ArrayHasKey
参数
int|string $key
返回
ArrayHasKey

assertArrayHasKey() ¶ public static

assertArrayHasKey(int|string $key, array<mixed>|ArrayAccess<array-key, mixed> $array, string $message = ''): void

断言数组具有指定的键。

参数
int|string $key
array<mixed>|ArrayAccess<array-key, mixed> $array
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertArrayIsEqualToArrayIgnoringListOfKeys() ¶ public static

assertArrayIsEqualToArrayIgnoringListOfKeys(array<mixed> $expected, array<mixed> $actual, non-empty-list<array-key> $keysToBeIgnored, string $message = ''): void

断言两个数组相等,同时忽略键列表。

参数
array<mixed> $expected
array<mixed> $actual
non-empty-list<array-key> $keysToBeIgnored
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertArrayIsEqualToArrayOnlyConsideringListOfKeys() ¶ public static

assertArrayIsEqualToArrayOnlyConsideringListOfKeys(array<mixed> $expected, array<mixed> $actual, non-empty-list<array-key> $keysToBeConsidered, string $message = ''): void

断言两个数组相等,同时仅考虑键列表。

参数
array<mixed> $expected
array<mixed> $actual
non-empty-list<array-key> $keysToBeConsidered
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertArrayIsIdenticalToArrayIgnoringListOfKeys() ¶ public static

assertArrayIsIdenticalToArrayIgnoringListOfKeys(array<mixed> $expected, array<mixed> $actual, non-empty-list<array-key> $keysToBeIgnored, string $message = ''): void

断言两个数组相等,同时忽略键列表。

参数
array<mixed> $expected
array<mixed> $actual
non-empty-list<array-key> $keysToBeIgnored
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys() ¶ public static

assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys(array<mixed> $expected, array<mixed> $actual, non-empty-list<array-key> $keysToBeConsidered, string $message = ''): void

断言两个数组完全相同,同时仅考虑键列表。

参数
array<mixed> $expected
array<mixed> $actual
non-empty-list<array-key> $keysToBeConsidered
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertArrayNotHasKey() ¶ public static

assertArrayNotHasKey(int|string $key, array<mixed>|ArrayAccess<array-key, mixed> $array, string $message = ''): void

断言数组不具有指定的键。

参数
int|string $key
array<mixed>|ArrayAccess<array-key, mixed> $array
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertContains() ¶ public static

assertContains(mixed $needle, iterable<mixed> $haystack, string $message = ''): void

断言干草堆包含一根针。

参数
mixed $needle
iterable<mixed> $haystack
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertContainsEquals() ¶ public static

assertContainsEquals(mixed $needle, iterable<mixed> $haystack, string $message = ''): void
参数
mixed $needle
iterable<mixed> $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertContainsOnly() ¶ public static

assertContainsOnly(array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type, iterable<mixed> $haystack, ?bool $isNativeType = null, string $message = ''): void

断言干草堆仅包含给定类型的值。

参数
array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type
iterable<mixed> $haystack
?bool $isNativeType optional
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertContainsOnlyInstancesOf() ¶ public static

assertContainsOnlyInstancesOf(class-string $className, iterable<mixed> $haystack, string $message = ''): void

断言干草堆仅包含给定类名的实例。

参数
class-string $className
iterable<mixed> $haystack
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertCount() ¶ public static

assertCount(int $expectedCount, Countable|iterable<mixed> $haystack, string $message = ''): void

断言数组、可计数或可遍历的元素数量。

参数
int $expectedCount
Countable|iterable<mixed> $haystack
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertDirectoryDoesNotExist() ¶ public static

assertDirectoryDoesNotExist(string $directory, string $message = ''): void

断言目录不存在。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDirectoryExists() ¶ public static

assertDirectoryExists(string $directory, string $message = ''): void

断言目录存在。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDirectoryIsNotReadable() ¶ public static

assertDirectoryIsNotReadable(string $directory, string $message = ''): void

断言目录存在并且不可读。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDirectoryIsNotWritable() ¶ public static

assertDirectoryIsNotWritable(string $directory, string $message = ''): void

断言目录存在并且不可写。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDirectoryIsReadable() ¶ public static

assertDirectoryIsReadable(string $directory, string $message = ''): void

断言目录存在并且可读。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDirectoryIsWritable() ¶ public static

assertDirectoryIsWritable(string $directory, string $message = ''): void

断言目录存在并且可写。

参数
string $directory
string $message optional
返回
void
抛出
ExpectationFailedException

assertDoesNotMatchRegularExpression() ¶ public static

assertDoesNotMatchRegularExpression(string $pattern, string $string, string $message = ''): void

断言字符串与给定的正则表达式不匹配。

参数
string $pattern
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertEmpty() ¶ public static

assertEmpty(mixed $actual, string $message = ''): void

断言变量为空。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

GeneratorNotSupportedException

assertEquals() ¶ public static

assertEquals(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量相等。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertEqualsCanonicalizing() ¶ public static

assertEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量相等(规范化)。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertEqualsIgnoringCase() ¶ public static

assertEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量相等(不区分大小写)。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertEqualsSql() ¶ public

assertEqualsSql(string $expected, string $actual, string $message = ''): void

断言字符串与 SQL 匹配,其中去除了特定于数据库的字符,如引号。

参数
string $expected

预期的 SQL 语句。

string $actual

要比较的 SQL 语句。

string $message optional

失败时显示的消息。

返回
void

assertEqualsWithDelta() ¶ public static

assertEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void

断言两个变量相等(带有增量)。

参数
mixed $expected
mixed $actual
float $delta
string $message optional
返回
void
抛出
ExpectationFailedException

assertEventFired() ¶ public

assertEventFired(string $name, Cake\Event\EventManager|null $eventManager = null, string $message = ''): void

断言全局事件已触发。您必须在事件管理器中跟踪事件才能使此断言起作用

参数
string $name

事件名称。

Cake\Event\EventManager|null $eventManager optional

要检查的事件管理器,默认为全局事件管理器。

string $message optional

断言失败消息。

返回
void

assertEventFiredWith() ¶ public

assertEventFiredWith(string $name, string $dataKey, mixed $dataValue, Cake\Event\EventManager|null $eventManager = null, string $message = ''): void

断言事件已触发并带有数据

如果传递了第三个参数,则该值将用于与 $dataKey 中的值进行比较。

参数
string $name

事件名称。

string $dataKey

数据键。

mixed $dataValue

数据值。

Cake\Event\EventManager|null $eventManager optional

要检查的事件管理器,默认为全局事件管理器。

string $message optional

断言失败消息。

返回
void

assertFalse() ¶ public static

assertFalse(mixed $condition, string $message = ''): void

断言条件为假。

参数
mixed $condition
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileDoesNotExist() ¶ public static

assertFileDoesNotExist(string $filename, string $message = ''): void

断言文件不存在。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileEquals() ¶ public static

assertFileEquals(string $expected, string $actual, string $message = ''): void

断言一个文件的内容等于另一个文件的内容。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileEqualsCanonicalizing() ¶ public static

assertFileEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void

断言一个文件的内容等于另一个文件的内容(规范化)。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileEqualsIgnoringCase() ¶ public static

assertFileEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void

断言一个文件的内容等于另一个文件的内容(不区分大小写)。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileExists() ¶ public static

assertFileExists(string $filename, string $message = ''): void

断言文件存在。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileIsNotReadable() ¶ public static

assertFileIsNotReadable(string $file, string $message = ''): void

断言文件存在并且不可读。

参数
string $file
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileIsNotWritable() ¶ public static

assertFileIsNotWritable(string $file, string $message = ''): void

断言文件存在并且不可写。

参数
string $file
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileIsReadable() ¶ public static

assertFileIsReadable(string $file, string $message = ''): void

断言文件存在并且可读。

参数
string $file
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileIsWritable() ¶ public static

assertFileIsWritable(string $file, string $message = ''): void

断言文件存在并且可写。

参数
string $file
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileMatchesFormat() ¶ public static

assertFileMatchesFormat(string $format, string $actualFile, string $message = ''): void

断言字符串与给定的格式字符串匹配。

参数
string $format
string $actualFile
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileMatchesFormatFile() ¶ public static

assertFileMatchesFormatFile(string $formatFile, string $actualFile, string $message = ''): void

断言字符串与给定的格式字符串匹配。

参数
string $formatFile
string $actualFile
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileNotEquals() ¶ public static

assertFileNotEquals(string $expected, string $actual, string $message = ''): void

断言一个文件的内容不等于另一个文件的内容。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileNotEqualsCanonicalizing() ¶ public static

assertFileNotEqualsCanonicalizing(string $expected, string $actual, string $message = ''): void

断言一个文件的内容不等于另一个文件的内容(规范化)。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFileNotEqualsIgnoringCase() ¶ public static

assertFileNotEqualsIgnoringCase(string $expected, string $actual, string $message = ''): void

断言一个文件的内容不等于另一个文件的内容(不区分大小写)。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertFinite() ¶ public static

assertFinite(mixed $actual, string $message = ''): void

断言变量是有限的。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertGreaterThan() ¶ public static

assertGreaterThan(mixed $expected, mixed $actual, string $message = ''): void

断言一个值大于另一个值。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertGreaterThanOrEqual() ¶ public static

assertGreaterThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void

断言一个值大于或等于另一个值。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertHtml() ¶ public

assertHtml(array $expected, string $string, bool $fullDebug = false): bool

断言 HTML 标签。

接收一个数组 $expected 并从中生成一个正则表达式来匹配提供的 $string。 $expected 的示例

检查一个带有 name 属性(包含任何非空值)和 id 属性(包含 'my-input')的输入标签。

['input' => ['name', 'id' => 'my-input']]

检查两个包含一些文本的 p 元素。

[
  ['p' => true],
  'textA',
  '/p',
  ['p' => true],
  'textB',
  '/p'
]

你也可以在属性值或标签定义中指定一个模式表达式,如果在值前面加上 preg: 并用斜杠括起来,例如

[
  ['input' => ['name', 'id' => 'preg:/FieldName\d+/']],
  'preg:/My\s+field/'
]

重要:此函数对空白非常宽容,也接受属性顺序的任何排列。 它还允许在指定的标签之间有空白。

参数
array $expected

一个数组,见上文。

string $string

一个 HTML/XHTML/XML 字符串。

bool $fullDebug optional

是否应使用更详细的输出。

返回
bool

assertInfinite() ¶ public static

assertInfinite(mixed $actual, string $message = ''): void

断言变量是无限的。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertInstanceOf() ¶ public static

assertInstanceOf(class-string<ExpectedType> $expected, mixed $actual, string $message = ''): void

断言变量是给定类型的。

参数
class-string<ExpectedType> $expected
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

UnknownClassOrInterfaceException

assertIsArray() ¶ public static

assertIsArray(mixed $actual, string $message = ''): void

断言变量是数组类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsBool() ¶ public static

assertIsBool(mixed $actual, string $message = ''): void

断言变量是布尔类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsCallable() ¶ public static

assertIsCallable(mixed $actual, string $message = ''): void

断言变量是可调用类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsClosedResource() ¶ public static

assertIsClosedResource(mixed $actual, string $message = ''): void

断言变量是资源类型并且已关闭。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsFloat() ¶ public static

assertIsFloat(mixed $actual, string $message = ''): void

断言变量是浮点类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsInt() ¶ public static

assertIsInt(mixed $actual, string $message = ''): void

断言变量是整型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsIterable() ¶ public static

assertIsIterable(mixed $actual, string $message = ''): void

断言变量是可迭代类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsList() ¶ public static

assertIsList(mixed $array, string $message = ''): void
参数
mixed $array
string $message optional
返回
void
抛出
ExpectationFailedException

assertIsNotArray() ¶ public static

assertIsNotArray(mixed $actual, string $message = ''): void

断言变量不是数组类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotBool() ¶ public static

assertIsNotBool(mixed $actual, string $message = ''): void

断言变量不是布尔类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotCallable() ¶ public static

assertIsNotCallable(mixed $actual, string $message = ''): void

断言变量不是可调用类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotClosedResource() ¶ public static

assertIsNotClosedResource(mixed $actual, string $message = ''): void

断言变量不是资源类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotFloat() ¶ public static

assertIsNotFloat(mixed $actual, string $message = ''): void

断言变量不是浮点类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotInt() ¶ public static

assertIsNotInt(mixed $actual, string $message = ''): void

断言变量不是整型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotIterable() ¶ public static

assertIsNotIterable(mixed $actual, string $message = ''): void

断言变量不是可迭代类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotNumeric() ¶ public static

assertIsNotNumeric(mixed $actual, string $message = ''): void

断言变量不是数值类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotObject() ¶ public static

assertIsNotObject(mixed $actual, string $message = ''): void

断言变量不是对象类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotReadable() ¶ public static

assertIsNotReadable(string $filename, string $message = ''): void

断言文件/目录存在且不可读。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertIsNotResource() ¶ public static

assertIsNotResource(mixed $actual, string $message = ''): void

断言变量不是资源类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotScalar() ¶ public static

assertIsNotScalar(mixed $actual, string $message = ''): void

断言变量不是标量类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotString() ¶ public static

assertIsNotString(mixed $actual, string $message = ''): void

断言变量不是字符串类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsNotWritable() ¶ public static

assertIsNotWritable(string $filename, string $message = ''): void

断言文件/目录存在且不可写。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertIsNumeric() ¶ public static

assertIsNumeric(mixed $actual, string $message = ''): void

断言变量是数值类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsObject() ¶ public static

assertIsObject(mixed $actual, string $message = ''): void

断言变量是对象类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsReadable() ¶ public static

assertIsReadable(string $filename, string $message = ''): void

断言文件/目录可读。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertIsResource() ¶ public static

assertIsResource(mixed $actual, string $message = ''): void

断言变量是资源类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsScalar() ¶ public static

assertIsScalar(mixed $actual, string $message = ''): void

断言变量是标量类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsString() ¶ public static

assertIsString(mixed $actual, string $message = ''): void

断言变量是字符串类型。

参数
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertIsWritable() ¶ public static

assertIsWritable(string $filename, string $message = ''): void

断言文件/目录存在且可写。

参数
string $filename
string $message optional
返回
void
抛出
ExpectationFailedException

assertJson() ¶ public static

assertJson(string $actual, string $message = ''): void

断言字符串是有效的 JSON 字符串。

参数
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonFileEqualsJsonFile() ¶ public static

assertJsonFileEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void

断言两个 JSON 文件相等。

参数
string $expectedFile
string $actualFile
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonFileNotEqualsJsonFile() ¶ public static

assertJsonFileNotEqualsJsonFile(string $expectedFile, string $actualFile, string $message = ''): void

断言两个 JSON 文件不相等。

参数
string $expectedFile
string $actualFile
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonStringEqualsJsonFile() ¶ public static

assertJsonStringEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void

断言生成的 JSON 编码对象和给定文件的内容相等。

参数
string $expectedFile
string $actualJson
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonStringEqualsJsonString() ¶ public static

assertJsonStringEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void

断言两个给定的 JSON 编码对象或数组相等。

参数
string $expectedJson
string $actualJson
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonStringNotEqualsJsonFile() ¶ public static

assertJsonStringNotEqualsJsonFile(string $expectedFile, string $actualJson, string $message = ''): void

断言生成的 JSON 编码对象和给定文件的内容不相等。

参数
string $expectedFile
string $actualJson
string $message optional
返回
void
抛出
ExpectationFailedException

assertJsonStringNotEqualsJsonString() ¶ public static

assertJsonStringNotEqualsJsonString(string $expectedJson, string $actualJson, string $message = ''): void

断言两个给定的 JSON 编码对象或数组不相等。

参数
string $expectedJson
string $actualJson
string $message optional
返回
void
抛出
ExpectationFailedException

assertLessThan() ¶ public static

assertLessThan(mixed $expected, mixed $actual, string $message = ''): void

断言一个值小于另一个值。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertLessThanOrEqual() ¶ public static

assertLessThanOrEqual(mixed $expected, mixed $actual, string $message = ''): void

断言一个值小于或等于另一个值。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertMatchesRegularExpression() ¶ public static

assertMatchesRegularExpression(string $pattern, string $string, string $message = ''): void

断言字符串匹配给定的正则表达式。

参数
string $pattern
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertNan() ¶ public static

assertNan(mixed $actual, string $message = ''): void

断言变量是 NaN。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotContains() ¶ public static

assertNotContains(mixed $needle, iterable<mixed> $haystack, string $message = ''): void

断言干草堆不包含针。

参数
mixed $needle
iterable<mixed> $haystack
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertNotContainsEquals() ¶ public static

assertNotContainsEquals(mixed $needle, iterable<mixed> $haystack, string $message = ''): void
参数
mixed $needle
iterable<mixed> $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotContainsOnly() ¶ public static

assertNotContainsOnly(array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type, iterable<mixed> $haystack, ?bool $isNativeType = null, string $message = ''): void

断言干草堆不只包含给定类型的值。

参数
array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type
iterable<mixed> $haystack
?bool $isNativeType optional
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertNotCount() ¶ public static

assertNotCount(int $expectedCount, Countable|iterable<mixed> $haystack, string $message = ''): void

断言数组、可计数或可遍历的元素数量。

参数
int $expectedCount
Countable|iterable<mixed> $haystack
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertNotEmpty() ¶ public static

assertNotEmpty(mixed $actual, string $message = ''): void

断言变量不为空。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

GeneratorNotSupportedException

assertNotEquals() ¶ public static

assertNotEquals(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量不相等。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotEqualsCanonicalizing() ¶ public static

assertNotEqualsCanonicalizing(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量不相等(规范化)。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotEqualsIgnoringCase() ¶ public static

assertNotEqualsIgnoringCase(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量不相等(忽略大小写)。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotEqualsWithDelta() ¶ public static

assertNotEqualsWithDelta(mixed $expected, mixed $actual, float $delta, string $message = ''): void

断言两个变量不相等(带 delta)。

参数
mixed $expected
mixed $actual
float $delta
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotFalse() ¶ public static

assertNotFalse(mixed $condition, string $message = ''): void

断言条件不为假。

参数
mixed $condition
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotInstanceOf() ¶ public static

assertNotInstanceOf(class-string<ExpectedType> $expected, mixed $actual, string $message = ''): void

断言变量不是给定类型的。

参数
class-string<ExpectedType> $expected
mixed $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

assertNotNull() ¶ public static

assertNotNull(mixed $actual, string $message = ''): void

断言变量不为 null。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotSame() ¶ public static

assertNotSame(mixed $expected, mixed $actual, string $message = ''): void

断言两个变量的类型和值不同。在对象上使用时,它断言两个变量不引用同一个对象。

参数
mixed $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotSameSize() ¶ public static

assertNotSameSize(Countable|iterable<mixed> $expected, Countable|iterable<mixed> $actual, string $message = ''): void

断言两个数组(或 Countable 或 Traversable 对象)的大小不同。

参数
Countable|iterable<mixed> $expected
Countable|iterable<mixed> $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertNotTrue() ¶ public static

assertNotTrue(mixed $condition, string $message = ''): void

断言条件不为真。

参数
mixed $condition
string $message optional
返回
void
抛出
ExpectationFailedException

assertNotWithinRange() ¶ protected static

assertNotWithinRange(float $expected, float $result, float $margin, string $message = ''): void

兼容性函数,用于测试值是否不在可接受的范围内。

参数
float $expected
float $result
float $margin

接受范围

string $message optional

断言不正确时显示的文本

返回
void

assertNull() ¶ public static

assertNull(mixed $actual, string $message = ''): void

断言变量为 null。

参数
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertObjectEquals() ¶ public static

assertObjectEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
参数
object $expected
object $actual
string $method 可选
string $message optional
返回
void
抛出
ExpectationFailedException

assertObjectHasProperty() ¶ public static

assertObjectHasProperty(string $propertyName, object $object, string $message = ''): void

断言对象具有指定的属性。

参数
string $propertyName
object $object
string $message optional
返回
void
抛出
ExpectationFailedException

assertObjectNotEquals() ¶ public static

assertObjectNotEquals(object $expected, object $actual, string $method = 'equals', string $message = ''): void
参数
object $expected
object $actual
string $method 可选
string $message optional
返回
void
抛出
ExpectationFailedException

assertObjectNotHasProperty() ¶ public static

assertObjectNotHasProperty(string $propertyName, object $object, string $message = ''): void

断言对象没有指定的属性。

参数
string $propertyName
object $object
string $message optional
返回
void
抛出
ExpectationFailedException

assertPathEquals() ¶ protected static

assertPathEquals(string $expected, string $result, string $message = ''): void

兼容性函数,用于测试路径。

参数
string $expected
string $result
string $message optional

断言不正确时显示的文本

返回
void

assertPostConditions() ¶ protected

assertPostConditions(): void

执行测试用例所有测试共享的断言。

此方法在测试和 tearDown() 之间调用。

返回
void

assertPreConditions() ¶ protected

assertPreConditions(): void

执行测试用例所有测试共享的断言。

此方法在 setUp() 和测试之间调用。

返回
void

assertRegExpSql() ¶ public

assertRegExpSql(string $pattern, string $actual, bool $optional = false): void

用于将正则表达式模式与具有引号标识符的查询进行比较的断言。它接受用字符 < 和 > 引用的查询。如果第三个参数设置为 true,它将改变模式以同时接受引用的和未引用的查询

参数
string $pattern

预期的 SQL 模式

string $actual

要比较的 SQL 语句。

bool $optional 可选

引号字符(用 <> 标记)是否可选

返回
void

assertSame() ¶ public static

assertSame(ExpectedType $expected, mixed $actual, string $message = ''): void

断言两个变量具有相同的类型和值。在对象上使用时,它断言两个变量引用同一个对象。

参数
ExpectedType $expected
mixed $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertSameSize() ¶ public static

assertSameSize(Countable|iterable<mixed> $expected, Countable|iterable<mixed> $actual, string $message = ''): void

断言两个数组(或 Countable 或 Traversable 对象)的大小相同。

参数
Countable|iterable<mixed> $expected
Countable|iterable<mixed> $actual
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

GeneratorNotSupportedException

assertStringContainsString() ¶ public static

assertStringContainsString(string $needle, string $haystack, string $message = ''): void
参数
string $needle
string $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringContainsStringIgnoringCase() ¶ public static

assertStringContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
参数
string $needle
string $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringContainsStringIgnoringLineEndings() ¶ public static

assertStringContainsStringIgnoringLineEndings(string $needle, string $haystack, string $message = ''): void
参数
string $needle
string $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringEndsNotWith() ¶ public static

assertStringEndsNotWith(non-empty-string $suffix, string $string, string $message = ''): void

断言字符串不以给定的后缀结尾。

参数
非空字符串 $suffix
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

InvalidArgumentException

assertStringEndsWith() ¶ public static

assertStringEndsWith(non-empty-string $suffix, string $string, string $message = ''): void

断言字符串以给定的后缀结尾。

参数
非空字符串 $suffix
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

InvalidArgumentException

assertStringEqualsFile() ¶ public static

assertStringEqualsFile(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容等于文件的内容。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringEqualsFileCanonicalizing() ¶ public static

assertStringEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容等于文件的内容(规范化)。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringEqualsFileIgnoringCase() ¶ public static

assertStringEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容等于文件的内容(不区分大小写)。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringEqualsStringIgnoringLineEndings() ¶ public static

assertStringEqualsStringIgnoringLineEndings(string $expected, string $actual, string $message = ''): void

断言两个字符串除了换行符外都相等。

参数
string $expected
string $actual
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringMatchesFormat() ¶ public static

assertStringMatchesFormat(string $format, string $string, string $message = ''): void

断言字符串与给定的格式字符串匹配。

参数
string $format
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringMatchesFormatFile() ¶ public static

assertStringMatchesFormatFile(string $formatFile, string $string, string $message = ''): void

断言字符串与给定的格式文件匹配。

参数
string $formatFile
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotContainsString() ¶ public static

assertStringNotContainsString(string $needle, string $haystack, string $message = ''): void
参数
string $needle
string $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotContainsStringIgnoringCase() ¶ public static

assertStringNotContainsStringIgnoringCase(string $needle, string $haystack, string $message = ''): void
参数
string $needle
string $haystack
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotEqualsFile() ¶ public static

assertStringNotEqualsFile(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容不等于文件的内容。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotEqualsFileCanonicalizing() ¶ public static

assertStringNotEqualsFileCanonicalizing(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容不等于文件的内容(规范化)。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotEqualsFileIgnoringCase() ¶ public static

assertStringNotEqualsFileIgnoringCase(string $expectedFile, string $actualString, string $message = ''): void

断言字符串的内容不等于文件的内容(不区分大小写)。

参数
string $expectedFile
string $actualString
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotMatchesFormat() ¶ public static

assertStringNotMatchesFormat(string $format, string $string, string $message = ''): void

断言字符串与给定的格式字符串不匹配。

参数
string $format
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringNotMatchesFormatFile() ¶ public static

assertStringNotMatchesFormatFile(string $formatFile, string $string, string $message = ''): void

断言字符串与给定的格式字符串不匹配。

参数
string $formatFile
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

assertStringStartsNotWith() ¶ public static

assertStringStartsNotWith(non-empty-string $prefix, string $string, string $message = ''): void

断言字符串不以给定的前缀开头。

参数
非空字符串 $prefix
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

InvalidArgumentException

assertStringStartsWith() ¶ public static

assertStringStartsWith(non-empty-string $prefix, string $string, string $message = ''): void

断言字符串以给定的前缀开头。

参数
非空字符串 $prefix
string $string
string $message optional
返回
void
抛出
ExpectationFailedException

InvalidArgumentException

assertTextContains() ¶ public

assertTextContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void

断言字符串包含另一个字符串,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $needle

要搜索的字符串。

string $haystack

要搜索的字符串。

string $message optional

失败时显示的消息。

bool $ignoreCase 可选

搜索是否区分大小写。

返回
void

assertTextEndsNotWith() ¶ public

assertTextEndsNotWith(string $suffix, string $string, string $message = ''): void

断言字符串不以给定的前缀结尾,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $suffix

要查找的非后缀。

string $string

要搜索的字符串。

string $message optional

失败时要使用的消息。

返回
void

assertTextEndsWith() ¶ public

assertTextEndsWith(string $suffix, string $string, string $message = ''): void

断言字符串以给定的前缀结尾,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $suffix

要查找的后缀。

string $string

要搜索的字符串。

string $message optional

失败时要使用的消息。

返回
void

assertTextEquals() ¶ public

assertTextEquals(string $expected, string $result, string $message = ''): void

断言文本相等,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $expected

预期值。

string $result

实际值。

string $message optional

失败时要使用的消息。

返回
void

assertTextNotContains() ¶ public

assertTextNotContains(string $needle, string $haystack, string $message = '', bool $ignoreCase = false): void

断言文本不包含另一个文本,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $needle

要搜索的字符串。

string $haystack

要搜索的字符串。

string $message optional

失败时显示的消息。

bool $ignoreCase 可选

搜索是否区分大小写。

返回
void

assertTextNotEquals() ¶ public

assertTextNotEquals(string $expected, string $result, string $message = ''): void

断言文本相等,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $expected

预期值。

string $result

实际值。

string $message optional

失败时要使用的消息。

返回
void

assertTextStartsNotWith() ¶ public

assertTextStartsNotWith(string $prefix, string $string, string $message = ''): void

断言字符串不以给定的前缀开头,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $prefix

要查找的非前缀。

string $string

要搜索的字符串。

string $message optional

失败时要使用的消息。

返回
void

assertTextStartsWith() ¶ public

assertTextStartsWith(string $prefix, string $string, string $message = ''): void

断言字符串以给定的前缀开头,忽略换行符的差异。对于跨平台测试文本块很有用。

参数
string $prefix

要检查的前缀。

string $string

要搜索的字符串。

string $message optional

失败时要使用的消息。

返回
void

assertThat() ¶ public static

assertThat(mixed $value, Constraint $constraint, string $message = ''): void

评估 PHPUnit\Framework\Constraint 匹配器对象。

参数
mixed $value
Constraint $constraint
string $message optional
返回
void
抛出
ExpectationFailedException

assertTrue() ¶ public static

assertTrue(mixed $condition, string $message = ''): void

断言条件为真。

参数
mixed $condition
string $message optional
返回
void
抛出
ExpectationFailedException

assertWithinRange() ¶ protected static

assertWithinRange(float $expected, float $result, float $margin, string $message = ''): void

兼容性函数,用于测试值是否在可接受范围内。

参数
float $expected
float $result
float $margin

接受范围

string $message optional

断言不正确时显示的文本

返回
void

assertXmlFileEqualsXmlFile() ¶ public static

assertXmlFileEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void

断言两个 XML 文件相等。

参数
string $expectedFile
string $actualFile
string $message optional
返回
void
抛出
Exception

ExpectationFailedException

XmlException

assertXmlFileNotEqualsXmlFile() ¶ public static

assertXmlFileNotEqualsXmlFile(string $expectedFile, string $actualFile, string $message = ''): void

断言两个 XML 文件不相等。

参数
string $expectedFile
string $actualFile
string $message optional
返回
void
抛出
PHPUnit\Util\Exception

ExpectationFailedException

assertXmlStringEqualsXmlFile() ¶ public static

assertXmlStringEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void

断言两个 XML 文档相等。

参数
string $expectedFile
string $actualXml
string $message optional
返回
void
抛出
ExpectationFailedException

XmlException

assertXmlStringEqualsXmlString() ¶ public static

assertXmlStringEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void

断言两个 XML 文档相等。

参数
string $expectedXml
string $actualXml
string $message optional
返回
void
抛出
ExpectationFailedException

XmlException

assertXmlStringNotEqualsXmlFile() ¶ public static

assertXmlStringNotEqualsXmlFile(string $expectedFile, string $actualXml, string $message = ''): void

断言两个 XML 文档不相等。

参数
string $expectedFile
string $actualXml
string $message optional
返回
void
抛出
ExpectationFailedException

XmlException

assertXmlStringNotEqualsXmlString() ¶ public static

assertXmlStringNotEqualsXmlString(string $expectedXml, string $actualXml, string $message = ''): void

断言两个 XML 文档不相等。

参数
string $expectedXml
string $actualXml
string $message optional
返回
void
抛出
ExpectationFailedException

XmlException

atLeast() ¶ protected

atLeast(int $requiredInvocations): InvokedAtLeastCountMatcher

返回一个匹配器,当方法至少执行 N 次时匹配。

参数
int $requiredInvocations
返回
InvokedAtLeastCountMatcher

atLeastOnce() ¶ protected

atLeastOnce(): InvokedAtLeastOnceMatcher

返回一个匹配器,当方法至少执行一次时匹配。

返回
InvokedAtLeastOnceMatcher

atMost() ¶ protected

atMost(int $allowedInvocations): InvokedAtMostCountMatcher

返回一个匹配器,当方法最多执行 N 次时匹配。

参数
int $allowedInvocations
返回
InvokedAtMostCountMatcher

callback() ¶ public static

callback(callable(CallbackInput $callback): bool $callback): Callback<CallbackInput>
参数
callable(CallbackInput $callback): bool $callback
返回
Callback<CallbackInput>

captureError() ¶ public

captureError(int $errorLevel, Closure $callable): Cake\Error\PhpError

捕获来自 $callable 的错误,以便您可以对错误进行断言。

如果未捕获到错误,断言将失败。

参数
int $errorLevel

要使用的 error_reporting() 值。

Closure $callable

用于捕获错误的闭包。

返回
Cake\Error\PhpError

clearPlugins() ¶ public

clearPlugins(): void

从全局插件集合中清除所有插件。

在测试用例拆卸方法中很有用。

返回
void

containsEqual() ¶ public static

containsEqual(mixed $value): TraversableContainsEqual
参数
mixed $value
返回
TraversableContainsEqual

containsIdentical() ¶ public static

containsIdentical(mixed $value): TraversableContainsIdentical
参数
mixed $value
返回
TraversableContainsIdentical

containsOnly() ¶ public static

containsOnly(array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type): TraversableContainsOnly
参数
array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type
返回
TraversableContainsOnly
抛出
Exception

containsOnlyInstancesOf() ¶ public static

containsOnlyInstancesOf(class-string $className): TraversableContainsOnly
参数
class-string $className
返回
TraversableContainsOnly
抛出
Exception

count() ¶ public

count(): int
返回
int

countOf() ¶ public static

countOf(int $count): Count
参数
int $count
返回
Count

createConfiguredMock() ¶ protected

createConfiguredMock(class-string<RealInstanceType> $originalClassName, array<non-empty-string, mixed> $configuration): MockObject&RealInstanceType

为指定的接口或类创建(并配置)一个模拟对象。

参数
class-string<RealInstanceType> $originalClassName
array<非空字符串, mixed> $configuration
返回
MockObject&RealInstanceType
抛出
InvalidArgumentException

MockObjectException

NoPreviousThrowableException

createConfiguredStub() ¶ protected static

createConfiguredStub(class-string<RealInstanceType> $originalClassName, array<non-empty-string, mixed> $configuration): RealInstanceType&Stub

为指定的接口或类创建(并配置)一个测试桩。

参数
class-string<RealInstanceType> $originalClassName
array<非空字符串, mixed> $configuration
返回
RealInstanceType&Stub
抛出
InvalidArgumentException

MockObjectException

NoPreviousThrowableException

createMock() ¶ protected

createMock(class-string<RealInstanceType> $originalClassName): MockObject&RealInstanceType

为指定的接口或类创建模拟对象。

参数
class-string<RealInstanceType> $originalClassName
返回
MockObject&RealInstanceType
抛出
InvalidArgumentException

MockObjectException

NoPreviousThrowableException

createMockForIntersectionOfInterfaces() ¶ protected

createMockForIntersectionOfInterfaces(list<class-string> $interfaces): MockObject
参数
list<class-string> $interfaces
返回
MockObject
抛出
MockObjectException

createPartialMock() ¶ protected

createPartialMock(class-string<RealInstanceType> $originalClassName, list<non-empty-string> $methods): MockObject&RealInstanceType

为指定的接口或类创建部分模拟对象。

参数
class-string<RealInstanceType> $originalClassName
list<非空字符串> $methods
返回
MockObject&RealInstanceType
抛出
InvalidArgumentException

MockObjectException

createStub() ¶ protected static

createStub(class-string<RealInstanceType> $originalClassName): RealInstanceType&Stub

为指定的接口或类创建测试桩。

参数
class-string<RealInstanceType> $originalClassName
返回
RealInstanceType&Stub
抛出
InvalidArgumentException

MockObjectException

NoPreviousThrowableException

createStubForIntersectionOfInterfaces() ¶ protected static

createStubForIntersectionOfInterfaces(list<class-string> $interfaces): Stub
参数
list<class-string> $interfaces
返回
Stub
抛出
MockObjectException

createTestProxy() ¶ protected

createTestProxy(class-string<RealInstanceType> $originalClassName, array<mixed> $constructorArguments = []): MockObject&RealInstanceType

为指定的类创建测试代理。

参数
class-string<RealInstanceType> $originalClassName
array<mixed> $constructorArguments 可选
返回
MockObject&RealInstanceType
抛出
InvalidArgumentException

MockObjectException

dataName() ¶ public

dataName(): int|string
返回
int|string

dataSetAsString() ¶ public

dataSetAsString(): string
返回
string

dataSetAsStringWithData() ¶ public

dataSetAsStringWithData(): string
返回
string

dependencyInput() ¶ public

dependencyInput(): array<non-empty-string, array<mixed>>
返回
array<非空字符串, array<mixed>>

deprecated() ¶ public

deprecated(Closure $callable): void

用于检查弃用方法的辅助方法

参数
Closure $callable

接收断言的可调用函数

返回
void

directoryExists() ¶ public static

directoryExists(): DirectoryExists
返回
DirectoryExists

doesNotPerformAssertions() ¶ public

doesNotPerformAssertions(): bool
返回
bool

equalTo() ¶ public static

equalTo(mixed $value): IsEqual
参数
mixed $value
返回
IsEqual

equalToCanonicalizing() ¶ public static

equalToCanonicalizing(mixed $value): IsEqualCanonicalizing
参数
mixed $value
返回
IsEqualCanonicalizing

equalToIgnoringCase() ¶ public static

equalToIgnoringCase(mixed $value): IsEqualIgnoringCase
参数
mixed $value
返回
IsEqualIgnoringCase

equalToWithDelta() ¶ public static

equalToWithDelta(mixed $value, float $delta): IsEqualWithDelta
参数
mixed $value
float $delta
返回
IsEqualWithDelta

exactly() ¶ protected

exactly(int $count): InvokedCountMatcher

返回一个匹配器,当方法恰好执行 $count 次时匹配。

参数
int $count
返回
InvokedCountMatcher

expectDeprecationMessageMatches() ¶ public

expectDeprecationMessageMatches(string $regex, Closure $callable): void
参数
string $regex

与弃用消息匹配的正则表达式

Closure $callable

应该触发警告的可调用函数

返回
void
抛出
Exception

expectErrorHandlerMessageMatches() ¶ protected

expectErrorHandlerMessageMatches(string $regex, Closure $callable, int $errorLevel): void
参数
string $regex

与警告消息匹配的正则表达式

Closure $callable

应该触发警告的可调用函数

int $errorLevel

要监听的错误级别

返回
void
抛出
Exception

expectErrorMessageMatches() ¶ public

expectErrorMessageMatches(string $regex, Closure $callable): void
参数
string $regex

与错误消息匹配的正则表达式

Closure $callable

应该触发警告的可调用函数

返回
void
抛出
Exception

expectException() ¶ protected

expectException(class-string<Throwable> $exception): void
参数
class-string<Throwable> $exception
返回
void

expectExceptionCode() ¶ protected

expectExceptionCode(int|string $code): void
参数
int|string $code
返回
void

expectExceptionMessage() ¶ protected

expectExceptionMessage(string $message): void
参数
string $message
返回
void

expectExceptionMessageMatches() ¶ protected

expectExceptionMessageMatches(string $regularExpression): void
参数
string $regularExpression
返回
void

expectExceptionObject() ¶ protected

expectExceptionObject(Exception $exception): void

为测试代码中要引发的异常设置一个期望。预期异常类、预期异常消息和预期异常代码的信息从给定的异常对象中检索。

参数
Exception $exception
返回
void

expectNotToPerformAssertions() ¶ protected

expectNotToPerformAssertions(): void
返回
void

expectNoticeMessageMatches() ¶ public

expectNoticeMessageMatches(string $regex, Closure $callable): void
参数
string $regex

与警告消息匹配的正则表达式

Closure $callable

应该触发警告的可调用函数

返回
void
抛出
Exception

expectOutputRegex() ¶ protected

expectOutputRegex(string $expectedRegex): void
参数
string $expectedRegex
返回
void

expectOutputString() ¶ protected

expectOutputString(string $expectedString): void
参数
string $expectedString
返回
void

expectUserDeprecationMessage() ¶ protected

expectUserDeprecationMessage(non-empty-string $expectedUserDeprecationMessage): void
参数
non-empty-string $expectedUserDeprecationMessage
返回
void

expectUserDeprecationMessageMatches() ¶ protected

expectUserDeprecationMessageMatches(non-empty-string $expectedUserDeprecationMessageRegularExpression): void
参数
non-empty-string $expectedUserDeprecationMessageRegularExpression
返回
void

expectWarningMessageMatches() ¶ public

expectWarningMessageMatches(string $regex, Closure $callable): void
参数
string $regex

与警告消息匹配的正则表达式

Closure $callable

应该触发警告的可调用函数

返回
void
抛出
Exception

expectsOutput() ¶ public

expectsOutput(): bool
返回
bool

fail() ¶ public static

fail(string $message = ''): never

使用给定的消息使测试失败。

参数
string $message optional
返回
never
抛出
AssertionFailedError

fetchTable() ¶ public

fetchTable(string|null $alias = null, array<string, mixed> $options = []): Cake\ORM\Table

获取表格实例的便利方法。

参数
string|null $alias optional

您想要获取的别名。应该使用驼峰式命名法。如果为 null,则使用 $defaultTable 属性的值。

array<string, mixed> $options optional

您想要用来构建表的选项。如果表已加载,则注册表选项将被忽略。

返回
Cake\ORM\Table
抛出
Cake\Core\Exception\CakeException
如果 `$alias` 参数和 `$defaultTable` 属性均为 `null`。
另请参见
\Cake\ORM\TableLocator::get()

fileExists() ¶ public static

fileExists(): FileExists
返回
FileExists

getActualOutputForAssertion() ¶ protected

getActualOutputForAssertion(): string
返回
string

getCount() ¶ public static

getCount(): int

返回当前断言计数。

返回
int

getFixtureStrategy() ¶ protected

getFixtureStrategy(): Cake\TestSuite\Fixture\FixtureStrategyInterface

返回这些测试使用的fixture策略。

返回
Cake\TestSuite\Fixture\FixtureStrategyInterface

getFixtures() ¶ public

getFixtures(): list<string>

获取此测试应使用的fixture。

返回
列表<字符串>

getMockBuilder() ¶ protected

getMockBuilder(class-string<RealInstanceType> $className): MockBuilder<RealInstanceType>

返回一个构建器对象,使用流畅接口创建模拟对象。

参数
class-string<RealInstanceType> $className
返回
MockBuilder<RealInstanceType>

getMockForAbstractClass() ¶ protected

getMockForAbstractClass(class-string<RealInstanceType> $originalClassName, array<mixed> $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, list<non-empty-string> $mockedMethods = [], bool $cloneArguments = false): MockObject&RealInstanceType

为指定的抽象类创建一个模拟对象,其中该类所有抽象方法都已模拟。具体方法默认不会被模拟。要模拟具体方法,请使用第 7 个参数($mockedMethods)。

参数
class-string<RealInstanceType> $originalClassName
array<mixed> $arguments optional
string $mockClassName optional
bool $callOriginalConstructor optional
bool $callOriginalClone optional
bool $callAutoload optional
list<non-empty-string> $mockedMethods optional
bool $cloneArguments optional
返回
MockObject&RealInstanceType
抛出
InvalidArgumentException

MockObjectException

getMockForModel() ¶ public

getMockForModel(string $alias, list<string> $methods = [], array<string, mixed> $options = []): Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject

模拟一个模型,维护fixture和表关联

参数
string $alias

要获取模拟对象的模型。

list<string> $methods optional

要模拟的方法列表

array<string, mixed> $options optional

模拟对象构造函数的配置数据。

返回
Cake\ORM\TablePHPUnit\Framework\MockObject\MockObject
抛出
Cake\ORM\Exception\MissingTableClassException

getMockForTrait() ¶ protected

getMockForTrait(trait-string $traitName, array<mixed> $arguments = [], string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, list<non-empty-string> $mockedMethods = [], bool $cloneArguments = false): MockObject

为指定的特征创建一个模拟对象,其中该特征所有抽象方法都已模拟。可以通过$mockedMethods参数指定要模拟的具体方法。

参数
trait-string $traitName
array<mixed> $arguments optional
string $mockClassName optional
bool $callOriginalConstructor optional
bool $callOriginalClone optional
bool $callAutoload optional
list<non-empty-string> $mockedMethods optional
bool $cloneArguments optional
返回
MockObject
抛出
InvalidArgumentException

MockObjectException

getMockFromWsdl() ¶ protected

getMockFromWsdl(string $wsdlFile, string $originalClassName = '', string $mockClassName = '', list<string> $methods = [], bool $callOriginalConstructor = true, list<mixed> $options = []): MockObject

根据给定的 WSDL 文件创建模拟对象。

参数
string $wsdlFile
string $originalClassName optional
string $mockClassName optional
list<string> $methods optional
bool $callOriginalConstructor optional
list<mixed> $options optional
返回
MockObject
抛出
MockObjectException

getObjectForTrait() ¶ protected

getObjectForTrait(trait-string $traitName, array<mixed> $arguments = [], string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true): object

创建一个使用指定特征的对象。

参数
trait-string $traitName
array<mixed> $arguments optional
string $traitClassName optional
bool $callOriginalConstructor optional
bool $callOriginalClone optional
bool $callAutoload optional
返回
object
抛出
MockObjectException

getTableLocator() ¶ public

getTableLocator(): Cake\ORM\Locator\LocatorInterface

获取表定位器。

返回
Cake\ORM\Locator\LocatorInterface

greaterThan() ¶ public static

greaterThan(mixed $value): GreaterThan
参数
mixed $value
返回
GreaterThan

greaterThanOrEqual() ¶ public static

greaterThanOrEqual(mixed $value): LogicalOr
参数
mixed $value
返回
LogicalOr

groups() ¶ public

groups(): list<string>
返回
列表<字符串>

hasDependencyInput() ¶ public

hasDependencyInput(): bool
返回
bool

hasUnexpectedOutput() ¶ public

hasUnexpectedOutput(): bool
返回
bool

identicalTo() ¶ public static

identicalTo(mixed $value): IsIdentical
参数
mixed $value
返回
IsIdentical

iniSet() ¶ protected

iniSet(string $varName, string $newValue): void

此方法是 ini_set() 函数的包装器,它会在测试运行后自动将修改后的 php.ini 设置重置为其原始值。

参数
string $varName
string $newValue
返回
void
抛出
Exception

isEmpty() ¶ public static

isEmpty(): IsEmpty
返回
IsEmpty

isFalse() ¶ public static

isFalse(): IsFalse
返回
IsFalse

isFinite() ¶ public static

isFinite(): IsFinite
返回
IsFinite

isInfinite() ¶ public static

isInfinite(): IsInfinite
返回
IsInfinite

isInstanceOf() ¶ public static

isInstanceOf(string $className): IsInstanceOf
参数
string $className
返回
IsInstanceOf
抛出
UnknownClassOrInterfaceException

isJson() ¶ public static

isJson(): IsJson
返回
IsJson

isList() ¶ public static

isList(): IsList
返回
IsList

isNan() ¶ public static

isNan(): IsNan
返回
IsNan

isNull() ¶ public static

isNull(): IsNull
返回
IsNull

isReadable() ¶ public static

isReadable(): IsReadable
返回
IsReadable

isTrue() ¶ public static

isTrue(): IsTrue
返回
IsTrue

isType() ¶ public static

isType(array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type): IsType
参数
array|bool|boolean|callable|double|float|int|integer|iterable|null|numeric|object|real|resource (closed)|resource|scalar|string $type
返回
IsType
抛出
Exception

isWritable() ¶ public static

isWritable(): IsWritable
返回
IsWritable

lessThan() ¶ public static

lessThan(mixed $value): LessThan
参数
mixed $value
返回
LessThan

lessThanOrEqual() ¶ public static

lessThanOrEqual(mixed $value): LogicalOr
参数
mixed $value
返回
LogicalOr

loadPlugins() ¶ public

loadPlugins(array $plugins = []): Cake\Http\BaseApplication

将插件加载到模拟应用程序中。

用于测试加载/未加载插件如何与 CakePHP 或应用程序中的其他元素交互。

参数
array $plugins optional

要加载的插件列表。

返回
Cake\Http\BaseApplication

loadRoutes() ¶ public

loadRoutes(array|null $appArgs = null): void

加载应用程序的路由。

如果找不到应用程序类,则会引发异常。插件的路由*不会*加载。使用 loadPlugins() 或使用 Cake\TestSuite\IntegrationTestCaseTrait 来更好地模拟所有路由和插件的加载。

参数
array|null $appArgs optional

应用程序类的构造函数参数。

返回
void

logicalAnd() ¶ public static

logicalAnd(mixed ...$constraints): LogicalAnd
参数
混合 ...$constraints
返回
LogicalAnd
抛出
Exception

logicalNot() ¶ public static

logicalNot(Constraint $constraint): LogicalNot
参数
Constraint $constraint
返回
LogicalNot

logicalOr() ¶ public static

logicalOr(mixed ...$constraints): LogicalOr
参数
混合 ...$constraints
返回
LogicalOr

logicalXor() ¶ public static

logicalXor(mixed ...$constraints): LogicalXor
参数
混合 ...$constraints
返回
LogicalXor

markTestIncomplete() ¶ public static

markTestIncomplete(string $message = ''): never

将测试标记为不完整。

参数
string $message optional
返回
never
抛出
IncompleteTestError

markTestSkipped() ¶ public static

markTestSkipped(string $message = ''): never

将测试标记为跳过。

参数
string $message optional
返回
never
抛出
SkippedWithMessageException

matches() ¶ public static

matches(string $string): StringMatchesFormatDescription
参数
string $string
返回
StringMatchesFormatDescription

matchesRegularExpression() ¶ public static

matchesRegularExpression(string $pattern): RegularExpression
参数
string $pattern
返回
RegularExpression

name() ¶ public

name(): non-empty-string
返回
非空字符串

nameWithDataSet() ¶ public

nameWithDataSet(): string
返回
string

never() ¶ protected

never(): InvokedCountMatcher

返回一个匹配器,当方法从未执行时匹配。

返回
InvokedCountMatcher

numberOfAssertionsPerformed() ¶ public

numberOfAssertionsPerformed(): int
返回
int

objectEquals() ¶ public static

objectEquals(object $object, string $method = 'equals'): ObjectEquals
参数
object $object
string $method 可选
返回
ObjectEquals

onConsecutiveCalls() ¶ protected

onConsecutiveCalls(mixed ...$arguments): ConsecutiveCallsStub
参数
混合 ...$arguments
返回
ConsecutiveCallsStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423
https://github.com/sebastianbergmann/phpunit/issues/5425

onNotSuccessfulTest() ¶ protected

onNotSuccessfulTest(Throwable $t): never

当测试方法未成功执行时调用此方法。

参数
Throwable $t
返回
never
抛出
Throwable

once() ¶ protected

once(): InvokedCountMatcher

返回一个匹配器,当方法正好执行一次时匹配。

返回
InvokedCountMatcher

output() ¶ public

output(): string
返回
string

providedData() ¶ public

providedData(): array<mixed>
返回
array<mixed>

provides() ¶ public

provides(): list<ExecutionOrderDependency>
返回
list<ExecutionOrderDependency>

registerComparator() ¶ protected

registerComparator(Comparator $comparator): void
参数
Comparator $comparator
返回
void

registerFailureType() ¶ protected

registerFailureType(class-string $classOrInterface): void
参数
class-string $classOrInterface
返回
void

registerMockObject() ¶ public

registerMockObject(MockObject $mockObject): void
参数
MockObject $mockObject
返回
void

removePlugins() ¶ public

removePlugins(list<string> $names = []): void

从全局插件集合中删除插件。

在测试用例拆卸方法中很有用。

参数
list<string> $names 可选

您要移除的插件列表。

返回
void

requires() ¶ public

requires(): list<ExecutionOrderDependency>
返回
list<ExecutionOrderDependency>

resetCount() ¶ public static

resetCount(): void

重置断言计数器。

返回
void

result() ¶ public

result(): mixed
返回
混合

returnArgument() ¶ protected

returnArgument(int $argumentIndex): ReturnArgumentStub
参数
int $argumentIndex
返回
ReturnArgumentStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423

returnCallback() ¶ protected

returnCallback(callable $callback): ReturnCallbackStub
参数
callable $callback
返回
ReturnCallbackStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423

returnSelf() ¶ protected

returnSelf(): ReturnSelfStub
返回
ReturnSelfStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423

returnValue() ¶ protected

returnValue(mixed $value): ReturnStub
参数
mixed $value
返回
ReturnStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423

returnValueMap() ¶ protected

returnValueMap(array<mixed> $valueMap): ReturnValueMapStub
参数
array<mixed> $valueMap
返回
ReturnValueMapStub
另请参见
https://github.com/sebastianbergmann/phpunit/issues/5423

run() ¶ public

run(): void
返回
void
抛出
PHPUnit\Runner\Exception

PHPUnit\Util\Exception

SebastianBergmann\CodeCoverage\InvalidArgumentException

SebastianBergmann\Template\InvalidArgumentException

CodeCoverageException

Exception

NoPreviousThrowableException

ProcessIsolationException

StaticAnalysisCacheNotConfiguredException

UnintentionallyCoveredCodeException

runBare() ¶ public

runBare(): void
返回
void
抛出
Throwable

runTest() ¶ protected

runTest(): mixed
返回
混合
抛出
AssertionFailedError

Exception

ExpectationFailedException

Throwable

setAppNamespace() ¶ public static

setAppNamespace(string $appNamespace = 'TestApp'): string|null

设置应用程序命名空间

参数
string $appNamespace 可选

应用程序命名空间,默认为 "TestApp"。

返回
字符串|null

setBackupGlobals() ¶ public

setBackupGlobals(bool $backupGlobals): void
参数
bool $backupGlobals
返回
void

setBackupGlobalsExcludeList() ¶ public

setBackupGlobalsExcludeList(list<string> $backupGlobalsExcludeList): void
参数
list<string> $backupGlobalsExcludeList
返回
void

setBackupStaticProperties() ¶ public

setBackupStaticProperties(bool $backupStaticProperties): void
参数
bool $backupStaticProperties
返回
void

setBackupStaticPropertiesExcludeList() ¶ public

setBackupStaticPropertiesExcludeList(array<string, list<class-string>> $backupStaticPropertiesExcludeList): void
参数
array<string, list<class-string>> $backupStaticPropertiesExcludeList
返回
void

setData() ¶ public

setData(int|string $dataName, array<mixed> $data): void
参数
int|string $dataName
array<mixed> $data
返回
void

setDependencies() ¶ public

setDependencies(list<ExecutionOrderDependency> $dependencies): void
参数
list<ExecutionOrderDependency> $dependencies
返回
void

setDependencyInput() ¶ public

setDependencyInput(array<non-empty-string, array<mixed>> $dependencyInput): void
参数
array<非空字符串, array<mixed>> $dependencyInput
返回
void

setGroups() ¶ public

setGroups(list<string> $groups): void
参数
list<string> $groups
返回
void

setInIsolation() ¶ public

setInIsolation(bool $inIsolation): void
参数
bool $inIsolation
返回
void

setLocale() ¶ protected

setLocale(mixed ...$arguments): void

此方法是 setlocale() 函数的包装器,它会在测试运行后自动将语言环境重置为其原始值。

参数
混合 ...$arguments
返回
void
抛出
Exception

setPreserveGlobalState() ¶ public

setPreserveGlobalState(bool $preserveGlobalState): void
参数
bool $preserveGlobalState
返回
void

setResult() ¶ public

setResult(mixed $result): void
参数
混合 $result
返回
void

setRunClassInSeparateProcess() ¶ public

setRunClassInSeparateProcess(bool $runClassInSeparateProcess): void
参数
bool $runClassInSeparateProcess
返回
void

setRunTestInSeparateProcess() ¶ public

setRunTestInSeparateProcess(bool $runTestInSeparateProcess): void
参数
bool $runTestInSeparateProcess
返回
void

setTableLocator() ¶ public

setTableLocator(Cake\ORM\Locator\LocatorInterface $tableLocator): $this

设置表定位器。

参数
Cake\ORM\Locator\LocatorInterface $tableLocator

LocatorInterface 实例。

返回
$this

setUp() ¶ protected

setUp(): void

设置测试用例,备份静态对象值以便可以恢复。具体而言,如果 Configure 和 App 中的路径尚未备份,则会备份其内容。

返回
void

setUpBeforeClass() ¶ public static

setUpBeforeClass(): void

此方法在运行此测试类的第一个测试之前调用。

返回
void

setupFixtures() ¶ protected

setupFixtures(): void

初始化并加载任何使用的fixture。

返回
void

size() ¶ public

size(): TestSize
返回
TestSize

skipIf() ¶ public

skipIf(bool $shouldSkip, string $message = ''): bool

覆盖 SimpleTestCase::skipIf 以提供布尔返回值

参数
bool $shouldSkip

是否应该跳过测试。

string $message optional

要显示的消息。

返回
bool

skipUnless() ¶ protected

skipUnless(bool $condition, string $message = ''): bool

用于跳过的兼容性函数。

参数
bool $condition

触发跳过的条件

string $message optional

跳过的消息

返回
bool

sortId() ¶ public

sortId(): string
返回
string

status() ¶ public

status(): TestStatus
返回
TestStatus

stringContains() ¶ public static

stringContains(string $string, bool $case = true): StringContains
参数
string $string
bool $case 可选
返回
StringContains

stringEndsWith() ¶ public static

stringEndsWith(non-empty-string $suffix): StringEndsWith
参数
非空字符串 $suffix
返回
StringEndsWith
抛出
InvalidArgumentException

stringEqualsStringIgnoringLineEndings() ¶ public static

stringEqualsStringIgnoringLineEndings(string $string): StringEqualsStringIgnoringLineEndings
参数
string $string
返回
StringEqualsStringIgnoringLineEndings

stringStartsWith() ¶ public static

stringStartsWith(non-empty-string $prefix): StringStartsWith
参数
非空字符串 $prefix
返回
StringStartsWith
抛出
InvalidArgumentException

tearDown() ¶ 受保护

tearDown(): void

拆卸任何静态对象更改并恢复它们。

返回
void

tearDownAfterClass() ¶ 公共 静态

tearDownAfterClass(): void

此方法在运行此测试类的最后一个测试后调用。

返回
void

teardownFixtures() ¶ 受保护

teardownFixtures(): void

卸载任何使用的fixture。

返回
void

throwException() ¶ 受保护

throwException(Throwable $exception): ExceptionStub
参数
Throwable $exception
返回
ExceptionStub

toString() ¶ 公共

toString(): string

返回测试用例的字符串表示形式。

返回
string
抛出
Exception

transformException() ¶ 受保护

transformException(Throwable $t): Throwable
参数
Throwable $t
返回
Throwable

usesDataProvider() ¶ 公共

usesDataProvider(): bool
返回
bool

valueObjectForEvents() ¶ 公共

valueObjectForEvents(): Event\Code\TestMethod
返回
Event\Code\TestMethod

wasPrepared() ¶ 公共

wasPrepared(): bool
返回
bool

withConsecutive() ¶ 公共 静态

withConsecutive(array $firstCallArguments, array ...$consecutiveCallsArguments): iterable
参数
array $firstCallArguments

调用参数

array ...$consecutiveCallsArguments

其他参数

返回
可迭代

withErrorReporting() ¶ 公共

withErrorReporting(int $errorLevel, callable $callable): void

需要使用 error_reporting() 的测试的辅助方法

参数
int $errorLevel

需要使用的 error_reporting() 值

callable $callable

接收断言的可调用函数

返回
void

属性细节

$_configure ¶ 受保护

在测试结束时要恢复的配置值。

类型
数组

$_tableLocator ¶ 受保护

表定位器实例

类型
Cake\ORM\Locator\LocatorInterface|null

$appPluginsToLoad ¶ 受保护

在创建应用程序实例后要加载的插件 ContainerStubTrait::creatApp()

类型
数组

$defaultTable ¶ 受保护

此对象的默认表别名。

类型
字符串|null

$fixtureStrategy ¶ 受保护

类型
Cake\TestSuite\Fixture\FixtureStrategyInterface|null

$fixtures ¶ 受保护

此测试用例使用的夹具。

类型
列表<字符串>
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与其中
  • 问题 (Github)
  • 面包店
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成