Пример #1
0
 /**
  * Assert that two values are equal. The test fails if they are not.
  *
  * NOTE: This method uses PHP's strict equality test operator ("===") to
  * compare values. This means values and types must be equal, key order must
  * be identical in arrays, and objects must be referentially identical.
  *
  * @param wild    The theoretically expected value, generated by careful
  *                reasoning about the properties of the system.
  * @param wild    The empirically derived value, generated by executing the
  *                test.
  * @param string  A human-readable description of what these values represent,
  *                and particularly of what a discrepancy means.
  *
  * @return void
  * @task assert
  */
 protected final function assertEqual($expect, $result, $message = null)
 {
     if ($expect === $result) {
         $this->assertions++;
         return;
     }
     $expect = PhutilReadableSerializer::printableValue($expect);
     $result = PhutilReadableSerializer::printableValue($result);
     $where = debug_backtrace();
     $where = array_shift($where);
     $line = idx($where, 'line');
     $file = basename(idx($where, 'file'));
     $output = "Assertion failed at line {$line} in {$file}";
     if ($message) {
         $output .= ": {$message}";
     }
     $output .= "\n";
     if (strpos($expect, "\n") === false && strpos($result, "\n") === false) {
         $output .= "Expected: {$expect}\n";
         $output .= "Actual: {$result}";
     } else {
         $output .= "Expected vs Actual Output Diff\n";
         $output .= ArcanistDiffUtils::renderDifferences($expect, $result, $lines = 0xffff);
     }
     $this->failTest($output);
     throw new ArcanistPhutilTestTerminatedException($output);
 }
 public function testPrintableValue()
 {
     $tests = array(array(null, 'null'), array(true, 'true'), array(false, 'false'), array(0, '0'), array(0.0, '0.0'), array(0.1, '0.1'), array('test', 'test'));
     foreach ($tests as $test) {
         list($value, $expect) = $test;
         $this->assertEqual($expect, PhutilReadableSerializer::printableValue($value));
     }
 }
 public static function registerErrorHandler()
 {
     // NOTE: This forces PhutilReadableSerializer to load, so that we are
     // able to handle errors which fire from inside autoloaders (PHP will not
     // reenter autoloaders).
     PhutilReadableSerializer::printableValue(null);
     PhutilErrorHandler::setErrorListener(array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
 }
Пример #4
0
 public function renderForDisplay(PhabricatorUser $viewer)
 {
     $data = PhutilReadableSerializer::printableValue($this->data);
     return phutil_tag('pre', array(), $data);
 }
Пример #5
0
 /**
  * Fail an assertion which checks that some result is equal to a specific
  * value, like 'true' or 'false'. This prints a readable error message and
  * fails the current test.
  *
  * This method throws and does not return.
  *
  * @param   string      Human readable description of the expected value.
  * @param   string      The actual value.
  * @param   string|null Optional assertion message.
  * @return  void
  * @task    internal
  */
 private function failAssertionWithExpectedValue($expect_description, $actual_result, $message)
 {
     $caller = self::getCallerInfo();
     $file = $caller['file'];
     $line = $caller['line'];
     if ($message !== null) {
         $description = pht("Assertion failed, expected '%s' (at %s:%d): %s", $expect_description, $file, $line, $message);
     } else {
         $description = pht("Assertion failed, expected '%s' (at %s:%d).", $expect_description, $file, $line);
     }
     $actual_result = PhutilReadableSerializer::printableValue($actual_result);
     $header = pht('ACTUAL VALUE');
     $output = $description . "\n\n" . $header . "\n" . $actual_result;
     $this->failTest($output);
     throw new PhutilTestTerminatedException($output);
 }