예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function diff($old, $new)
 {
     return implode(PHP_EOL, array_map(function ($string) {
         $string = preg_replace('/^(\\+){3}/', '<info>+++</info>', $string);
         $string = preg_replace('/^(\\+){1}/', '<info>+</info>', $string);
         $string = preg_replace('/^(\\-){3}/', '<error>---</error>', $string);
         $string = preg_replace('/^(\\-){1}/', '<error>-</error>', $string);
         return $string;
     }, explode(PHP_EOL, $this->differ->diff($old, $new))));
 }
예제 #2
0
 public function difObj($obj1, $obj2)
 {
     $differ = new Differ();
     $arr = [];
     foreach ($obj1 as $a => $v) {
         if ($v != $obj2[$a]) {
             if (is_numeric($v) && is_numeric($obj2[$a])) {
                 $arr[$a] = $v;
             } else {
                 /*
                 if (substr_count( $v, "\n" ) > 1 && substr_count( $obj2[$a], "\n" ) > 1)
                 {
                 	$arr[$a] = $differ->diff($v,$obj2[$a]);	
                 }
                 else
                 {	
                 	$arr[$a] = $differ->diff(self::strLine($v),self::strLine($obj2[$a]));
                 }
                 */
                 $arr[$a] = $differ->diff($v, $obj2[$a]);
             }
         }
     }
     return $arr;
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function diffTemplate(Stack $stack)
 {
     $actual_template = $stack->provisioned ? $this->cfn($stack)->getTemplate(['StackName' => $stack->get('name')])->get('TemplateBody') : '{}';
     $new_template = $this->createTemplate($stack);
     $arr_diff = new Differ();
     $diff = $arr_diff->diff(json_encode(json_decode($actual_template, true), JSON_PRETTY_PRINT), json_encode(json_decode($new_template, true), JSON_PRETTY_PRINT));
     return $diff;
 }
예제 #4
0
 /**
  * @param string $expected
  * @param string $actual
  * @return string
  */
 private function getDiff($expected = '', $actual = '')
 {
     if (!$actual && !$expected) {
         return '';
     }
     $differ = new Differ('');
     return $differ->diff($expected, $actual);
 }
예제 #5
0
 protected function execute(array $arguments)
 {
     if (isset($arguments[0]) && isset($arguments[1])) {
         $differ = new Differ();
         return $differ->diff($arguments[0], $arguments[1]);
     }
     throw new InvalidArgumentException('strings invalid');
 }
예제 #6
0
파일: EqualTo.php 프로젝트: komex/unteist
 /**
  * Get difference of two variables.
  *
  * @param mixed $actual
  *
  * @return string
  */
 protected function getDiff($actual)
 {
     if (is_array($actual) or is_array($this->expected)) {
         $diff = new Diff\Differ('--- Expected' . PHP_EOL . '+++ Actual' . PHP_EOL);
         return $diff->diff(var_export($this->expected, true), var_export($actual, true));
     } else {
         return 'expected ' . $this->formatter($this->expected) . ', but given ' . $this->formatter($actual);
     }
 }
 private function diffFiles($path, $from, $to)
 {
     if (!$this->compareFiles($from, $to)) {
         $differ = new Differ();
         $this->filesystem->put($path, $differ->diff($from, $to));
         $this->diffedFiles[] = $path;
     } else {
         $this->filesystem->put($path, $to);
     }
 }
예제 #8
0
 protected function stringDiff($old, $new)
 {
     $diff = $this->diff->diff($old, $new);
     $diff = implode(PHP_EOL, array_map(function ($string) {
         $string = preg_replace('/^(\\+){3}/', '<info>+++</info>', $string);
         $string = preg_replace('/^(\\+){1}/', '<info>+</info>', $string);
         $string = preg_replace('/^(\\-){3}/', '<error>---</error>', $string);
         $string = preg_replace('/^(\\-){1}/', '<error>-</error>', $string);
         $string = str_repeat(' ', 6) . $string;
         return $string;
     }, explode(PHP_EOL, $diff)));
     return $diff;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = (new Finder())->in($input->getArgument('input'))->exclude($input->getOption('exclude'))->name('*.php')->files();
     $files = [];
     foreach ($finder as $file) {
         $files[] = $file->getRealpath();
     }
     $project = ProjectFactory::createInstance()->create('current', $files);
     $converter = new Converter();
     $output->writeln('<comment>Running the PHPDoc to Type Hint converter. Brought to you by Kévin Dunglas and Les-Tilleuls.coop.</comment>');
     $output->writeln('');
     $progress = new ProgressBar($output, count($files));
     $changed = [];
     foreach ($project->getFiles() as $file) {
         $old = $file->getSource();
         $new = $converter->convert($project, $file);
         if ($new !== $old) {
             if ($input->getOption('dry-run')) {
                 $changed[] = ['path' => $file->getPath(), 'diff' => $this->differ->diff($old, $new)];
             } else {
                 file_put_contents($file->getPath(), $new);
             }
         }
         $progress->advance();
     }
     $progress->finish();
     $output->writeln('');
     $output->writeln('');
     foreach ($changed as $i => $file) {
         $output->writeln(sprintf('<fg=blue>%d) %s</>', $i + 1, $file['path']));
         $output->writeln('');
         $output->writeln($file['diff']);
         $output->writeln('');
     }
     $output->writeln('<info>Conversion done.</info>');
 }
예제 #10
0
 protected function additionalFailureDescription($other)
 {
     $from = preg_split('(\\r\\n|\\r|\\n)', $this->string);
     $to = preg_split('(\\r\\n|\\r|\\n)', $other);
     foreach ($from as $index => $line) {
         if (isset($to[$index]) && $line !== $to[$index]) {
             $line = $this->createPatternFromFormat($line);
             if (preg_match($line, $to[$index]) > 0) {
                 $from[$index] = $to[$index];
             }
         }
     }
     $this->string = implode("\n", $from);
     $other = implode("\n", $to);
     $differ = new Differ("--- Expected\n+++ Actual\n");
     return $differ->diff($this->string, $other);
 }
예제 #11
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $files = $this->getResource($input);
     if (count($files) != 2) {
         throw new \InvalidArgumentException('You have to define 2 files.');
     }
     $results = array();
     foreach ($files as $file) {
         if ($file->isCrypted()) {
             $file = $this->getBackend($input->getOption('configuration-file'))->setIO($this->getIO())->decrypt($file);
         }
     }
     $it = $files->getIterator();
     $output->writeln(sprintf('<info>Diff between <comment>%s</comment> and <comment>%s</comment></info>', $it[0]->getSourceFile(), $it[1]->getSourceFile()));
     $from = $this->clean($it[0]->isCrypted() ? $it[0]->getTargetContent() : $it[0]->getSourceContent());
     $to = $this->clean($it[1]->isCrypted() ? $it[1]->getTargetContent() : $it[1]->getSourceContent());
     if ($from == $to) {
         $output->writeln('no diff.');
     } else {
         $differ = new Differ();
         echo $differ->diff($from, $to);
     }
 }
