toString() public static method

public static toString ( $value, $short = FALSE )
Beispiel #1
0
    public function toString()
    {
        return sprintf(
          'return user-specified value %s',

          PHPUnit_Util_Type::toString($this->value)
        );
    }
Beispiel #2
0
    public function toString()
    {
        return sprintf(
          'raise user-specified exception %s',

          PHPUnit_Util_Type::toString($this->exception)
        );
    }
Beispiel #3
0
 /**
  * @param PHPUnit_Framework_MockObject_Invocation $invocation
  * @return the invocation of the Entry with matching parameters.
  */
 public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation)
 {
     foreach ($this->return_map as $entry) {
         if ($entry->matches($invocation)) {
             return $entry->invoke($invocation);
         }
     }
     PHPUnit_Framework_Assert::fail(sprintf('No return value defined for %s', PHPUnit_Util_Type::toString($invocation->parameters)));
 }
Beispiel #4
0
    /**
     * Returns a string describing the type difference between the expected
     * and the actual value.
     */
    public function toString()
    {
        return sprintf(
          '%s does not match expected type "%s".',

          PHPUnit_Util_Type::toString($this->actual),
          gettype($this->expected)
        );
    }
Beispiel #5
0
 /**
  * For layout, actual value should be always set
  * (non-PHPdoc)
  * @see Mage_PHPUnit_Constraint_Abstract::getActualValue()
  */
 protected function getActualValue($other)
 {
     if ($this->_useActualValue) {
         if (is_array($this->_actualValue)) {
             return PHPUnit_Util_Type::toString($this->_actualValue);
         }
         return parent::getActualValue($other);
     }
     return '';
 }
Beispiel #6
0
    /**
     * Returns a string describing the difference between the expected and the
     * actual scalar value.
     */
    public function toString()
    {
        return sprintf(
          'Failed asserting that %s %s %s.',

          PHPUnit_Util_Type::toString($this->actual),
          $this->identical ? 'is identical to' : 'matches expected',
          PHPUnit_Util_Type::toString($this->expected)
        );
    }
Beispiel #7
0
 /**
  * Returning user friendly actual value
  * (non-PHPdoc)
  * @see Mage_PHPUnit_Constraint_Abstract::getActualValue()
  */
 protected function getActualValue($other)
 {
     if ($this->_useActualValue) {
         if ($this->_actualValue instanceof Varien_Object) {
             $value = $this->_actualValue->debug();
         } else {
             $value = $this->_actualValue;
         }
         return PHPUnit_Util_Type::toString($value);
     }
     return '';
 }
Beispiel #8
0
 public function fail($other, $description, \SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = NULL)
 {
     throw new PHPUnit_Framework_ExpectationFailedException(sprintf('%sFailed asserting that %s contains a query element that restricts the search to groups', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE)), NULL);
 }
Beispiel #9
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'is greater than ' . PHPUnit_Util_Type::toString($this->value);
 }
Beispiel #10
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'has the key ' . PHPUnit_Util_Type::toString($this->key);
 }
Beispiel #11
0
 public static function shortenedString($string)
 {
     $string = preg_replace('#\\n|\\r\\n|\\r#', ' ', $string);
     if (strlen($string) > 14) {
         return PHPUnit_Util_Type::toString(substr($string, 0, 7) . '...' . substr($string, -7));
     } else {
         return PHPUnit_Util_Type::toString($string);
     }
 }
 /**
  * Send a command to the Selenium RC server and treat the result
  * as a number.
  *
  * @param  string $command
  * @param  array  $arguments
  * @return numeric
  * @author Shin Ohno <*****@*****.**>
  * @author Bjoern Schotte <*****@*****.**>
  */
 protected function getNumber($command, array $arguments)
 {
     $result = $this->getString($command, $arguments);
     if (!is_numeric($result)) {
         $this->stop();
         throw new PHPUnit_Framework_Exception('Result is not numeric: ' . PHPUnit_Util_Type::toString($result, TRUE));
     }
     return $result;
 }
