类 ContentsContainRow
ContentsContainRow
方法摘要
- 
          __construct() public构造函数 
- 
          additionalFailureDescription() protected返回需要时的附加失败描述。 
- 
          count() public计算约束元素的数量。 
- 
          evaluate() public评估参数 $other 的约束。 
- 
          fail() protected为给定的比较值和测试描述抛出异常。 
- 
          failureDescription() public返回失败的描述。 
- 
          failureDescriptionInContext() protected返回此约束出现在 $operator 表达式上下文中的失败描述。 
- 
          matches() public检查内容是否包含预期内容 
- 
          reduce() protected通过跳过退化子表达式来减少从 $this 开始的子表达式,并返回第一个开始非可减少子表达式的后代约束。 
- 
          toString() public断言消息 
- 
          toStringInContext() protected当约束出现在 $operator 表达式上下文中的时候,返回约束对象的自定义字符串表示形式。 
- 
          valueToTypeStringFragment() protected
方法详细
__construct() ¶ public
__construct(list<string> $contents, string $output)构造函数
参数
- 
                list<string>$contents
- 内容 
- 
                string$output
- 输出类型 
additionalFailureDescription() ¶ protected
additionalFailureDescription(mixed $other): string返回需要时的附加失败描述。
该函数可以被覆盖以提供额外的失败信息,比如差异
参数
- 
                mixed$other
返回值
stringevaluate() ¶ 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抛出
ExpectationFailedExceptionfail() ¶ protected
fail(mixed $other, string $description, ?ComparisonFailure $comparisonFailure = null): never为给定的比较值和测试描述抛出异常。
参数
- 
                mixed$other
- 
                string$description
- 
                ?ComparisonFailure$comparisonFailure optional
返回值
never抛出
ExpectationFailedExceptionfailureDescription() ¶ public
failureDescription(mixed $other): string返回失败的描述。
在大多数情况下,失败消息的开头是“Failed asserting that”。此方法应返回该句子的第二部分。
要提供额外的失败信息,可以使用 additionalFailureDescription。
参数
- 
                mixed$other
- 预期内容 
返回值
stringfailureDescriptionInContext() ¶ protected
failureDescriptionInContext(Operator $operator, mixed $role, mixed $other): string返回此约束出现在 $operator 表达式上下文中的失败描述。
此方法的目的是在 LogicalNot 等运算符的上下文中提供有意义的失败描述。原生 PHPUnit 约束由 LogicalNot 开箱即用地支持,但外部开发的约束在该上下文中无法提供正确的消息。
如果该方法没有自行处理定制,则应返回空字符串。
参数
- 
                Operator$operator
- 
                mixed$role
- 
                mixed$other
返回值
stringmatches() ¶ public
matches(mixed $other): bool检查内容是否包含预期内容
此方法可以被覆盖以实现评估算法。
参数
- 
                mixed$other
- 行 
返回值
boolreduce() ¶ 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- -
 
 
- LogicalAnd
是退化的。在上面的 LogicalOr 对象上调用 reduce(),以及在 LogicalAnd 上调用 reduce(),都将返回 IsType('int') 实例。
可以实现其他特定缩减,例如 LogicalNot 运算符的级联
- LogicalNot- LogicalNot +LogicalNot- IsTrue
 
 
- LogicalNot +LogicalNot
可以简化为
LogicalNot
- IsTrue
返回值
selftoStringInContext() ¶ protected
toStringInContext(Operator $operator, mixed $role): string当约束出现在 $operator 表达式上下文中的时候,返回约束对象的自定义字符串表示形式。
此方法的目的是在 LogicalNot 等运算符的上下文中提供有意义的描述性字符串。原生 PHPUnit 约束由 LogicalNot 开箱即用地支持,但外部开发的约束在该上下文中无法提供正确的字符串。
如果该方法没有自行处理定制,则应返回空字符串。
参数
- 
                Operator$operator
- 
                mixed$role
返回值
stringvalueToTypeStringFragment() ¶ protected
valueToTypeStringFragment(mixed $value): non-empty-string参数
- 
                mixed$value
返回值
非空字符串