CakePHP
  • 文档
    • 书籍
    • API
    • 视频
    • 报告安全问题
    • 隐私政策
    • 标识和商标
  • 商业解决方案
  • 周边商品
  • 公路旅行
  • 团队
  • 社区
    • 社区
    • 参与
    • 问题 (Github)
    • 烘焙坊
    • 特色资源
    • 培训
    • 聚会
    • 我的 CakePHP
    • CakeFest
    • 时事通讯
    • 领英
    • YouTube
    • 脸书
    • 推特
    • 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

Trait IntegrationTestTrait

一个旨在使控制器集成测试更容易的 Trait。

此测试类提供了一些辅助方法和功能,使调度请求和检查其响应变得更简单。它更倾向于完整的集成测试而不是模拟对象,因为你可以轻松地测试更多代码,并避免模拟对象带来的某些维护陷阱。

命名空间: Cake\TestSuite

属性摘要

  • $_appArgs protected
    array|null

    自定义应用程序构造函数参数。

  • $_appClass protected
    string|null

    自定义应用程序类名。

  • $_controller protected
    Cake\Controller\Controller|null

    上次请求中使用的控制器。

  • $_cookie protected
    array

    下一个请求中使用的 Cookie 数据。

  • $_cookieEncryptionKey protected
    string|null
  • $_csrfKeyName protected
    string

    检索 csrf 令牌时使用的名称。

  • $_csrfToken protected
    bool

    请求是否应添加 CSRF 令牌的布尔标志。

  • $_exception protected
    Throwable|null

    如果出现这种情况,则抛出的异常。

  • $_flashMessages protected
    array

    渲染前的存储的闪存消息

  • $_layoutName protected
    string|null

    最后渲染的布局

  • $_request protected
    array

    用于构建下一个请求的数据。

  • $_requestSession protected
    Cake\Http\Session|null

    上次请求的会话实例

  • $_response protected
    Psr\Http\Message\ResponseInterface|null

    最近请求的响应。

  • $_retainFlashMessages protected
    bool

    请求是否应重新存储闪存消息的布尔标志

  • $_securityToken protected
    bool

    请求是否应添加 SecurityComponent 令牌的布尔标志。

  • $_session protected
    array

    下一个请求中使用的会话数据。

  • $_unlockedFields protected
    list<string>

    从字段验证中排除的字段列表。

  • $_validCiphers protected
    list<string>

    加密 Cookie 的有效密码名称。

  • $_viewName protected
    string|null

    最后渲染的视图

