本文整理汇总了PHP中PHPUnit_Framework_Constraint::evaluate方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_Constraint::evaluate方法的具体用法?PHP PHPUnit_Framework_Constraint::evaluate怎么用?PHP PHPUnit_Framework_Constraint::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_Constraint
的用法示例。
在下文中一共展示了PHPUnit_Framework_Constraint::evaluate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: matches
protected function matches($other)
{
if (!$other instanceof ResponseInterface) {
return false;
}
return $this->status->evaluate($other->getStatusCode(), '', true);
}
示例2: evaluate
/**
* {@inheritdoc}
* @see PHPUnit_Framework_Constraint::evaluate()
*/
public function evaluate($other, $description = '', $returnResult = false)
{
if (!array_key_exists($this->arrayKey, $other)) {
return false;
}
$this->value = $other[$this->arrayKey];
return $this->constraint->evaluate($other[$this->arrayKey]);
}
示例3: evaluate
/**
* Evaluates the constraint for parameter $other
*
* If $returnResult is set to false (the default), an exception is thrown
* in case of a failure. null is returned otherwise.
*
* If $returnResult is true, the result of the evaluation is returned as
* a boolean value instead: true in case of success, false in case of a
* failure.
*
* @param mixed $other
* Value or object to evaluate.
* @param string $description
* Additional information about the test
* @param bool $returnResult
* Whether to return a result or throw an exception
*
* @return mixed
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
{
try {
return $this->innerConstraint->evaluate($other, $description, $returnResult);
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$this->fail($other, $description);
}
}
示例4: matches
protected function matches($other)
{
if (!$other instanceof MessageInterface) {
return false;
}
$other->getBody()->rewind();
$body = $other->getBody()->getContents();
return $this->constraint->evaluate($body, '', true);
}
示例5: evaluate
/**
* Evaluates the constraint for parameter $other
*
* If $returnResult is set to false (the default), an exception is thrown
* in case of a failure. null is returned otherwise.
*
* If $returnResult is true, the result of the evaluation is returned as
* a boolean value instead: true in case of success, false in case of a
* failure.
*
* @param mixed $other Value or object to evaluate.
* @param string $description Additional information about the test
* @param bool $returnResult Whether to return a result or throw an exception
*
* @return mixed
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
{
$success = !$this->constraint->evaluate($other, $description, true);
if ($returnResult) {
return $success;
}
if (!$success) {
$this->fail($other, $description);
}
}
示例6: testDefaultSchema
public function testDefaultSchema()
{
$this->constraint = new ResponseBodyConstraint($this->schemaManager, '/pets', 'get', 222);
$response = <<<JSON
{
"code": 123456789,
"message": "foo"
}
JSON;
$response = json_decode($response);
self::assertTrue($this->constraint->evaluate($response, '', true), $this->constraint->evaluate($response));
}
示例7: matches
/**
* Executes the matcher on a given argument value.
*
* Forwards the call to PHPUnit's evaluate() method.
*
* @param mixed $argument
* @throws Phake_Exception_MethodMatcherException
*/
protected function matches(&$argument)
{
try {
$this->constraint->evaluate($argument, '');
} catch (PHPUnit_Framework_ExpectationFailedException $e) {
$failure = $e->getComparisonFailure();
if ($failure instanceof PHPUnit_Framework_ComparisonFailure) {
$failure = $failure->getDiff();
} else {
$failure = '';
}
throw new Phake_Exception_MethodMatcherException($e->getMessage() . "\n" . $failure, $e);
}
}
示例8: matches
protected function matches($other)
{
if (!$other instanceof MessageInterface) {
return false;
}
if (!$other->hasHeader($this->name)) {
return false;
}
foreach ($other->getHeader($this->name) as $value) {
if ($this->constraint->evaluate($value, '', true)) {
return true;
}
}
return false;
}
示例9: evaluate
/**
* Evaluates the constraint for parameter $other
*
* If $returnResult is set to false (the default), an exception is thrown
* in case of a failure. null is returned otherwise.
*
* If $returnResult is true, the result of the evaluation is returned as
* a boolean value instead: true in case of success, false in case of a
* failure.
*
* @param mixed $other Value or object to evaluate.
* @param string $description Additional information about the test
* @param bool $returnResult Whether to return a result or throw an exception
*
* @return mixed
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = false)
{
$success = true;
foreach ($other as $item) {
if (!$this->constraint->evaluate($item, '', true)) {
$success = false;
break;
}
}
if ($returnResult) {
return $success;
}
if (!$success) {
$this->fail($other, $description);
}
}
示例10: testInvalidHeaderType
public function testInvalidHeaderType()
{
$headers = ['Content-Type' => 'application/json'];
self::assertFalse($this->constraint->evaluate($headers, '', true));
try {
$this->constraint->evaluate($headers);
self::fail('Expected ExpectationFailedException to be thrown');
} catch (ExpectationFailedException $e) {
self::assertEquals(<<<EOF
Failed asserting that {"Content-Type":"application\\/json"} is valid.
[etag] The property etag is required
EOF
, TestFailure::exceptionToString($e));
}
}
示例11: evaluate
/**
* Evaluates the constraint for parameter $other
*
* If $returnResult is set to false (the default), an exception is thrown
* in case of a failure. null is returned otherwise.
*
* If $returnResult is true, the result of the evaluation is returned as
* a boolean value instead: true in case of success, false in case of a
* failure.
*
* @param mixed $other Value or object to evaluate.
* @param string $description Additional information about the test
* @param bool $returnResult Whether to return a result or throw an exception
*
* @return mixed
*
* @throws PHPUnit_Framework_ExpectationFailedException
*/
public function evaluate($other, $description = '', $returnResult = FALSE)
{
$success = TRUE;
foreach ($other as $item) {
if (!$this->constraint->evaluate($item, '', TRUE)) {
$success = FALSE;
break;
}
}
if ($returnResult) {
return $success;
}
if (!$success) {
$this->fail($other, $description);
}
}
示例12: evaluate
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Value or object to evaluate.
* @return bool
*/
public function evaluate($other)
{
return $this->constraint->evaluate(
PHPUnit_Framework_Assert::readAttribute(
$other, $this->attributeName
)
);
}
示例13: evaluate
/**
* Overridden function to cover differences between PHPUnit 3.5 and 3.6.
* Intentionally made final so people have to use match() from now on.
* match() should be abstract really, but isn't, the usual PHPUnit quality...
*
* @param mixed The item to evaluate.
* @param string Additional information about the test (3.6+).
* @param bool Whether to return a result or throw an exception (3.6+).
*
* @author David Zülke <david.zuelke@bitextender.com>
* @since 1.0.7
*/
public function evaluate($other, $description = '', $returnResult = false)
{
if (version_compare(PHPUnit_Runner_Version::id(), '3.6', '<')) {
return $this->matches($other);
} else {
return parent::evaluate($other, $description, $returnResult);
}
}
开发者ID:horros,项目名称:agavi,代码行数:20,代码来源:AgaviBaseConstraintBecausePhpunitSucksAtBackwardsCompatibility.class.php
示例14: evaluate
/**
* Evaluates the constraint for parameter $other. Returns TRUE if the
* constraint is met, FALSE otherwise.
*
* @param mixed $other Value or object to evaluate.
* @return bool
*/
public function evaluate($other)
{
foreach ($other as $item) {
if (!$this->constraint->evaluate($item)) {
return FALSE;
}
}
return TRUE;
}
示例15: matches
/**
* @inheritdoc
*/
protected function matches($other)
{
if (is_string($other)) {
$other = json_decode($other);
}
$result = (new JSONPath($other))->find($this->jsonPath);
if (!isset($result[0])) {
return false;
}
$combineFunc = $this->buildCombinationFunction();
$matches = null;
foreach ($result as $v) {
if ($v instanceof JSONPath) {
$v = $v->data();
}
$singleMatchResult = $this->constraint->evaluate($v, '', true);
$matches = $combineFunc($matches, $singleMatchResult);
}
return $matches;
}