Author: James Titcumb (james@asgrim.com)
Inheritance: implements Browscap\Parser\ParserInterface
Example #1
0
 /**
  * Entry point for generating builds for a specified version
  *
  * @param string $leftFilename
  * @param string $rightFilename
  */
 public function run($leftFilename, $rightFilename)
 {
     $this->logger->debug('parsing left file ' . $leftFilename);
     $iniParserLeft = new IniParser($leftFilename);
     $leftFile = $iniParserLeft->setShouldSort(true)->parse();
     $this->logger->debug('parsing right file ' . $rightFilename);
     $iniParserRight = new IniParser($rightFilename);
     $rightFile = $iniParserRight->setShouldSort(true)->parse();
     $this->logger->debug('build diffs between files');
     $ltrDiff = $this->recursiveArrayDiff($leftFile, $rightFile);
     $rtlDiff = $this->recursiveArrayDiff($rightFile, $leftFile);
     $this->logger->debug('LTR');
     $this->logger->debug(var_export($ltrDiff, true));
     $this->logger->debug('RTL');
     $this->logger->debug(var_export($rtlDiff, true));
     $this->diffsFound = 0;
     if (count($ltrDiff) || count($rtlDiff)) {
         $this->logger->info('The following differences have been found:');
         $sectionsRead = [];
         $this->logger->debug('Pass 1 (LTR)');
         foreach ($ltrDiff as $section => $props) {
             if (isset($rightFile[$section]) && is_array($rightFile[$section])) {
                 $this->compareSectionProperties($section, $props, isset($rtlDiff[$section]) ? $rtlDiff[$section] : null, $rightFile[$section]);
             } else {
                 $this->logger->info('[' . $section . ']' . "\n" . 'Whole section only on LEFT');
                 ++$this->diffsFound;
             }
             $sectionsRead[] = $section;
         }
         $this->logger->debug('Pass 2 (RTL)');
         foreach ($rtlDiff as $section => $props) {
             if (in_array($section, $sectionsRead)) {
                 continue;
             }
             if (isset($leftFile[$section]) && is_array($leftFile[$section])) {
                 $this->compareSectionProperties($section, isset($ltrDiff[$section]) ? $ltrDiff[$section] : [], $props, $rightFile[$section]);
             } else {
                 $this->logger->info('[' . $section . ']' . "\n" . 'Whole section only on RIGHT');
                 ++$this->diffsFound;
             }
         }
         $msg = sprintf('%sThere %s %d difference%s found in the comparison.', "\n", $this->diffsFound === 1 ? 'was' : 'were', $this->diffsFound, $this->diffsFound === 1 ? '' : 's');
         $this->logger->info($msg);
     } else {
         $this->logger->info('No differences found, hooray!');
     }
 }
Example #2
0
 /**
  * tests throwing an exception if more than one eual sign is present in a line
  *
  * @group parser
  * @group sourcetest
  */
 public function testParseThrowsExceptionWhenInvalidFormatting()
 {
     $lines = ['double=equals=here'];
     $parser = new IniParser('');
     $parser->setFileLines($lines);
     $this->setExpectedException('\\RuntimeException', 'Too many equals in line: double=equals=here');
     $parser->parse();
 }