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;
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function render(Log $log)
 {
     $content = ['title' => $log->getTitle(), 'description' => $log->getDescription(), 'releases' => []];
     /**
      * @var string  $name
      * @var Release $release
      */
     foreach ($log as $name => $release) {
         $content['releases'][$name] = $this->renderRelease($release);
     }
     return json_encode($content);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function render(Log $log)
 {
     $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><log />');
     $xml->addChild('title', $log->getTitle());
     $xml->addChild('description', $log->getDescription());
     $releases = $xml->addChild('releases');
     /** @var Release $release */
     foreach ($log as $release) {
         $this->renderRelease($releases, $release);
     }
     $xml = $xml->asXML();
     return $xml !== false ? $xml : '';
 }
 /**
  * {@inheritdoc}
  */
 public function render(Log $log)
 {
     $content = "# {$log->getTitle()}\n" . "{$log->getDescription()}\n";
     $links = '';
     /** @var Release $release */
     foreach ($log as $release) {
         $content .= $this->renderRelease($release);
         $links .= $this->createLink($release);
     }
     if ($links !== '') {
         $content .= "\n\n" . $links;
     }
     return $content;
 }
Exemple #6
0
 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'));
 }
Exemple #7
0
 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);
 }
Exemple #8
0
 /**
  * Combines all changes of the name of the given release from the given log into this log.
  *
  * @param Log    $log
  * @param string $name
  */
 protected function mergeRelease(Log $log, $name)
 {
     $myRelease = $this->getRelease($name);
     $theirRelease = $log->getRelease($name);
     $changes = $this->mergeChangesArrays($theirRelease->getAllChanges(), $myRelease->getAllChanges());
     $myRelease->setAllChanges($changes);
 }