public function testRenderLink() { $log = new Log(); $log->setTitle('Change log'); $log->setDescription('My change log'); $release1 = new Release('1.0.0'); $release1->setLink('http://fuelphp.com'); $log->addRelease($release1); $release1 = new Release('0.1.0'); $release1->setLink('http://google.com'); $release1->setLinkName('a'); $log->addRelease($release1); $expected = <<<'EXPECTED' # Change log My change log ## [1.0.0] ## [0.1.0][a] [1.0.0] http://fuelphp.com [a] http://google.com EXPECTED; $result = $this->renderer->render($log); $this->assertEquals($expected, $result); }
/** * Takes the given content and parses it into a populated Log object. * * @param string[] $content * * @return Log */ public function parse($content) { $log = new Log(); $description = []; $links = []; $matches = []; $bodyEnded = false; $line = current($content); while ($line !== false) { $line = ltrim($line); if (preg_match('/^#(?!#).+/', $line) === 1) { $log->setTitle($this->trimHashes($line)); } elseif (preg_match('/^##(?!#).+/', $line) === 1) { $release = $this->parseRelease($content); $log->addRelease($release); $bodyEnded = true; } elseif (preg_match('/^\\[(.+)\\]: (.+)/', $line, $matches)) { if (count($matches) >= 3) { $links[$matches[1]] = $matches[2]; } $bodyEnded = true; } elseif (!$bodyEnded) { $description[] = $line; } $line = next($content); } $log->setDescription(implode("\n", $description)); // Assign the releases their real links $this->assignLinks($log, $links); return $log; }
public function testGetNextVersion() { $release1 = new Release('0.1.0'); $this->log->addRelease($release1); $this->assertEquals('0.1.1', $this->log->getNextVersion(Log::VERSION_PATCH)); $this->assertEquals('0.2.0', $this->log->getNextVersion(Log::VERSION_MINOR)); $this->assertEquals('1.1.0', $this->log->getNextVersion(Log::VERSION_MAJOR)); $this->assertEquals('foobar', $this->log->getNextVersion('foobar')); }
public function testRender() { $log = new Log(); $log->setTitle('Change Log'); $log->setDescription('A log for changes!'); $release1 = new Release('1.0.0'); $release1->setLink('http://fuelphp.com'); $release1->setAllChanges(['Fixed' => ['fixed 1', 'fixed 2'], 'Changed' => ['changed 1']]); $release1->setDate(DateTime::createFromFormat('Y-m-d', '2015-01-29')); $log->addRelease($release1); $release2 = new Release('0.1.0'); $release2->setLink('http://google.com'); $release2->setLinkName('foobar'); $release2->setDate(DateTime::createFromFormat('Y-m-d', '2015-01-20')); $release2->setAllChanges(['Changed' => ['changed 2']]); $log->addRelease($release2); $result = $this->renderer->render($log); $this->assertJsonStringEqualsJsonFile(__DIR__ . '/../../resources/Parser-Json-testRender.json', $result); }