/**
  * {@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;
 }
 /**
  * @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);
         }
     }
     if ($this->default != NULL) {
         return $this->default->invoke($invocation);
     }
     PHPUnit_Framework_Assert::fail(sprintf('No return value defined for %s', PHPUnit_Util_Type::export($invocation->parameters)));
 }
 public static function assertArraySameValues($expected, $actual)
 {
     $extra = array_diff($expected, $actual);
     $missing = array_diff($actual, $expected);
     CakeTestCase::assertSame($extra, $missing, "Got extra elements " . PHPUnit_Util_Type::export($extra) . " and some are elements missing " . PHPUnit_Util_Type::export($missing));
 }
 /**
  * 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)));
     }
 }
Esempio n. 5
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));
     }
 }
 /**
  * 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);
     }
 }
Esempio n. 7
0
 public function toString()
 {
     return sprintf('has items %s', PHPUnit_Util_Type::export($this->expected));
 }
Esempio n. 8
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)) {
         throw new PHPUnit_Framework_Exception('Result is not numeric: ' . PHPUnit_Util_Type::export($result));
     }
     return $result;
 }
Esempio n. 9
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)
 {
     $expectedToCompare = $expected;
     $actualToCompare = $actual;
     // always compare as strings to avoid strange behaviour
     // otherwise 0 == 'Foobar'
     if (is_string($expected) || is_string($actual)) {
         $expectedToCompare = (string) $expectedToCompare;
         $actualToCompare = (string) $actualToCompare;
         if ($ignoreCase) {
             $expectedToCompare = strtolower($expectedToCompare);
             $actualToCompare = strtolower($actualToCompare);
         }
     }
     if ($expectedToCompare != $actualToCompare) {
         if (is_string($expected) && is_string($actual)) {
             throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, PHPUnit_Util_Type::export($expected), PHPUnit_Util_Type::export($actual), FALSE, 'Failed asserting that two strings are equal.');
         }
         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)));
     }
 }
 /**
  * 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)
 {
     foreach ($actual as $object) {
         if (!$expected->contains($object)) {
             throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, PHPUnit_Util_Type::export($expected), PHPUnit_Util_Type::export($actual), false, 'Failed asserting that two objects are equal.');
         }
     }
     foreach ($expected as $object) {
         if (!$actual->contains($object)) {
             throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, PHPUnit_Util_Type::export($expected), PHPUnit_Util_Type::export($actual), false, 'Failed asserting that two objects are equal.');
         }
     }
 }
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'has the same values with ' . PHPUnit_Util_Type::export($this->value);
 }
Esempio n. 12
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return sprintf('%s Reason: %s', PHPUnit_Util_Type::export($this->value), $this->failure_reason);
 }
 public function toString()
 {
     return sprintf('equals ignoring whitespace %s', PHPUnit_Util_Type::export($this->normalize($this->expected)));
 }
Esempio n. 14
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, array &$processed = array())
 {
     if ($canonicalize) {
         sort($expected);
         sort($actual);
     }
     $remaining = $actual;
     $expString = $actString = "Array (\n";
     $equal = TRUE;
     foreach ($expected as $key => $value) {
         unset($remaining[$key]);
         if (!array_key_exists($key, $actual)) {
             $expString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), PHPUnit_Util_Type::shortenedExport($value));
             $equal = FALSE;
             continue;
         }
         try {
             $this->factory->getComparatorFor($value, $actual[$key])->assertEquals($value, $actual[$key], $delta, $canonicalize, $ignoreCase, $processed);
             $expString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), PHPUnit_Util_Type::shortenedExport($value));
             $actString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), PHPUnit_Util_Type::shortenedExport($actual[$key]));
         } catch (PHPUnit_Framework_ComparisonFailure $e) {
             $expString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), $e->getExpectedAsString() ? $this->indent($e->getExpectedAsString()) : PHPUnit_Util_Type::shortenedExport($e->getExpected()));
             $actString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), $e->getActualAsString() ? $this->indent($e->getActualAsString()) : PHPUnit_Util_Type::shortenedExport($e->getActual()));
             $equal = FALSE;
         }
     }
     foreach ($remaining as $key => $value) {
         $actString .= sprintf("    %s => %s\n", PHPUnit_Util_Type::export($key), PHPUnit_Util_Type::shortenedExport($value));
         $equal = FALSE;
     }
     $expString .= ')';
     $actString .= ')';
     if (!$equal) {
         throw new PHPUnit_Framework_ComparisonFailure($expected, $actual, $expString, $actString, FALSE, 'Failed asserting that two arrays are equal.');
     }
 }
Esempio n. 15
0
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'has the key ' . PHPUnit_Util_Type::export($this->key);
 }
Esempio n. 16
0
 /**
  * @see \PHPUnit_Framework_Constraint::toString()
  */
 public function toString()
 {
     return sprintf('has the key %s and its value %s', \PHPUnit_Util_Type::export($this->key), $this->constraint->toString());
 }