예제 #12
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);
     }
 }
예제 #13
0
 public function testTypesOtherThanArrayAndStringCanBePassed()
 {
     $this->assertEquals("--- Original\n+++ New\n@@ @@\n-1\n+2\n", $this->differ->diff(1, 2));
 }
예제 #14
0
 /**
  * @param $text
  */
 public function __construct($old, $new)
 {
     $differ = new Differ('');
     $this->diff = $differ->diff($old, $new);
 }
예제 #15
0
 /**
  *
  * @return string
  */
 public function getDiff()
 {
     if (!$this->actualAsString && !$this->expectedAsString) {
         return '';
     }
     $differ = new Differ("\n--- Expected\n+++ Actual\n");
     return $differ->diff($this->expectedAsString, $this->actualAsString);
 }
 /**
  * {@inheritdoc}
  */
 public function diff($old, $new)
 {
     return $this->differ->diff($old, $new);
 }
예제 #17
0
 /**
  * @Then the file :file should contain:
  */
 public function theFileShouldContain($file, PyStringNode $contents)
 {
     $this->throwExceptionIfFalse(file_exists($file), sprintf('Expected file exist: %s', $file));
     $writtenContent = preg_replace("/humbug-behat[0-9A-Za-z]+\\//", 'humbug-behatJ6Dj5I/', file_get_contents($file));
     $this->throwExceptionIfFalse(trim($writtenContent) == trim((string) $contents), sprintf('Actual file content differs:%s%s', PHP_EOL, $this->differ->diff((string) $contents, $writtenContent)));
 }
예제 #18
0
 /**
  * @covers SebastianBergmann\Diff\Differ::diff
  */
 public function testCustomHeaderCanBeUsed()
 {
     $differ = new Differ('CUSTOM HEADER');
     $this->assertEquals("CUSTOM HEADER@@ @@\n-a\n+b\n", $differ->diff('a', 'b'));
 }
예제 #19
0
 /**
  * @deprecated Will be removed in the 2.0
  *
  * @param string $old
  * @param string $new
  *
  * @return string
  */
 protected function stringDiff($old, $new)
 {
     return $this->diff->diff($old, $new);
 }
예제 #20
0
 /**
  * Get diff.
  *
  * @return string
  */
 public function diff()
 {
     return $this->differ->diff($this->wrappedObject->old_value, $this->wrappedObject->new_value);
 }
 /**
  * {@inheritDoc}
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  * @throws ParserException
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $align = $input->getOption('align') === Step::ALIGN_TO_LEFT ? Step::ALIGN_TO_LEFT : Step::ALIGN_TO_RIGHT;
     $directory = $input->getArgument('directory');
     $finder = (new FeatureResolve($directory))->__invoke();
     $output->writeln("\nFinding files on <info>" . $directory . "</info>\n");
     $tagFormatter = new Tags();
     $featureDescription = new FeatureDescription();
     $background = new Background($align);
     $scenario = new Scenario($align);
     /* @var $file \Symfony\Component\Finder\SplFileInfo */
     foreach ($finder as $file) {
         $fileContent = $file->getContents();
         $contentWithoutComments = $this->removeComments($fileContent);
         $feature = $this->parser->parse($fileContent);
         $formatted = $feature->hasTags() ? $tagFormatter->format($feature->getTags()) . "\n" : '';
         $formatted .= $featureDescription->format($feature) . "\n\n";
         $formatted .= $feature->hasBackground() ? $background->format($feature->getBackground()) . "\n" : '';
         $formatted .= $feature->hasScenarios() ? $scenario->format($feature->getScenarios()) : '';
         if ($formatted !== $contentWithoutComments) {
             if (!defined('FAILED')) {
                 define('FAILED', true);
             }
             $diff = new Differ("--- Original\n+++ Expected\n", false);
             $output->writeln('<error>Wrong style: ' . $file->getRealPath() . '</error>');
             $output->writeln($diff->diff($contentWithoutComments, $formatted));
         }
     }
     if (defined('FAILED')) {
         return 1;
     }
     $output->writeln('<bg=green;fg=white>     Everything is OK!     </>');
 }