方法摘要

  • _addTokens() protected

    如果需要,添加 CSRF 和 Security Component 令牌。

  • _buildRequest() protected

    使用配置的选项和参数创建请求对象。

  • _castToString() protected

    递归地将所有数据强制转换为字符串,因为这是数据在现实世界中 POST 的方式

  • _checkCipher() protected

    验证加密密码名称的辅助方法。

  • _decode() protected

    解码和解密单个值。

  • _decrypt() protected

    使用 Security 类中的公共 $type 方法解密 $value

  • _encrypt() protected

    使用 Security 类中的公共 $type 方法加密 $value

  • _explode() protected

    explode 方法从 CookieComponent::_implode() 中设置的字符串中返回数组,保持与 1.x CookieComponent::_implode() 的向后兼容性。

  • _getBodyAsString() protected

    获取响应主体作为字符串

  • _getCookieEncryptionKey() protected

    返回要使用的加密密钥。

  • _handleError() protected

    尝试为给定异常渲染错误响应。

  • _implode() protected

    implode 方法保留多维数组的键

  • _makeDispatcher() protected

    获取正确的调度器实例。

  • _sendRequest() protected

    创建请求并将其发送到 Dispatcher 实例中。

  • _url() protected

    创建有效的请求 URL 和参数数组,类似于 Request::_url()

  • assertContentType() public

    断言内容类型

  • assertCookie() public

    断言 Cookie 值

  • assertCookieEncrypted() public

    断言由 CookieComponent 加密的 Cookie 值。

  • assertCookieIsSet() public

    断言已设置 Cookie。

  • assertCookieNotSet() public

    断言响应中未设置 Cookie

  • assertFileResponse() public

    断言响应中发送了具有给定名称的文件

  • assertFlashElement() public

    断言已设置闪存元素

  • assertFlashElementAt() public

    断言闪存元素已在特定索引处设置

  • assertFlashMessage() public

    断言已设置闪存消息

  • assertFlashMessageAt() public

    断言闪存消息已在特定索引处设置

  • assertHeader() public

    断言响应头

  • assertHeaderContains() public

    断言响应头包含字符串

  • assertHeaderNotContains() public

    断言响应头不包含字符串

  • assertLayout() public

    断言搜索字符串在布局名称中。

  • assertNoRedirect() public

    断言 Location 头未设置。

  • assertRedirect() public

    断言 Location 头正确。比较针对完整 URL 进行。

  • assertRedirectContains() public

    断言 Location 头包含子字符串

  • assertRedirectEquals() public

    断言 Location 头正确。比较针对提供的 URL 进行。

  • assertRedirectNotContains() public

    断言 Location 头不包含子字符串

  • assertResponseCode() public

    断言特定的响应状态代码。

  • assertResponseContains() public

    断言响应主体中存在内容。

  • assertResponseEmpty() public

    断言响应内容为空。

  • assertResponseEquals() public

    断言响应主体中的内容相等。

  • assertResponseError() public

    断言响应状态代码在 4xx 范围内。

  • assertResponseFailure() public

    断言响应状态代码在 5xx 范围内。

  • assertResponseNotContains() public

    断言响应主体中不存在内容。

  • assertResponseNotEmpty() public

    断言响应内容不为空。

  • assertResponseNotEquals() public

    断言响应主体中的内容不相等。

  • assertResponseNotRegExp() public

    断言响应主体与给定的正则表达式不匹配。

  • assertResponseOk() public

    断言响应状态代码在 2xx 范围内。

  • assertResponseRegExp() public

    断言响应主体与给定的正则表达式匹配。

  • assertResponseSuccess() public

    断言响应状态码在 2xx/3xx 范围内。

  • assertSession() public

    断言会话内容

  • assertSessionHasKey() public

    断言会话键存在。

  • assertSessionNotHasKey() public

    断言会话键不存在。

  • assertTemplate() public

    断言搜索字符串在模板名称中。

  • cleanup() public

    清除用于请求的状态。

  • cleanupContainer() public

    清除任何已定义的模拟,并清理应用程序类配置。

  • configApplication() public

    配置要在集成测试中使用的应用程序类。

  • configRequest() public

    配置下一个请求的数据,与现有状态合并。

  • controllerSpy() public

    向控制器/视图事件管理器添加额外的事件间谍。

  • cookie() public

    为将来的请求设置请求 Cookie。

  • cookieEncrypted() public

    为将来的请求设置加密的请求 Cookie。

  • createApp() protected

    创建一个应用程序实例。

  • delete() public

    使用当前请求数据执行 DELETE 请求。

  • disableErrorHandlerMiddleware() public

    禁用错误处理中间件。

  • enableCsrfToken() public

    调用此方法将向请求添加 CSRF 令牌。

  • enableRetainFlashMessages() public

    调用此方法将在 FlashHelper 删除后将闪存消息重新存储到测试会话中

  • enableSecurityToken() public

    调用此方法将启用与 SecurityComponent 兼容的令牌添加到请求数据中。这使您可以轻松测试受 SecurityComponent 保护的操作。

  • extractExceptionMessage() protected

    提取现有异常的详细消息

  • extractVerboseMessage() protected

    检查控制器以提取断言失败的可能原因

  • get() public

    使用当前请求数据执行 GET 请求。

  • getSession() protected
  • head() public

    使用当前请求数据执行 HEAD 请求。

  • isDebug() protected

    检查调试标志是否设置。

  • mockService() public

    向容器添加模拟服务。

  • modifyContainer() public

    将应用程序的容器包装在一个包含模拟的容器中。

  • options() public

    使用当前请求数据执行 OPTIONS 请求。

  • patch() public

    使用当前请求数据执行 PATCH 请求。

  • post() public

    使用当前请求数据执行 POST 请求。

  • put() public

    使用当前请求数据执行 PUT 请求。

  • removeMockService() public

    从容器中删除模拟服务。

  • replaceRequest() public

    配置下一个请求的数据,替换现有状态。

  • requestAsJson() public

    设置下一个请求的 HTTP 标头,以识别为 JSON 请求。

  • resolveRoute() protected

    通过路由将 URL 数组转换为字符串 URL。

  • resolveUrl() public

    将提供的 URL 解析为字符串。

  • responseBody() protected

    调试响应主体的內容。

  • session() public

    设置会话数据。

  • setUnlockedFields() public

    设置从字段验证中排除的字段列表。

  • viewVariable() public

    按名称获取视图变量。

