类 HeaderSet
HeaderSet
属性摘要
- 
        $headerName 受保护的字符串
- 
        $response 受保护的Psr\Http\Message\ResponseInterface
方法摘要
- 
          __construct() 公共的构造函数。 
- 
          _getBodyAsString() 受保护的将响应主体作为字符串获取 
- 
          additionalFailureDescription() 受保护的在需要时返回额外的失败描述。 
- 
          count() 公共的计算约束元素的数量。 
- 
          evaluate() 公共的评估参数 $other 的约束。 
- 
          fail() 受保护的为给定的比较值和测试描述抛出异常。 
- 
          failureDescription() 受保护的覆盖描述,以便我们可以删除自动的“预期”消息 
- 
          failureDescriptionInContext() 受保护的当此约束出现在 $operator 表达式的上下文中时,返回失败的描述。 
- 
          matches() 公共的检查断言 
- 
          readCookie() 受保护的从响应 cookie 集合或标题中读取 cookie 
- 
          reduce() 受保护的通过跳过退化的子表达式,减少从 $this 开始的子表达式,并返回第一个开始非可约子表达式的后代约束。 
- 
          toString() 公共的断言消息 
- 
          toStringInContext() 受保护的当约束出现在 $operator 表达式的上下文中时,返回约束对象的自定义字符串表示形式。 
- 
          valueToTypeStringFragment() 受保护的
方法详细说明
__construct() ¶ 公共的
__construct(Psr\Http\Message\ResponseInterface|null $response, string $headerName)构造函数。
参数
- 
                Psr\Http\Message\ResponseInterface|null$response
- 一个响应实例。 
- 
                字符串$headerName
- 标题名称 
additionalFailureDescription() ¶ 受保护的
additionalFailureDescription(mixed $other): string在需要时返回额外的失败描述。
该函数可以被覆盖以提供额外的失败信息,例如差异
参数
- 
                混合$other
返回值
字符串evaluate() ¶ 公共的
evaluate(mixed $other, string $description = '', bool $returnResult = false): ?bool评估参数 $other 的约束。
如果 $returnResult 设置为 false(默认值),则在失败的情况下抛出异常。否则返回 null。
如果 $returnResult 为 true,则评估结果将作为布尔值返回:成功时为 true,失败时为 false。
参数
- 
                混合$other
- 
                字符串$description 可选的
- 
                布尔值$returnResult 可选的
返回值
?布尔值抛出
ExpectationFailedExceptionfail() ¶ 受保护的
fail(mixed $other, string $description, ?ComparisonFailure $comparisonFailure = null): never为给定的比较值和测试描述抛出异常。
参数
- 
                混合$other
- 
                字符串$description
- 
                ?ComparisonFailure$comparisonFailure 可选的
返回值
永远不会抛出
ExpectationFailedExceptionfailureDescription() ¶ 受保护的
failureDescription(mixed $other): string覆盖描述,以便我们可以删除自动的“预期”消息
在大多数情况下,失败消息的开头是“断言失败”。此方法应返回该句子的第二部分。
要提供额外的失败信息,可以使用 additionalFailureDescription。
参数
- 
                混合$other
- 价值 
返回值
字符串failureDescriptionInContext() ¶ 受保护的
failureDescriptionInContext(Operator $operator, mixed $role, mixed $other): string当此约束出现在 $operator 表达式的上下文中时,返回失败的描述。
此方法的目的是在诸如 LogicalNot 之类的运算符的上下文中提供有意义的失败描述。本机 PHPUnit 约束在 LogicalNot 中开箱即用地受支持,但外部开发的约束无法在该上下文中提供正确的消息。
该方法应返回空字符串,如果它本身不处理自定义。
参数
- 
                运算符$operator
- 
                混合$role
- 
                混合$other
返回值
字符串readCookie() ¶ 受保护的
readCookie(string $name): array|null从响应 cookie 集合或标题中读取 cookie
参数
- 
                字符串$name
- 您要读取的 cookie 的名称。 
返回值
数组|nullreduce() ¶ 受保护的
reduce(): self通过跳过退化的子表达式,减少从 $this 开始的子表达式,并返回第一个开始非可约子表达式的后代约束。
对于终端约束和开始非可约子表达式的运算符返回 $this,或者返回 $this 的最近后代,该后代开始非可约子表达式。
约束表达式可以被建模为一棵树,树上有非终端节点(运算符)和终端节点。例如
LogicalOr(运算符,非终端)
- LogicalAnd(运算符,非终端)| + IsType('int')(终端)| + GreaterThan(10)(终端)
- LogicalNot(运算符,非终端)- IsType('array')(终端)
 
退化的子表达式是树的一部分,它实际上对它所在的表达式的评估没有贡献。退化子表达式的例子是使用单个操作数或嵌套的 BinaryOperators(每个操作数都有单个操作数)构建的 BinaryOperator。涉及退化子表达式的表达式等同于删除退化子表达式的简化表达式,例如
LogicalAnd(运算符)
- LogicalOr(退化运算符)| + LogicalAnd(退化运算符)| + IsType('int')(终端)
- GreaterThan(10)(终端)
等同于
LogicalAnd(运算符)
- IsType('int')(终端)
- GreaterThan(10)(终端)
因为子表达式
- LogicalOr- LogicalAnd- -
 
 
- LogicalAnd
是退化的。在上面的 LogicalOr 对象上调用 reduce(),以及在 LogicalAnd 上调用 reduce(),都将返回 IsType('int') 实例。
可以实现其他特定减少,例如 LogicalNot 运算符的级联
- LogicalNot- LogicalNot +LogicalNot- IsTrue
 
 
- LogicalNot +LogicalNot
可以简化为
LogicalNot
- IsTrue
返回值
自身toStringInContext() ¶ 受保护的
toStringInContext(Operator $operator, mixed $role): string当约束出现在 $operator 表达式的上下文中时,返回约束对象的自定义字符串表示形式。
此方法的目的是在诸如 LogicalNot 之类的运算符的上下文中提供有意义的描述性字符串。本机 PHPUnit 约束在 LogicalNot 中开箱即用地受支持,但外部开发的约束无法在该上下文中提供正确的字符串。
该方法应返回空字符串,如果它本身不处理自定义。
参数
- 
                运算符$operator
- 
                混合$role
返回值
字符串valueToTypeStringFragment() ¶ 受保护的
valueToTypeStringFragment(mixed $value): non-empty-string参数
- 
                混合$value
返回值
非空字符串