Beispiel #13
0
 /**
  * Returns a string describing the difference between the expected and the
  * actual array.
  *
  * @return string
  */
 public function toString()
 {
     if (!$this->identical) {
         ksort($this->expected);
         ksort($this->actual);
     }
     $diff = PHPUnit_Util_Diff::diff(print_r($this->expected, TRUE), print_r($this->actual, TRUE));
     if ($diff !== FALSE) {
         return trim($diff);
     }
     // Fallback: Either diff is not available or the print_r() output for
     // the expected and the actual array are equal (but the arrays are not).
     $expectedOnly = array();
     $actualOnly = array();
     $diff = '';
     foreach ($this->expected as $expectedKey => $expectedValue) {
         if (!array_key_exists($expectedKey, $this->actual)) {
             $expectedOnly[] = $expectedKey;
             continue;
         }
         if ($expectedValue === $this->actual[$expectedKey]) {
             continue;
         }
         $diffObject = PHPUnit_Framework_ComparisonFailure::diffIdentical($expectedValue, $this->actual[$expectedKey], sprintf('%sarray key %s: ', $this->message, PHPUnit_Util_Type::toString($expectedKey)));
         $diff .= $diffObject->toString() . "\n";
     }
     foreach ($this->actual as $actualKey => $actualValue) {
         if (!array_key_exists($actualKey, $this->expected)) {
             $actualOnly[] = $actualKey;
             continue;
         }
     }
     foreach ($expectedOnly as $expectedKey) {
         $diff .= sprintf("array key %s: only in expected %s\n", PHPUnit_Util_Type::toString($expectedKey), PHPUnit_Util_Type::toString($this->expected[$expectedKey]));
     }
     foreach ($actualOnly as $actualKey) {
         $diff .= sprintf("array key %s: only in actual %s\n", PHPUnit_Util_Type::toString($actualKey), PHPUnit_Util_Type::toString($this->actual[$actualKey]));
     }
     return $diff;
 }
Beispiel #14
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return "is equivalent to the SQL query " . \PHPUnit_Util_Type::toString($this->sql);
 }
Beispiel #15
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return "produces" . \PHPUnit_Util_Type::toString($this->value) . "when iterated over";
 }
Beispiel #16
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'is identical to ' . PHPUnit_Util_Type::toString($this->value);
 }
Beispiel #17
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     if (is_string($this->value) && strpos($this->value, "\n") !== FALSE) {
         return 'contains "' . $this->value . '"';
     } else {
         return 'contains ' . PHPUnit_Util_Type::toString($this->value);
     }
 }
Beispiel #18
0
 /**
  * @param   mixed   $other The value passed to evaluate() which failed the
  *                         constraint check.
  * @param   string  $description A string with extra description of what was
  *                               going on while the evaluation failed.
  * @param   boolean $not Flag to indicate negation.
  * @throws  PHPUnit_Framework_ExpectationFailedException
  */
 public function fail($other, $description, $not = FALSE)
 {
     throw new PHPUnit_Framework_ExpectationFailedException(sprintf('Failed asserting that %s %s.', PHPUnit_Util_Type::toString($other), $this->toString()), NULL, $description);
 }