方法详情

_addTokens() ¶ protected

_addTokens(string $url, array $data, string $method): array

如果需要,添加 CSRF 和 Security Component 令牌。

参数
string $url

表单提交的 URL。

array $data

请求主体数据。

string $method

请求方法。

返回
array

_buildRequest() ¶ protected

_buildRequest(string $url, string $method, array|string $data = []): array

使用配置的选项和参数创建请求对象。

参数
string $url

URL

string $method

HTTP 方法

array|string $data optional

请求数据。

返回
array

_castToString() ¶ protected

_castToString(array $data): array

递归地将所有数据强制转换为字符串,因为这是数据在现实世界中 POST 的方式

参数
array $data

POST 数据

返回
array

_checkCipher() ¶ protected

_checkCipher(string $encrypt): void

验证加密密码名称的辅助方法。

参数
string $encrypt

密码名称。

返回
void
抛出
RuntimeException
当提供无效的密码时。

_decode() ¶ protected

_decode(string $value, string|false $encrypt, string|null $key): array|string

解码和解密单个值。

参数
string $value

要解码和解密的值。

string|false $encrypt

要使用的加密密码。

string|null $key

如果指定,用作安全盐。

返回
array|string

_decrypt() ¶ protected

_decrypt(list<string>|string $values, string|false $mode, string|null $key = null): array|string

使用 Security 类中的公共 $type 方法解密 $value

参数
list<string>|string $values

要解密的值

string|false $mode

加密模式

string|null $key optional

如果指定,用作安全盐。

返回
array|string

_encrypt() ¶ protected

_encrypt(array|string $value, string|false $encrypt, string|null $key = null): string

使用 Security 类中的公共 $type 方法加密 $value

参数
array|string $value

要加密的值

string|false $encrypt

要使用的加密模式。False 禁用加密。

string|null $key optional

如果指定,用作安全盐。

返回
string

_explode() ¶ protected

_explode(string $string): array|string

explode 方法从 CookieComponent::_implode() 中设置的字符串中返回数组,保持与 1.x CookieComponent::_implode() 的向后兼容性。

参数
string $string

包含 JSON 编码数据的字符串,或一个简单的字符串。

返回
array|string

_getBodyAsString() ¶ protected

_getBodyAsString(): string

获取响应主体作为字符串

返回
string

_getCookieEncryptionKey() ¶ protected

_getCookieEncryptionKey(): string

返回要使用的加密密钥。

返回
string

_handleError() ¶ protected

_handleError(Throwable $exception): void

尝试为给定异常渲染错误响应。

此方法将尝试使用配置的异常渲染器。如果该类不存在,则将使用内置的渲染器。

参数
Throwable $exception

要处理的异常。

返回
void

_implode() ¶ protected

_implode(array $array): string

implode 方法保留多维数组的键

参数
array $array

键值对映射

返回
string

_makeDispatcher() ¶ protected

_makeDispatcher(): Cake\TestSuite\MiddlewareDispatcher

获取正确的调度器实例。

返回
Cake\TestSuite\MiddlewareDispatcher

_sendRequest() ¶ protected

_sendRequest(array|string $url, string $method, array|string $data = []): void

创建请求并将其发送到 Dispatcher 实例中。

接收并存储响应以供将来检查。

参数
array|string $url

URL

string $method

HTTP 方法

array|string $data optional

请求数据。

返回
void
抛出
PHPUnit\ExceptionThrowable

_url() ¶ protected

_url(string $url): array

创建有效的请求 URL 和参数数组,类似于 Request::_url()

参数
string $url

URL

返回
array

assertContentType() ¶ public

assertContentType(string $type, string $message = ''): void

断言内容类型

参数
string $type

要检查的 Content-Type。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertCookie() ¶ public

assertCookie(mixed $expected, string $name, string $message = ''): void

