/** * 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!'); } }
/** * tests parsing sections with sorting * * @group parser * @group sourcetest */ public function testParseWithSorting() { $lines = ['', ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; division1', '', '; this line is a comment', '[section1]', 'property11=value11', 'property12=value12', '', '; this line is a comment', '[section2]', 'property21=value21', 'property22=value22', '', ';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; division2', '', '; this line is a comment', '[section3]', 'property31=value31', 'property32=value32']; $parser = new IniParser(''); $parser->setFileLines($lines); $parser->setShouldSort(true); $expected = ['section1' => ['Division' => 'division1', 'property11' => 'value11', 'property12' => 'value12'], 'section2' => ['Division' => 'division1', 'property21' => 'value21', 'property22' => 'value22'], 'section3' => ['Division' => 'division2', 'property31' => 'value31', 'property32' => 'value32']]; $data = $parser->parse(); self::assertSame($expected, $data); }