evaluate() public method

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.
public evaluate ( mixed $other, string $description = '', boolean $returnResult = false ) : mixed
$other mixed Value or object to evaluate.
$description string Additional information about the test
$returnResult boolean Whether to return a result or throw an exception
return mixed
 protected function matches($other)
 {
     if (!$other instanceof ResponseInterface) {
         return false;
     }
     return $this->status->evaluate($other->getStatusCode(), '', true);
 }
Example #2
0
 /**
  * {@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]);
 }
Example #3
0
 /**
  * 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);
     }
 }
 protected function matches($other)
 {
     if (!$other instanceof MessageInterface) {
         return false;
     }
     $other->getBody()->rewind();
     $body = $other->getBody()->getContents();
     return $this->constraint->evaluate($body, '', true);
 }
Example #5
0
 /**
  * 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);
     }
 }
    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));
    }
 /**
  * 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);
     }
 }
 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;
 }
 /**
  * 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);
     }
 }
    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));
        }
    }
 /**
  * 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);
     }
 }
Example #12
0
 /**
  * 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
       )
     );
 }
 /**
  * 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 <*****@*****.**>
  * @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);
     }
 }
 /**
  * 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;
 }
 /**
  * @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;
 }
 /**
  *
  *
  * @param  mixed                        $value
  * @param  PHPUnit_Framework_Constraint $constraint
  * @param  string                       $message
  * @access public
  * @static
  * @since  Method available since Release 3.0.0
  */
 public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
 {
     if (!$constraint->evaluate($value)) {
         $constraint->fail($value, $message);
     }
 }
 /**
  * @param  PHPUnit_Framework_MockObject_Invocation $invocation
  * @return boolean
  */
 public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
 {
     return $this->constraint->evaluate($invocation->methodName, '', TRUE);
 }
Example #18
0
 /**
  * Evaluates a constraint for the given value.
  *
  * @param mixed                         $value
  * @param \PHPUnit_Framework_Constraint $constraint
  * @param string                        $message
  *
  * @return bool
  */
 public static function evaluate($value, \PHPUnit_Framework_Constraint $constraint, $message = '')
 {
     return $constraint->evaluate($value, $message, true);
 }
Example #19
0
 /**
  * Evalutes constraint that is passed in the parameter
  *
  * @param Varien_Simplexml_Config $config
  * @see PHPUnit_Framework_Constraint::evaluate()
  */
 public function evaluate($config, $description = '', $returnResult = false)
 {
     $nodeValue = $this->getNodeValue($config);
     return $this->constraint->evaluate($nodeValue, $description, $returnResult);
 }
Example #20
0
 /**
  *
  *
  * @param  mixed                        $value
  * @param  PHPUnit_Framework_Constraint $constraint
  * @param  string                       $message
  * @since  Method available since Release 3.0.0
  */
 public static function assertThat($value, PHPUnit_Framework_Constraint $constraint, $message = '')
 {
     $stack = debug_backtrace();
     for ($i = 1; $i <= 2; $i++) {
         if (isset($stack[$i]['object']) && $stack[$i]['object'] instanceof PHPUnit_Framework_TestCase) {
             $test = $stack[$i]['object'];
         }
     }
     if (isset($test)) {
         $test->incrementAssertionCounter();
     }
     if (!$constraint->evaluate($value)) {
         $constraint->fail($value, $message);
     }
 }
Example #21
0
 /**
  * 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($other);
 }
 public function testDefaultMediaType()
 {
     $this->constraint = new ResponseMediaTypeConstraint($this->schemaManager, '/pets', 'delete');
     self::assertTrue($this->constraint->evaluate('application/json', '', true));
 }
Example #23
0
 /**
  * Executes the matcher on a given argument value.
  *
  * Forwards the call to PHPUnit's evaluate() method.
  *
  * @param mixed $argument
  *
  * @return boolean
  */
 public function matches(&$argument)
 {
     return $this->constraint->evaluate($argument, '', true);
 }
 private function assertConstraintPasses(\PHPUnit_Framework_Constraint $constraint)
 {
     $this->assertTrue($constraint->evaluate($this->containerBuilder, '', true));
 }