断言 Cookie 值

参数
mixed $expected

预期的内容。

string $name

Cookie 名称。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertCookieEncrypted() ¶ public

assertCookieEncrypted(mixed $expected, string $name, string $encrypt = 'aes', string|null $key = null, string $message = ''): void

断言由 CookieComponent 加密的 Cookie 值。

与 assertCookie() 的区别在于,此方法像 CookieComponent 一样解密 Cookie 值以进行此断言。

参数
mixed $expected

预期的内容。

string $name

Cookie 名称。

string $encrypt optional

要使用的加密模式。

string|null $key optional

使用的加密密钥。默认为 Security.salt。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void
参见
\Cake\Utility\CookieCryptTrait::_encrypt()

assertCookieIsSet() ¶ public

assertCookieIsSet(string $name, string $message = ''): void

断言已设置 Cookie。

当您使用具有混淆值的 Cookie 但需要设置的 Cookie 很重要时很有用。

参数
string $name

Cookie 名称。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertCookieNotSet() ¶ public

assertCookieNotSet(string $cookie, string $message = ''): void

断言响应中未设置 Cookie

参数
string $cookie

要检查的 Cookie 名称。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertFileResponse() ¶ public

assertFileResponse(string $expected, string $message = ''): void

断言响应中发送了具有给定名称的文件

参数
string $expected

应在响应中发送的绝对文件路径。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertFlashElement() ¶ public

assertFlashElement(string $expected, string $key = 'flash', string $message = ''): void

断言已设置闪存元素

参数
string $expected

预期的元素名称

string $key optional

Flash 键

string $message optional

断言失败消息

返回
void

assertFlashElementAt() ¶ public

assertFlashElementAt(int $at, string $expected, string $key = 'flash', string $message = ''): void

断言闪存元素已在特定索引处设置

参数
int $at

Flash 索引

string $expected

预期的元素名称

string $key optional

Flash 键

string $message optional

断言失败消息

返回
void

assertFlashMessage() ¶ public

assertFlashMessage(string $expected, string $key = 'flash', string $message = ''): void

断言已设置闪存消息

参数
string $expected

预期的消息

string $key optional

Flash 键

string $message optional

断言失败消息

返回
void

assertFlashMessageAt() ¶ public

assertFlashMessageAt(int $at, string $expected, string $key = 'flash', string $message = ''): void

断言闪存消息已在特定索引处设置

参数
int $at

Flash 索引

string $expected

预期的消息

string $key optional

Flash 键

string $message optional

断言失败消息

返回
void

assertHeader() ¶ public

assertHeader(string $header, string $content, string $message = ''): void

断言响应头

参数
string $header

要检查的标头。

string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertHeaderContains() ¶ public

assertHeaderContains(string $header, string $content, string $message = ''): void

断言响应头包含字符串

参数
string $header

要检查的标头。

string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertHeaderNotContains() ¶ public

assertHeaderNotContains(string $header, string $content, string $message = ''): void

断言响应头不包含字符串

参数
string $header

要检查的标头。

string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertLayout() ¶ public

assertLayout(string $content, string $message = ''): void

断言搜索字符串在布局名称中。

参数
string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertNoRedirect() ¶ public

assertNoRedirect(string $message = ''): void

断言 Location 头未设置。

参数
string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertRedirect() ¶ public

assertRedirect(array|string|null $url = null, string $message = ''): void

断言 Location 头正确。比较针对完整 URL 进行。

参数
array|string|null $url optional

您期望客户端转到的 URL。这可以是字符串 URL 或与 Router::url() 兼容的数组。使用 null 仅检查此标头是否存在。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertRedirectContains() ¶ public

assertRedirectContains(string $url, string $message = ''): void

断言 Location 头包含子字符串

参数
string $url

您期望客户端转到的 URL。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertRedirectEquals() ¶ public

assertRedirectEquals(array|string|null $url = null, string $message = ''): void

断言 Location 头正确。比较针对提供的 URL 进行。

参数
array|string|null $url optional

您期望客户端转到的 URL。这可以是字符串 URL 或与 Router::url() 兼容的数组。使用 null 仅检查此标头是否存在。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertRedirectNotContains() ¶ public