Beispiel #19
0
 /**
  * Returns a description for an exception.
  *
  * @param  Exception $e
  * @return string
  * @since  Method available since Release 3.2.0
  */
 public static function exceptionToString(Exception $e)
 {
     if ($e instanceof PHPUnit_Framework_SelfDescribing) {
         if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
             $comparisonFailure = $e->getComparisonFailure();
             $description = $e->getDescription();
             $message = $e->getCustomMessage();
             if ($message == '') {
                 $buffer = '';
             } else {
                 $buffer = $message . "\n";
             }
             if ($comparisonFailure !== NULL) {
                 if ($comparisonFailure->identical()) {
                     if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object) {
                         $buffer .= 'Failed asserting that two variables ' . "reference the same object.\n";
                     } else {
                         $buffer .= $comparisonFailure->toString() . "\n";
                     }
                 } else {
                     if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Scalar) {
                         $buffer .= sprintf("Failed asserting that %s matches expected %s.\n", PHPUnit_Util_Type::toString($comparisonFailure->getActual()), PHPUnit_Util_Type::toString($comparisonFailure->getExpected()));
                     } else {
                         if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) {
                             $buffer .= sprintf("Failed asserting that two %ss are equal.\n%s\n", strtolower(substr(get_class($comparisonFailure), 36)), $comparisonFailure->toString());
                         }
                     }
                 }
             } else {
                 $buffer .= $e->toString();
                 if (!empty($buffer)) {
                     $buffer .= "\n";
                 }
                 if (strpos($buffer, $description) === FALSE) {
                     $buffer .= $description . "\n";
                 }
             }
         } else {
             $buffer = $e->toString();
             if (!empty($buffer)) {
                 $buffer .= "\n";
             }
         }
     } else {
         if ($e instanceof PHPUnit_Framework_Error) {
             $buffer = $e->getMessage() . "\n";
         } else {
             $buffer = get_class($e) . ': ' . $e->getMessage() . "\n";
         }
     }
     return $buffer;
 }
 public function toString()
 {
     return sprintf('has the value %s under key %s', \PHPUnit_Util_Type::toString($this->value), \PHPUnit_Util_Type::toString($this->key));
 }
Beispiel #21
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     if (is_object($this->value)) {
         return 'is identical to an object of class "' . get_class($this->value) . '"';
     } else {
         return 'is identical to ' . PHPUnit_Util_Type::toString($this->value);
     }
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 public function toString()
 {
     return sprintf('contains color histogram identical to expected %s', \PHPUnit_Util_Type::toString($this->value));
 }
Beispiel #23
0
 /**
  * @param mixed   $other
  * @param string  $description
  * @param boolean $not
  */
 protected function failureDescription($other, $description, $not)
 {
     $failureDescription = $this->customFailureDescription($other, $description, $not);
     if ($failureDescription === NULL) {
         $failureDescription = sprintf('Failed asserting that %s %s.', PHPUnit_Util_Type::toString($other), $this->toString());
     }
     if ($not) {
         $failureDescription = self::negate($failureDescription);
     }
     if (!empty($description)) {
         $failureDescription = $description . "\n" . $failureDescription;
     }
     return $failureDescription;
 }
Beispiel #24
0
 /**
  * @param  PHPUnit_Framework_TestFailure $defect
  * @access protected
  */
 protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
 {
     $e = $defect->thrownException();
     if ($e instanceof PHPUnit_Framework_SelfDescribing) {
         $buffer = $e->toString();
         if (!empty($buffer)) {
             $buffer .= "\n";
         }
         if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
             $comparisonFailure = $e->getComparisonFailure();
             if ($comparisonFailure !== NULL) {
                 if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Scalar) {
                     $buffer .= sprintf("Failed asserting that %s matches expected value %s.\n", PHPUnit_Util_Type::toString($comparisonFailure->getActual()), PHPUnit_Util_Type::toString($comparisonFailure->getExpected()));
                 } else {
                     if (PHPUnit_Framework_ComparisonFailure::hasDiff() && ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object || $comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String)) {
                         $buffer .= sprintf("Failed asserting that two %ss are equal.\n%s\n", strtolower(substr(get_class($comparisonFailure), 36)), $comparisonFailure->toString());
                     }
                 }
                 if ($this->verbose && !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Array && !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_Object && !$comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure_String) {
                     $buffer .= $comparisonFailure->toString() . "\n";
                 }
             } else {
                 $buffer .= $e->getDescription() . "\n";
             }
         }
     } else {
         if ($e instanceof PHPUnit_Framework_Error) {
             $buffer = $e->getMessage() . "\n";
         } else {
             $buffer = get_class($e) . ': ' . $e->getMessage() . "\n";
         }
     }
     $this->write($buffer . PHPUnit_Util_Filter::getFilteredStacktrace($defect->thrownException(), FALSE));
 }
