Автор: Sebastian Bergmann (sebastian@phpunit.de)
Пример #1
0
    public function toString()
    {
        return sprintf(
          'return user-specified value %s',

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

          PHPUnit_Util_Type::toString($this->exception)
        );
    }
Пример #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)));
 }
Пример #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)
        );
    }
Пример #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 '';
 }
Пример #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)
        );
    }
Пример #7
0
 /**
  * Evaluate that string is valid JSON
  *
  * @param string $other
  * @return boolean
  */
 protected function evaluateValid($other)
 {
     try {
         $decodedJson = Zend_Json::decode($other);
         $this->setActualValue($decodedJson);
     } catch (Zend_Json_Exception $e) {
         $this->setActualValue(PHPUnit_Util_Type::shortenedString($other) . "\n" . $e->__toString());
         return false;
     }
     return true;
 }
Пример #8
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 '';
 }
 /**
  * {@inheritdoc}
  *
  * @todo Improve output using diff when expected and actual arguments of a
  *       command do not match.
  */
 public function toString()
 {
     $string = 'is a Redis command';
     if ($this->commandID) {
         $string .= " with ID '{$this->commandID}'";
     }
     if ($this->arguments) {
         $string .= " and the following arguments:\n\n";
         $string .= PHPUnit_Util_Type::export($this->arguments);
     }
     return $string;
 }
Пример #10
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);
 }
Пример #11
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'is greater than ' . PHPUnit_Util_Type::toString($this->value);
 }
 /**
  * Asserts that two values are equal.
  *
  * @param  mixed $expected The first value to compare
  * @param  mixed $actual The second value to compare
  * @param  float $delta The allowed numerical distance between two values to
  *                      consider them equal
  * @param  bool  $canonicalize If set to TRUE, arrays are sorted before
  *                             comparison
  * @param  bool  $ignoreCase If set to TRUE, upper- and lowercasing is
  *                           ignored when comparing string values
  * @throws PHPUnit_Framework_ComparisonFailure Thrown when the comparison
  *                           fails. Contains information about the
  *                           specific errors that lead to the failure.
  */
 public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE)
 {
     if (is_infinite($actual) && is_infinite($expected)) {
         return;
     }
     if ((is_infinite($actual) xor is_infinite($expected)) || (is_nan($actual) or is_nan($expected)) || abs($actual - $expected) > $delta) {
         throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, '', '', FALSE, sprintf('Failed asserting that %s matches expected %s.', PHPUnit_Util_Type::export($actual), PHPUnit_Util_Type::export($expected)));
     }
 }
Пример #13
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'has the key ' . PHPUnit_Util_Type::toString($this->key);
 }
Пример #14
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);
     }
 }
Пример #15
0
 /**
  * @dataProvider provideNonBinaryMultibyteStrings
  */
 public function testNonBinaryStringExport($value, $expectedLength)
 {
     $this->assertRegExp("~'.{{$expectedLength}}'\$~s", PHPUnit_Util_Type::export($value));
 }
Пример #16
0
 public function toString()
 {
     return sprintf('is equal to %s', PHPUnit_Util_Type::export($this->expected));
 }
Пример #17
0
 /**
  * Asserts that two values are equal.
  *
  * @param  mixed $expected The first value to compare
  * @param  mixed $actual The second value to compare
  * @param  float $delta The allowed numerical distance between two values to
  *                      consider them equal
  * @param  bool  $canonicalize If set to TRUE, arrays are sorted before
  *                             comparison
  * @param  bool  $ignoreCase If set to TRUE, upper- and lowercasing is
  *                           ignored when comparing string values
  * @throws PHPUnit_Framework_ComparisonFailure Thrown when the comparison
  *                           fails. Contains information about the
  *                           specific errors that lead to the failure.
  */
 public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE)
 {
     if ($actual != $expected) {
         throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, PHPUnit_Util_Type::export($expected), PHPUnit_Util_Type::export($actual));
     }
 }
Пример #18
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'is less than ' . PHPUnit_Util_Type::export($this->value);
 }
Пример #19
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);
     }
 }
Пример #20
0
 public function toString()
 {
     return sprintf('has items %s', PHPUnit_Util_Type::export($this->expected));
 }
Пример #21
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;
 }
Пример #22
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;
 }
Пример #23
0
 /**
  * Asserts that a haystack does not contain only values of a given type.
  *
  * @param string $type
  * @param mixed  $haystack
  * @param bool   $isNativeType
  * @param string $message
  * @since  Method available since Release 3.1.4
  */
 public static function assertNotContainsOnly($type, $haystack, $isNativeType = null, $message = '')
 {
     if (!(is_array($haystack) || is_object($haystack) && $haystack instanceof Traversable)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'array or traversable');
     }
     if ($isNativeType == null) {
         $isNativeType = PHPUnit_Util_Type::isType($type);
     }
     self::assertThat($haystack, new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_TraversableContainsOnly($type, $isNativeType)), $message);
 }
Пример #24
0
 /**
  * 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;
 }
Пример #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);
 }
 /**
  * Asserts that two values are equal.
  *
  * @param  mixed $expected The first value to compare
  * @param  mixed $actual The second value to compare
  * @param  float $delta The allowed numerical distance between two values to
  *                      consider them equal
  * @param  bool  $canonicalize If set to TRUE, arrays are sorted before
  *                             comparison
  * @param  bool  $ignoreCase If set to TRUE, upper- and lowercasing is
  *                           ignored when comparing string values
  * @throws PHPUnit_Framework_ComparisonFailure Thrown when the comparison
  *                           fails. Contains information about the
  *                           specific errors that lead to the failure.
  */
 public function assertEquals($expected, $actual, $delta = 0, $canonicalize = FALSE, $ignoreCase = FALSE)
 {
     if (gettype($expected) != gettype($actual)) {
         throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, '', '', FALSE, sprintf('%s does not match expected type "%s".', PHPUnit_Util_Type::shortenedExport($actual), gettype($expected)));
     }
 }
 /**
  * Asserts that a variable is not of a given type.
  *
  * @param  string $expected
  * @param  mixed  $actual
  * @param  string $message
  * @access public
  * @static
  * @since  Method available since Release 2.2.0
  */
 public static function assertNotType($expected, $actual, $message = '')
 {
     if (is_string($expected)) {
         if (PHPUnit_Util_Type::isType($expected)) {
             $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsType($expected));
         } else {
             if (class_exists($expected) || interface_exists($expected)) {
                 $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_IsInstanceOf($expected));
             } else {
                 throw new InvalidArgumentException();
             }
         }
     } else {
         throw new InvalidArgumentException();
     }
     self::assertThat($actual, $constraint, $message);
 }
Пример #28
0
 /**
  * Returns the description of the failure
  *
  * The beginning of failure messages is "Failed asserting that" in most
  * cases. This method should return the second part of that sentence.
  *
  * @param  mixed  $other Evaluated value or object.
  * @return string
  */
 protected function failureDescription($other)
 {
     $code = method_exists($other, 'getMessageCode') ? $other->getMessageCode() : $other->getCode();
     return sprintf('%s is equal to expected exception code %s', PHPUnit_Util_Type::export($code), PHPUnit_Util_Type::export($this->expectedCode));
 }
Пример #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);
     }
 }
 /**
  * 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::export($this->value);
     }
 }