assertRedirectNotContains(string $url, string $message = ''): void

断言 Location 头不包含子字符串

参数
string $url

您期望客户端转到的 URL。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseCode() ¶ public

assertResponseCode(int $code, string $message = ''): void

断言特定的响应状态代码。

参数
int $code

要断言的状态代码。

string $message optional

自定义失败消息。

返回
void

assertResponseContains() ¶ public

assertResponseContains(string $content, string $message = '', bool $ignoreCase = false): void

断言响应主体中存在内容。

参数
string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

bool $ignoreCase optional

一个标志,用于检查我们是否应该忽略大小写。

返回
void

assertResponseEmpty() ¶ public

assertResponseEmpty(string $message = ''): void

断言响应内容为空。

参数
string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseEquals() ¶ public

assertResponseEquals(mixed $content, string $message = ''): void

断言响应主体中的内容相等。

参数
mixed $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseError() ¶ public

assertResponseError(string $message = ''): void

断言响应状态代码在 4xx 范围内。

参数
string $message optional

自定义失败消息。

返回
void

assertResponseFailure() ¶ public

assertResponseFailure(string $message = ''): void

断言响应状态代码在 5xx 范围内。

参数
string $message optional

自定义失败消息。

返回
void

assertResponseNotContains() ¶ public

assertResponseNotContains(string $content, string $message = '', bool $ignoreCase = false): void

断言响应主体中不存在内容。

参数
string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

bool $ignoreCase optional

一个标志,用于检查我们是否应该忽略大小写。

返回
void

assertResponseNotEmpty() ¶ public

assertResponseNotEmpty(string $message = ''): void

断言响应内容不为空。

参数
string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseNotEquals() ¶ public

assertResponseNotEquals(mixed $content, string $message = ''): void

断言响应主体中的内容不相等。

参数
mixed $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseNotRegExp() ¶ public

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

断言响应主体与给定的正则表达式不匹配。

参数
string $pattern

要比较的模式。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseOk() ¶ public

assertResponseOk(string $message = ''): void

断言响应状态代码在 2xx 范围内。

参数
string $message optional

自定义失败消息。

返回
void

assertResponseRegExp() ¶ public

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

断言响应主体与给定的正则表达式匹配。

参数
string $pattern

要比较的模式。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertResponseSuccess() ¶ public

assertResponseSuccess(string $message = ''): void

断言响应状态码在 2xx/3xx 范围内。

参数
string $message optional

自定义失败消息。

返回
void

assertSession() ¶ public

assertSession(mixed $expected, string $path, string $message = ''): void

断言会话内容

参数
mixed $expected

预期的内容。

string $path

会话数据路径。使用 Hash::get() 兼容的符号。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertSessionHasKey() ¶ public

assertSessionHasKey(string $path, string $message = ''): void

断言会话键存在。

参数
string $path

会话数据路径。使用 Hash::get() 兼容的符号。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertSessionNotHasKey() ¶ public

assertSessionNotHasKey(string $path, string $message = ''): void

断言会话键不存在。

参数
string $path

会话数据路径。使用 Hash::get() 兼容的符号。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

assertTemplate() ¶ public

assertTemplate(string $content, string $message = ''): void

断言搜索字符串在模板名称中。

参数
string $content

要检查的内容。

string $message optional

将附加到生成的错误消息中的错误消息。

返回
void

cleanup() ¶ public

cleanup(): void

清除用于请求的状态。

返回
void

cleanupContainer() ¶ public

cleanupContainer(): void

清除任何已定义的模拟,并清理应用程序类配置。

返回
void

configApplication() ¶ public

configApplication(string $class, array|null $constructorArgs): void

配置要在集成测试中使用的应用程序类。

参数
string $class

应用程序类名。

array|null $constructorArgs

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

返回
void

configRequest() ¶ public

configRequest(array $data): void

配置下一个请求的数据,与现有状态合并。

此数据在 tearDown() 方法中清除。

您可以多次调用此方法以追加到当前状态。子键将与现有状态合并。

参数
array $data

要使用的请求数据。

返回
void

controllerSpy() ¶ public

controllerSpy(Cake\Event\EventInterface $event, Cake\Controller\Controller|null $controller = null): void

向控制器/视图事件管理器添加额外的事件间谍。

