类 MailConstraintBase
所有邮件断言约束的基类
属性摘要
- 
        $at protectedint|null
方法摘要
- 
          __construct() public构造函数 
- 
          additionalFailureDescription() protected在需要时返回附加的失败描述。 
- 
          count() public计算约束元素的数量。 
- 
          evaluate() public评估参数 $other 的约束。 
- 
          fail() protected针对给定的比较值和测试描述抛出异常。 
- 
          failureDescription() protected返回失败的描述。 
- 
          failureDescriptionInContext() protected当此约束出现在 $operator 表达式的上下文中时,返回失败的描述。 
- 
          getMessages() public获取要检查的电子邮件或电子邮件 
- 
          matches() protected评估参数 $other 的约束。如果满足约束,则返回 true,否则返回 false。 
- 
          reduce() protected通过跳过退化子表达式,从 $this 开始减少子表达式,并返回第一个开始非可简化子表达式的后代约束。 
- 
          toString() public返回对象的字符串表示形式。 
- 
          toStringInContext() protected当约束出现在 $operator 表达式的上下文中时,返回约束对象的自定义字符串表示形式。 
- 
          valueToTypeStringFragment() protected
方法详细说明
__construct() ¶ public
__construct(int|null $at = null): void构造函数
参数
- 
                int|null$at optional
- At 
返回值
voidadditionalFailureDescription() ¶ 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() ¶ protected
failureDescription(mixed $other): string返回失败的描述。
大多数情况下,失败消息的开头是“断言失败”。此方法应返回该句子的第二部分。
要提供额外的失败信息,可以使用 additionalFailureDescription。
参数
- 
                mixed$other
返回值
stringfailureDescriptionInContext() ¶ protected
failureDescriptionInContext(Operator $operator, mixed $role, mixed $other): string当此约束出现在 $operator 表达式的上下文中时,返回失败的描述。
此方法的目的是在 LogicalNot 等运算符的上下文中提供有意义的失败描述。原生 PHPUnit 约束通过 LogicalNot 获得开箱即用的支持,但外部开发的约束没有办法在此上下文中提供正确的消息。
如果该方法不自行处理自定义,则应返回空字符串。
参数
- 
                Operator$operator
- 
                mixed$role
- 
                mixed$other
返回值
stringgetMessages() ¶ public
getMessages(): arrayCake\Mailer\Message>获取要检查的电子邮件或电子邮件
返回值
arrayCake\Mailer\Message>matches() ¶ protected
matches(mixed $other): bool评估参数 $other 的约束。如果满足约束,则返回 true,否则返回 false。
此方法可以被覆盖以实现评估算法。
参数
- 
                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
返回值
非空字符串