Esempio n. 1
0
 /**
  * @param array $transformed
  * @param string $type
  * @return object
  * @throws \Exception
  */
 protected function revertObject($transformed, $type)
 {
     $class = new \ReflectionClass($type);
     $instance = $class->newInstanceWithoutConstructor();
     if (!is_array($transformed)) {
         throw new \Exception("Error while reverting [{$type}]. Input is not an array: " . ValuePrinter::serialize($transformed));
     }
     $reader = new PropertyReader($this->types, $class->getName());
     $properties = [];
     foreach ($reader->readState() as $property) {
         $properties[] = $property->name();
         if (array_key_exists($property->name(), $transformed)) {
             $value = new TypedValue($transformed[$property->name()], $property->type());
             $transformer = $this->transformers->toRevert($value);
             $property->set($instance, $transformer->revert($value));
         }
     }
     foreach ($transformed as $key => $value) {
         if (!in_array($key, $properties)) {
             $transformer = $this->transformers->toRevert($value);
             $instance->{$key} = $transformer->revert($value);
         }
     }
     return $instance;
 }
Esempio n. 2
0
 function testPrintException()
 {
     $this->assertEquals("<Exception>", ValuePrinter::serialize(new \Exception()));
     $this->assertEquals("<InvalidArgumentException>('Some message')", ValuePrinter::serialize(new \InvalidArgumentException('Some message')));
     $this->assertEquals("<Exception>('With code', 42)", ValuePrinter::serialize(new \Exception('With code', 42)));
     $this->assertEquals("<Exception>('With previous') <- <Exception>('The previous') <- <Exception>", ValuePrinter::serialize(new \Exception('With previous', 0, new \Exception('The previous', 0, new \Exception()))));
 }
Esempio n. 3
0
 /**
  * @param Argument[] $arguments
  * @return string
  */
 private function printArguments($arguments)
 {
     return implode(', ', array_map(function (ExactArgument $argument) {
         return ValuePrinter::serialize($argument->value());
     }, array_filter($arguments, function (Argument $argument) {
         return $argument instanceof ExactArgument;
     })));
 }
Esempio n. 4
0
 /**
  * @param mixed $value
  * @return Renderer
  * @throws \Exception
  */
 public function getRenderer($value)
 {
     foreach ($this->renderers as $renderer) {
         if ($renderer->handles($value)) {
             return $renderer;
         }
     }
     throw new \Exception("No Renderer found to handle " . ValuePrinter::serialize($value));
 }
Esempio n. 5
0
 /**
  * @param \Exception The expected thrown Exception
  * @throws AssertionFailedException If thrown exception is not $exception
  */
 public function thrown(\Exception $exception)
 {
     if (!$this->call->thrown()) {
         throw new AssertionFailedException($this->methodCall . ' did not throw ' . ValuePrinter::serialize($exception) . "\n" . ' No exception was thrown.');
     }
     if (get_class($exception) != get_class($this->call->thrown()) || $exception->getMessage() != $this->call->thrown()->getMessage()) {
         throw new AssertionFailedException($this->methodCall . ' did not throw ' . ValuePrinter::serialize($exception) . "\n" . ' The thrown exception was ' . ValuePrinter::serialize($this->call->thrown()));
     }
 }
Esempio n. 6
0
 private function toString($value)
 {
     return ValuePrinter::serialize($value);
 }
Esempio n. 7
0
 protected function export($value)
 {
     return ValuePrinter::serialize($value);
 }
Esempio n. 8
0
 private function printResult(Console $console, ExecutionResult $result)
 {
     if ($result instanceof RenderedResult) {
         $console->writeLine((string) $result->getOutput());
         return self::OK;
     } else {
         if ($result instanceof MissingParametersResult) {
             $console->writeLine("Missing parameters " . ValuePrinter::serialize($result->getParameters()));
             return self::ERROR;
         } else {
             if ($result instanceof NotPermittedResult) {
                 $console->writeLine('Permission denied');
                 return self::ERROR;
             } else {
                 if ($result instanceof FailedResult) {
                     $console->writeLine("Error: " . $result->getMessage());
                     $exception = $result->getException();
                     $console->error($exception->getMessage() . ' ' . '[' . $exception->getFile() . ':' . $exception->getLine() . ']' . "\n" . $exception->getTraceAsString());
                     return $exception->getCode() ?: self::ERROR;
                 } else {
                     if ($result instanceof NoResult || $result instanceof RedirectResult) {
                         return self::OK;
                     } else {
                         $console->writeLine('Cannot print [' . (new \ReflectionClass($result))->getShortName() . ']');
                         return self::OK;
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
 private function checkReturnValue($returnValue)
 {
     $type = $this->typeHint->getType();
     if (!$type->is($returnValue)) {
         $returned = ValuePrinter::serialize($returnValue);
         throw new \ReflectionException("[{$this->class}::{$this->name}()] returned [{$returned}] " . "which does not match its return type [{$type}]");
     }
 }