Exemplo n.º 1
0
 public function versionsAction($id)
 {
     $object = $this->getObjectById($id);
     if ($object) {
         $versions = [];
         $differ = new \SebastianBergmann\Diff\Differ('');
         $prevContent = '';
         foreach ($object->versions as $version) {
             $nextContent = $this->decryptContent($version);
             $diff = $differ->diff($prevContent, $nextContent);
             $prevContent = $nextContent;
             $version->_diff = $this->formatDiff($diff);
             $versions[] = $version;
         }
         $object->_diff = $this->formatDiff($differ->diff($prevContent, $this->decryptContent($object)));
         $versions[] = $object;
         krsort($versions);
         $this->view->setLayout('object');
         $this->view->setVar('object', $object);
         $this->view->setVar('versions', $versions);
     } else {
         $this->handleAs404('Object not found');
     }
 }
Exemplo n.º 2
0
 function assertNodes($expected, $nodes)
 {
     $valid = $this->compareNodes($expected, $nodes);
     $msg = '';
     if (!$valid) {
         ob_start();
         Helper::dumpTree((object) ['type' => Renderer::P_ROOT, 'nodes' => $expected]);
         $e = ob_get_clean();
         ob_start();
         Helper::dumpTree((object) ['type' => Renderer::P_ROOT, 'nodes' => $nodes]);
         $t = ob_get_clean();
         $d = new \SebastianBergmann\Diff\Differ();
         $msg = $d->diff($e, $t);
     }
     $this->assertTrue($valid, $msg);
 }
 /**
  * Paints the test failure with a breadcrumbs
  * trail of the nesting test suites below the
  * top level test.
  *
  * @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in
  *   the context of the other tests.
  * @param mixed $test
  * @return void
  */
 public function paintFail($message, $test)
 {
     $trace = $this->_getStackTrace($message);
     $testName = get_class($test) . '(' . $test->getName() . ')';
     $actualMsg = $expectedMsg = null;
     if (method_exists($message, 'getComparisonFailure')) {
         $failure = $message->getComparisonFailure();
         if (is_object($failure)) {
             $actualMsg = $failure->getActualAsString();
             $expectedMsg = $failure->getExpectedAsString();
         }
     }
     echo "<li class='fail'>\n";
     echo "<span>Failed</span>";
     echo "<div class='msg'><pre>" . $this->_htmlEntities($message->toString());
     if (is_string($actualMsg) && is_string($expectedMsg) || is_array($actualMsg) && is_array($expectedMsg)) {
         $Differ = new SebastianBergmann\Diff\Differ();
         echo "<br />" . $this->_htmlEntities($Differ->diff($expectedMsg, $actualMsg));
     }
     echo "</pre></div>\n";
     echo "<div class='msg'>" . __d('cake_dev', 'Test case: %s', $testName) . "</div>\n";
     echo "<div class='msg'>" . __d('cake_dev', 'Stack trace:') . '<br />' . $trace . "</div>\n";
     echo "</li>\n";
 }
Exemplo n.º 4
0
 /**
  * @param \Shmock\ClassBuilder\Invocation
  * @return mixed|null
  */
 public function doInvocation(Invocation $invocation)
 {
     $this->frequency->addCall();
     $args = $invocation->getArguments();
     $i = 0;
     foreach ($this->arguments as $expected) {
         $argi = null;
         if ($i < count($args)) {
             $argi = $args[$i];
         }
         if (!$this->argumentMatches($expected, $argi)) {
             $expectedStr = print_r($expected, true);
             $actualStr = print_r($argi, true);
             $extra = "";
             if (strlen($expectedStr) > 100) {
                 $differ = new \SebastianBergmann\Diff\Differ();
                 $extra = "Diff: \n" . $differ->diff($expectedStr, $actualStr);
             }
             throw new \PHPUnit_Framework_AssertionFailedError(sprintf("Unexpected argument#%s %s (%s) to method '%s', was expecting %s (%s). %s", $i, $actualStr, gettype($argi), $this->methodName, $expectedStr, print_r(gettype($expected), true), $extra));
         }
         $i++;
     }
     if ($this->will) {
         return call_user_func($this->will, $invocation);
     }
     if ($this->returnThis) {
         $target = $invocation->getTarget();
         // as implemented, returnThis can only be verified by policies at
         // calltime.
         foreach ($this->policies as $policy) {
             $policy->check_method_return_value($this->className, $this->methodName, $target, true);
         }
         return $target;
     }
     return $this->returnValue;
 }