参数
Cake\Event\EventInterface $event

一个调度器事件。

Cake\Controller\Controller|null $controller optional

控制器实例。

返回
void

cookie() ¶ public

cookie(string $name, string $value): void

为将来的请求设置请求 Cookie。

此方法允许您配置要用于后续请求的会话数据。会话状态在每次 tearDown() 中重置。

您可以多次调用此方法以追加到当前状态。

参数
string $name

要使用的 Cookie 名称。

string $value

Cookie 的值。

返回
void

cookieEncrypted() ¶ public

cookieEncrypted(string $name, array|string $value, string|false $encrypt = 'aes', string|null $key = null): void

为将来的请求设置加密的请求 Cookie。

与 cookie() 的区别在于它使用 CookieComponent 对 Cookie 值进行加密。

参数
string $name

要使用的 Cookie 名称。

array|string $value

Cookie 的值。

string|false $encrypt optional

要使用的加密模式。

string|null $key optional

使用的加密密钥。默认为 Security.salt。

返回
void
参见
\Cake\Utility\CookieCryptTrait::_encrypt()

createApp() ¶ protected

createApp(): Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface

创建一个应用程序实例。

使用 configApplication() 中设置的配置。

返回
Cake\Core\HttpApplicationInterfaceCake\Core\ConsoleApplicationInterface

delete() ¶ public

delete(array|string $url): void

使用当前请求数据执行 DELETE 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

返回
void

disableErrorHandlerMiddleware() ¶ public

disableErrorHandlerMiddleware(): void

禁用错误处理中间件。

使用此函数后,异常不再由 ErrorHandlerMiddleware 捕获,而是由 TestExceptionRenderer 重新抛出。这在尝试诊断/调试测试用例中意外失败时很有用。

返回
void

enableCsrfToken() ¶ public

enableCsrfToken(string $cookieName = 'csrfToken'): void

调用此方法将向请求添加 CSRF 令牌。

启用此选项后,将填充 POST 数据和 Cookie。将使用默认参数名称。

参数
string $cookieName optional

CSRF 令牌 Cookie 的名称。

返回
void

enableRetainFlashMessages() ¶ public

enableRetainFlashMessages(): void

调用此方法将在 FlashHelper 删除后将闪存消息重新存储到测试会话中

返回
void

enableSecurityToken() ¶ public

enableSecurityToken(): void

调用此方法将启用与 SecurityComponent 兼容的令牌添加到请求数据中。这使您可以轻松测试受 SecurityComponent 保护的操作。

返回
void

extractExceptionMessage() ¶ protected

extractExceptionMessage(Exception $exception): string

提取现有异常的详细消息

参数
Exception $exception

要提取的异常。

返回
string

extractVerboseMessage() ¶ protected

extractVerboseMessage(string $message): string

检查控制器以提取断言失败的可能原因

参数
string $message

用作基准的原始消息。

返回
string

get() ¶ public

get(array|string $url): void

使用当前请求数据执行 GET 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

返回
void

getSession() ¶ protected

getSession(): Cake\TestSuite\TestSession
返回
Cake\TestSuite\TestSession

head() ¶ public

head(array|string $url): void

使用当前请求数据执行 HEAD 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

返回
void

isDebug() ¶ protected

isDebug(): bool

检查调试标志是否设置。

标志通过 --debug 设置。允许在启用调试时添加其他内容,例如不模拟。或显示响应体。

返回
bool

mockService() ¶ public

mockService(string $class, Closure $factory): $this

向容器添加模拟服务。

创建容器时,提供的类名将映射到工厂函数。工厂函数将用于创建模拟服务。

参数
string $class

您要定义的类或接口。

Closure $factory

模拟服务的工厂函数。

返回
$this

modifyContainer() ¶ public

modifyContainer(Cake\Event\EventInterface $event, Cake\Core\ContainerInterface $container): void

将应用程序的容器包装在一个包含模拟的容器中。

如果定义了任何模拟服务,应用程序的容器将被替换为包含模拟的容器。原始容器将被设置为模拟容器的委托。

参数
Cake\Event\EventInterface $event

事件。

Cake\Core\ContainerInterface $container

要包装的容器。

返回
void

options() ¶ public

options(array|string $url): void

使用当前请求数据执行 OPTIONS 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