Beispiel #25
0
 /**
  * Creates the appropriate exception for the constraint which can be caught
  * by the unit test system. This can be called if a call to evaluate()
  * fails.
  *
  * @param   mixed   $other The value passed to evaluate() which failed the
  *                         constraint check.
  * @param   string  $description A string with extra description of what was
  *                               going on while the evaluation failed.
  * @param   boolean $not Flag to indicate negation.
  * @throws  PHPUnit_Framework_ExpectationFailedException
  */
 public function fail($other, $description, $not = FALSE)
 {
     throw new PHPUnit_Framework_ExpectationFailedException(sprintf('%sFailed asserting that %s is %san instance of class "%s".', !empty($description) ? $description . "\n" : '', PHPUnit_Util_Type::toString($other, TRUE), $not ? 'not ' : '', $this->className), NULL);
 }
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'contains ' . PHPUnit_Util_Type::toString($this->value);
 }
 /**
  * Asserts that a condition is false.
  *
  * @param  boolean  $condition
  * @param  string   $message
  * @throws PHPUnit_Framework_AssertionFailedError
  * @access public
  * @static
  */
 public static function assertFalse($condition, $message = '')
 {
     if ($condition !== FALSE) {
         throw new PHPUnit_Framework_ExpectationFailedException(sprintf('Failed asserting that %s is false.', PHPUnit_Util_Type::toString($condition)), NULL, $message);
     }
 }
Beispiel #28
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return sprintf('is equal to expected %s', PHPUnit_Util_Type::toString($this->value));
 }
Beispiel #29
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     $delta = '';
     if (is_string($this->value)) {
         if (strpos($this->value, "\n") !== FALSE) {
             return 'is equal to <text>';
         } else {
             return sprintf('is equal to <string:%s>', $this->value);
         }
     } else {
         if ($this->delta != 0) {
             $delta = sprintf(' with delta <%F>', $this->delta);
         }
         return sprintf('is equal to %s%s', PHPUnit_Util_Type::toString($this->value), $delta);
     }
 }
Beispiel #30
0
 /**
  * Returns a string describing the type difference between the expected
  * and the actual value.
  */
 public function toString()
 {
     $actualType = gettype($this->actual);
     if ($this->expectedIsType) {
         $expectedType = $this->expected;
     } else {
         $expectedType = gettype($this->expected);
     }
     $expectedDiffLen = strlen($expectedType) - strlen($actualType);
     $actualDiffLen = -$expectedDiffLen;
     if ($expectedDiffLen > 0) {
         $expectedType .= str_repeat(' ', $expectedDiffLen);
     }
     if ($actualDiffLen > 0) {
         $actualType .= str_repeat(' ', $actualDiffLen);
     }
     $actualValue = '';
     if (is_string($this->actual) || is_bool($this->actual) || is_int($this->actual) || is_float($this->actual)) {
         $actualValue = PHPUnit_Util_Type::toString($this->actual);
     } elseif (is_object($this->actual)) {
         $actualValue = '<' . get_class($this->actual) . '>';
     }
     $expectedValue = '';
     if ($this->expectedIsType) {
         $expectedValue = '<' . $this->expected . '>';
     } else {
         if (is_string($this->expected) || is_bool($this->expected) || is_int($this->expected) || is_float($this->expected)) {
             $expectedValue = PHPUnit_Util_Type::toString($this->expected);
         } elseif (is_object($this->expected)) {
             $expectedValue = '<' . get_class($this->expected) . '>';
         }
     }
     if ($this->expectedIsType) {
         return sprintf("%s%sexpected type %s\n" . '%sgot      type %s %s', $this->message, $this->message != '' ? ' ' : '', $expectedType, $this->message != '' ? str_repeat(' ', strlen($this->message) + 1) : '', $actualType, $actualValue);
     } else {
         return sprintf("%s%sexpected %s %s\n" . '%sgot      %s %s', $this->message, $this->message != '' ? ' ' : '', $expectedType, $expectedValue, $this->message != '' ? str_repeat(' ', strlen($this->message) + 1) : '', $actualType, $actualValue);
     }
 }