Esempio n. 17
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::export($this->value);
     }
 }
Esempio n. 18
0
 public function toString()
 {
     return sprintf('raise user-specified exception %s', PHPUnit_Util_Type::export($this->exception));
 }
Esempio n. 19
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::export($this->value), $delta);
     }
 }
Esempio n. 20
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, array &$processed = array())
    {
        if (get_class($actual) !== get_class($expected)) {
            throw new PHPUnit_Framework_ComparisonFailure(
              $expected,
              $actual,
              PHPUnit_Util_Type::export($expected),
              PHPUnit_Util_Type::export($actual),
              FALSE,
              sprintf(
                '%s is not instance of expected class "%s".',

                PHPUnit_Util_Type::export($actual),
                get_class($expected)
              )
            );
        }

        // don't compare twice to allow for cyclic dependencies
        if (in_array(array($actual, $expected), $processed, TRUE) ||
            in_array(array($expected, $actual), $processed, TRUE)) {
            return;
        }

        $processed[] = array($actual, $expected);

        // don't compare objects if they are identical
        // this helps to avoid the error "maximum function nesting level reached"
        // CAUTION: this conditional clause is not tested
        if ($actual !== $expected) {
            try {
                parent::assertEquals($this->toArray($expected), $this->toArray($actual), $delta, $canonicalize, $ignoreCase, $processed);
            }

            catch (PHPUnit_Framework_ComparisonFailure $e) {
                throw new PHPUnit_Framework_ComparisonFailure(
                  $expected,
                  $actual,
                  // replace "Array" with "MyClass object"
                  substr_replace($e->getExpectedAsString(), get_class($expected).' Object', 0, 5),
                  substr_replace($e->getActualAsString(), get_class($actual).' Object', 0, 5),
                  FALSE,
                  'Failed asserting that two objects are equal.'
                );
            }
        }
    }
Esempio n. 21
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.
  *
  * To provide additional failure information additionalFailureDescription
  * can be used.
  *
  * @param  mixed $other Evaluated value or object.
  * @return string
  */
 protected function failureDescription($other)
 {
     return PHPUnit_Util_Type::export($other) . ' ' . $this->toString();
 }
Esempio n. 22
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));
 }
Esempio n. 23
0
 public function toString()
 {
     return sprintf('return user-specified value %s', PHPUnit_Util_Type::export($this->value));
 }
Esempio n. 24
0
 public function toString()
 {
     return sprintf('is equal to %s', PHPUnit_Util_Type::export($this->expected));
 }
 /**
  * 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)
 {
     return sprintf('%s is equal to expected exception code %s', PHPUnit_Util_Type::export($other->getCode()), PHPUnit_Util_Type::export($this->expectedCode));
 }
Esempio n. 26
0
 /**
  * @dataProvider provideNonBinaryMultibyteStrings
  */
 public function testNonBinaryStringExport($value, $expectedLength)
 {
     $this->assertRegExp("~'.{{$expectedLength}}'\$~s", PHPUnit_Util_Type::export($value));
 }
Esempio n. 27
0
 /**
  * @dataProvider exportProvider
  */
 public function testExport($value, $expected)
 {
     $this->assertSame($expected, self::trimnl(PHPUnit_Util_Type::export($value)));
 }
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'is greater than ' . PHPUnit_Util_Type::export($this->value);
 }
 /**
  * Returns a string representation of the constraint.
  *
  * @return string
  */
 public function toString()
 {
     return 'has the key ' . PHPUnit_Util_Type::export($this->key) . ' with the value ' . PHPUnit_Util_Type::export($this->value);
 }