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
        • Email
        • Response
        • Session
        • View
      • Fixture
      • Stub
    • Utility
    • Validation
    • View

类 StatusCode

StatusCode

命名空间: Cake\TestSuite\Constraint\Response

属性摘要

  • $code protected
    array<int, int>|int
  • $response protected
    Psr\Http\Message\ResponseInterface

方法摘要

  • __construct() public

    构造函数

  • _getBodyAsString() protected

    将响应主体作为字符串获取

  • additionalFailureDescription() protected

    根据需要返回额外的失败描述。

  • count() public

    计算约束元素的数量。

  • evaluate() public

    评估参数 $other 的约束条件。

  • fail() protected

    针对给定的比较值和测试描述抛出异常。

  • failureDescription() public

    失败描述

  • failureDescriptionInContext() protected

    当此约束条件出现在 $operator 表达式上下文中时,返回失败的描述。

  • matches() public

    检查断言

  • readCookie() protected

    从响应 cookie 集合或标头中读取 cookie

  • reduce() protected

    通过跳过退化的子表达式来减少从 $this 开始的子表达式,并返回第一个从非可减少子表达式开始的后代约束条件。

  • statusCodeBetween() protected

    用于检查状态码的助手

  • toString() public

    断言消息

  • toStringInContext() protected

    当约束对象出现在 $operator 表达式上下文中时,返回约束对象的自定字符串表示形式。

  • valueToTypeStringFragment() protected

方法详情

__construct() ¶ public

__construct(Psr\Http\Message\ResponseInterface|null $response)

构造函数

参数
Psr\Http\Message\ResponseInterface|null $response

Response

_getBodyAsString() ¶ protected

_getBodyAsString(): string

将响应主体作为字符串获取

返回值
string

additionalFailureDescription() ¶ protected

additionalFailureDescription(mixed $other): string

根据需要返回额外的失败描述。

此函数可以被重写以提供额外的失败信息,例如 diff

参数
mixed $other
返回值
string

count() ¶ public

count(): int

计算约束元素的数量。

返回值
int

evaluate() ¶ public

evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool

评估参数 $other 的约束条件。

如果 $returnResult 设置为 false(默认值),则在失败的情况下会抛出异常。否则返回 null。

如果 $returnResult 设置为 true,则评估结果将作为布尔值返回:成功为 true,失败为 false。

参数
mixed $other
string $description optional
bool $returnResult optional
返回值
?bool
抛出
ExpectationFailedException

fail() ¶ protected

fail(mixed $other, string $description, ?ComparisonFailure $comparisonFailure = null): never

针对给定的比较值和测试描述抛出异常。

参数
mixed $other
string $description
?ComparisonFailure $comparisonFailure optional
返回值
never
抛出
ExpectationFailedException

failureDescription() ¶ public

failureDescription(mixed $other): string

失败描述

在大多数情况下,失败消息的开头是“Failed asserting that”。此方法应该返回该句子的第二部分。

要提供额外的失败信息,可以使用 additionalFailureDescription。

参数
mixed $other

预期代码

返回值
string

failureDescriptionInContext() ¶ protected

failureDescriptionInContext(Operator $operator, mixed $role, mixed $other): string

当此约束条件出现在 $operator 表达式上下文中时,返回失败的描述。

此方法的目的是在逻辑非等运算符的上下文中提供有意义的失败描述。原生 PHPUnit 约束在逻辑非等运算符中默认支持,但外部开发的约束条件无法在此上下文中提供正确的消息。

如果此方法不自行处理自定义,则应返回空字符串。

参数
Operator $operator
mixed $role
mixed $other
返回值
string

matches() ¶ public

matches(array<int, int>|int $other): bool

检查断言

此方法可以被重写以实现评估算法。

参数
array<int, int>|int $other

最小/最大状态码数组,或单个代码

返回值
bool

readCookie() ¶ protected

readCookie(string $name): array|null

从响应 cookie 集合或标头中读取 cookie

参数
string $name

要读取的 cookie 的名称。

返回值
array|null

reduce() ¶ protected

reduce(): self

通过跳过退化的子表达式来减少从 $this 开始的子表达式,并返回第一个从非可减少子表达式开始的后代约束条件。

对于终端约束条件和从非可减少子表达式开始的运算符,返回 $this,或者返回 $this 的最近后代,它从非可减少子表达式开始。

约束表达式可以被建模为一个树,该树具有非终端节点(运算符)和终端节点。例如

LogicalOr(运算符,非终端节点)

  • LogicalAnd(运算符,非终端节点) | + IsType('int')(终端节点) | + GreaterThan(10)(终端节点)
  • LogicalNot(运算符,非终端节点)
    • IsType('array')(终端节点)

退化的子表达式是树的一部分,它实际上对包含它的表达式的评估没有贡献。退化子表达式的示例是使用单个操作数或嵌套的二元运算符(每个二元运算符都使用单个操作数)构造的二元运算符。涉及退化子表达式的表达式等同于删除了退化子表达式的简化表达式,例如

LogicalAnd(运算符)

  • LogicalOr(退化运算符) | + LogicalAnd(退化运算符) | + IsType('int')(终端节点)
  • GreaterThan(10)(终端节点)

等同于

LogicalAnd(运算符)

  • IsType('int')(终端节点)
  • GreaterThan(10)(终端节点)

因为子表达式

  • LogicalOr
    • LogicalAnd
      • -

是退化的。在上面的 LogicalOr 对象上调用 reduce(),以及在 LogicalAnd 上调用 reduce(),都将返回 IsType('int') 实例。

可以实现其他具体的简化,例如 LogicalNot 运算符的级联

  • LogicalNot
    • LogicalNot +LogicalNot
      • IsTrue

可以简化为

LogicalNot

  • IsTrue
返回值
self

statusCodeBetween() ¶ protected

statusCodeBetween(int $min, int $max): bool

用于检查状态码的助手

参数
int $min

最小状态码(包含)

int $max

最大状态码(包含)

返回值
bool

toString() ¶ public

toString(): string

断言消息

返回值
string

toStringInContext() ¶ protected

toStringInContext(Operator $operator, mixed $role): string

当约束对象出现在 $operator 表达式上下文中时,返回约束对象的自定字符串表示形式。

此方法的目的是在 LogicalNot 等运算符的上下文中提供有意义的描述性字符串。原生 PHPUnit 约束在 LogicalNot 中开箱即用,但外部开发的约束无法在此上下文中提供正确的字符串。

如果此方法不自行处理自定义,则应返回空字符串。

参数
Operator $operator
mixed $role
返回值
string

valueToTypeStringFragment() ¶ protected

valueToTypeStringFragment(mixed $value): non-empty-string
参数
mixed $value
返回值
非空字符串

属性详情

$code ¶ protected

类型
array<int, int>|int

$response ¶ protected

类型
Psr\Http\Message\ResponseInterface
OpenHub
Pingping
Linode
  • 商业解决方案
  • 展示
  • 文档
  • 手册
  • API
  • 视频
  • 报告安全问题
  • 隐私政策
  • 标识和商标
  • 社区
  • 参与进来
  • 问题 (Github)
  • 面包店
  • 精选资源
  • 培训
  • 聚会
  • 我的 CakePHP
  • CakeFest
  • 时事通讯
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • 帮助和支持
  • 论坛
  • Stack Overflow
  • IRC
  • Slack
  • 付费支持

使用 CakePHP API Docs 生成