返回
void

patch() ¶ public

patch(array|string $url, array|string $data = []): void

使用当前请求数据执行 PATCH 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

array|string $data optional

请求的数据。

返回
void

post() ¶ public

post(array|string $url, array|string $data = []): void

使用当前请求数据执行 POST 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

array|string $data optional

请求的数据。

返回
void

put() ¶ public

put(array|string $url, array|string $data = []): void

使用当前请求数据执行 PUT 请求。

已分派请求的响应将作为属性存储。您可以使用各种断言方法来检查响应。

参数
array|string $url

要请求的 URL。

array|string $data optional

请求的数据。

返回
void

removeMockService() ¶ public

removeMockService(string $class): $this

从容器中删除模拟服务。

参数
string $class

您要删除的类或接口。

返回
$this

replaceRequest() ¶ public

replaceRequest(array $data): void

配置下一个请求的数据,替换现有状态。

参数
array $data

要使用的请求数据。

返回
void

requestAsJson() ¶ public

requestAsJson(): void

设置下一个请求的 HTTP 标头,以识别为 JSON 请求。

返回
void

resolveRoute() ¶ protected

resolveRoute(array $url): string

通过路由将 URL 数组转换为字符串 URL。

参数
array $url

要解析的 URL。

返回
string

resolveUrl() ¶ public

resolveUrl(array|string $url): string

将提供的 URL 解析为字符串。

参数
array|string $url

要解析的 URL 数组/字符串。

返回
string

responseBody() ¶ protected

responseBody(): string

调试响应主体的內容。

返回
string

session() ¶ public

session(array $data): void

设置会话数据。

此方法允许您配置要用于后续请求的会话数据。会话状态在每次 tearDown() 中重置。

您可以多次调用此方法以追加到当前状态。

参数
array $data

要使用的会话数据。

返回
void

setUnlockedFields() ¶ public

setUnlockedFields(list<string> $unlockedFields = []): void

设置从字段验证中排除的字段列表。

参数
list<string> $unlockedFields optional

从字段验证中排除的字段列表。

返回
void

viewVariable() ¶ public

viewVariable(string $name): mixed

按名称获取视图变量。

如果视图变量不存在,将返回 null。

参数
string $name

要获取的视图变量。

返回
mixed

属性详情

$_appArgs ¶ protected

自定义应用程序构造函数参数。

类型
array|null

$_appClass ¶ protected

自定义应用程序类名。

类型
string|null

$_controller ¶ protected

上次请求中使用的控制器。

类型
Cake\Controller\Controller|null

$_cookie ¶ protected

下一个请求中使用的 Cookie 数据。

类型
array

$_cookieEncryptionKey ¶ protected

类型
string|null

$_csrfKeyName ¶ protected

检索 csrf 令牌时使用的名称。

类型
string

$_csrfToken ¶ protected

请求是否应添加 CSRF 令牌的布尔标志。

类型
bool

$_exception ¶ protected

如果出现这种情况,则抛出的异常。

类型
Throwable|null

$_flashMessages ¶ 受保护的

渲染前的存储的闪存消息

类型
array

$_layoutName ¶ 受保护的

最后渲染的布局

类型
string|null

$_request ¶ 受保护的

用于构建下一个请求的数据。

类型
array

$_requestSession ¶ 受保护的

上次请求的会话实例

类型
Cake\Http\Session|null

$_response ¶ 受保护的

最近请求的响应。

类型
Psr\Http\Message\ResponseInterface|null

$_retainFlashMessages ¶ 受保护的

请求是否应重新存储闪存消息的布尔标志

类型
bool

$_securityToken ¶ 受保护的

请求是否应添加 SecurityComponent 令牌的布尔标志。

类型
bool

$_session ¶ 受保护的

下一个请求中使用的会话数据。

类型
array

$_unlockedFields ¶ 受保护的

从字段验证中排除的字段列表。

类型
list<string>

$_validCiphers ¶ 受保护的

加密 Cookie 的有效密码名称。

类型
list<string>

$_viewName ¶ 受保护的

最后渲染的视图

类型
string|null
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 书籍
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与
  • 问题 (Github)
  • 烘焙坊
  • 特色资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • 领英
  • YouTube
  • 脸书
  • 推特
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API 文档 生成