function it_converts_objects_to_string_and_diffs_the_result(Exporter $exporter, StringEngine $stringDiffer)
 {
     $exporter->export(Argument::type('DateTime'))->willReturn('DateTime');
     $exporter->export(Argument::type('ArrayObject'))->willReturn('ArrayObject');
     $stringDiffer->compare('DateTime', 'ArrayObject')->willReturn('-DateTime+ArrayObject');
     $diff = $this->compare(new \DateTime(), new \ArrayObject());
     $diff->shouldBe('-DateTime+ArrayObject');
 }
Esempio n. 2
0
 public function recursiveExport(&$value, $indentation, $processed = null)
 {
     if ($value instanceof CM_Debug_DebugInfoInterface) {
         return $this->shortenedExport($value);
     }
     return parent::recursiveExport($value, $indentation, $processed);
 }
 public function shortenedExport($value)
 {
     if ($value instanceof CallableInterface) {
         return (string) $value;
     }
     return parent::shortenedExport($value);
 }
 /**
  * @param  mixed   $data
  * @param  Context $context
  *
  * @return string
  */
 public function shortenedRecursiveExport(&$data, Context $context = null)
 {
     $result = array();
     $exporter = new Exporter();
     if (!$context) {
         $context = new Context();
     }
     $context->add($data);
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             if ($context->contains($data[$key]) !== false) {
                 $result[] = '*RECURSION*';
             } else {
                 $result[] = sprintf('array(%s)', $this->shortenedRecursiveExport($data[$key], $context));
             }
         } else {
             $result[] = $exporter->shortenedExport($value);
         }
     }
     return join(', ', $result);
 }
Esempio n. 5
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $start = microtime(true);
     $encoding = $input->getOption(self::OPTION_ENCODING);
     $codepointValue = $input->getArgument(self::ARGUMENT_CODEPOINT);
     $codepoint = $this->valueToCodepoint($codepointValue, $encoding);
     $from = $input->getOption(self::OPTION_FROM);
     $repository = $this->getRepositoryByName($from);
     $db = new Database($repository);
     $exporter = new Exporter();
     try {
         $character = $db->getCharacterByCodepoint($codepoint);
     } catch (CharacterNotFoundException $e) {
         $output->writeln('<error>Character Not Found</error>');
         return 1;
     }
     $output->writeln('<info>Character Found</info>');
     $output->writeln(sprintf('Export: %s', $exporter->export($character)));
     $output->writeln(sprintf('UTF-8: %s', $codepoint->toUTF8()));
     $output->writeln(sprintf('Memory peak: %.5f MB', memory_get_peak_usage() / 1048576));
     $output->writeln(sprintf('Took: %.5f seconds', microtime(true) - $start));
     return 0;
 }
Esempio n. 6
0
 /**
  * @param  array  $before
  * @param  array  $after
  * @param  string $header
  * @throws PHPUnit_Framework_RiskyTestError
  */
 private function compareGlobalStateSnapshotPart(array $before, array $after, $header)
 {
     if ($before != $after) {
         $differ = new Differ($header);
         $exporter = new Exporter();
         $diff = $differ->diff($exporter->export($before), $exporter->export($after));
         throw new PHPUnit_Framework_RiskyTestError($diff);
     }
 }
Esempio n. 7
0
 /**
  * @param  mixed                                      $data       The data to export as a string
  * @param  SebastianBergmann\RecursionContext\Context $processed  Contains all objects and arrays that have previously been processed
  * @return string
  * @since  Method available since Release 3.2.1
  */
 protected function dataToString(&$data, $processed = null)
 {
     $result = array();
     $exporter = new Exporter();
     if (!$processed) {
         $processed = new Context();
     }
     $processed->add($data);
     foreach ($data as $key => $value) {
         if (is_array($value)) {
             if ($processed->contains($data[$key]) !== false) {
                 $result[] = '*RECURSION*';
             } else {
                 $result[] = sprintf('array(%s)', $this->dataToString($data[$key], $processed));
             }
         } else {
             $result[] = $exporter->shortenedExport($value);
         }
     }
     return join(', ', $result);
 }
Esempio n. 8
0
 public function toString()
 {
     $exporter = new Exporter();
     return sprintf('return user-specified value %s', $exporter->export($this->value));
 }
Esempio n. 9
0
 /**
  * @param object $expected
  * @param object $actual
  *
  * @return string
  */
 public function compare($expected, $actual)
 {
     return $this->stringDiffer->compare($this->exporter->export($expected), $this->exporter->export($actual));
 }
Esempio n. 10
0
 public function toString()
 {
     $exporter = new Exporter();
     return sprintf('raise user-specified exception %s', $exporter->export($this->exception));
 }
Esempio n. 11
0
 /**
  * @param mixed $x
  * @param mixed $y
  *
  * @return string
  */
 private function diff($x, $y)
 {
     $exporter = new Exporter();
     $diff = new Diff(preg_split('/\\n/', $exporter->export($x)), preg_split('/\\n/', $exporter->export($y)));
     return $diff->render(new Diff_Renderer_Text_Unified());
 }
Esempio n. 12
0
 /**
  * Gets the data set description of a TestCase.
  *
  * @param  boolean $includeData
  * @return string
  * @since  Method available since Release 3.3.0
  */
 protected function getDataSetAsString($includeData = true)
 {
     $buffer = '';
     if (!empty($this->data)) {
         if (is_int($this->dataName)) {
             $buffer .= sprintf(' with data set #%d', $this->dataName);
         } else {
             $buffer .= sprintf(' with data set "%s"', $this->dataName);
         }
         $exporter = new Exporter();
         if ($includeData) {
             $buffer .= sprintf(' (%s)', $exporter->shortenedRecursiveExport($this->data));
         }
     }
     return $buffer;
 }
 /**
  * @dataProvider readwritePropertiesProvider
  */
 public function testPropertiesWithFullAccessAreReadablesAndWritables(IStrictPropertiesContainer $obj = null, $property = null, $value = null, $expected = null)
 {
     if ($obj === null) {
         $this->markTestSkipped('Target class has not read-write properties to test.');
     }
     $exporter = new Exporter();
     $var = get_class($obj);
     $var = Inflector::variable(substr($var, strrpos($var, '\\') === false ? 0 : strrpos($var, '\\') + 1));
     $obj->{$property} = $value;
     $actual = $obj->{$property};
     $message = String::format('${var}->{property} = {value}; $actual = ${var}->{property}; // {actual}', ['var' => $var, 'property' => $property, 'actual' => $exporter->shortenedExport($actual), 'value' => $exporter->shortenedExport($value)]);
     $this->assertEquals($expected, $actual, $message);
 }