Browse Source

Phar release - fix readme generation

SpacePossum 7 years ago
parent
commit
f9b2c23e99

+ 18 - 4
src/Console/Command/HelpCommand.php

@@ -338,10 +338,14 @@ EOF
             return $version;
         }
 
-        $currentMajor = (int) Application::VERSION;
-        $changelogFile = __DIR__.'/../../../CHANGELOG.md';
-        $changelog = @file_get_contents($changelogFile);
+        $changelogFile = self::getChangeLogFile();
+        if (null === $changelogFile) {
+            $version = Application::VERSION;
 
+            return $version;
+        }
+
+        $changelog = @file_get_contents($changelogFile);
         if (false === $changelog) {
             $error = error_get_last();
 
@@ -352,7 +356,7 @@ EOF
             ));
         }
 
-        for ($i = $currentMajor; $i > 0; --$i) {
+        for ($i = (int) Application::VERSION; $i > 0; --$i) {
             if (1 === preg_match('/Changelog for v('.$i.'.\d+.\d+)/', $changelog, $matches)) {
                 $version = $matches[1];
 
@@ -375,6 +379,16 @@ EOF
         $output->getFormatter()->setStyle('url', new OutputFormatterStyle('blue'));
     }
 
+    /**
+     * @return string|null
+     */
+    private static function getChangeLogFile()
+    {
+        $changelogFile = __DIR__.'/../../../CHANGELOG.md';
+
+        return is_file($changelogFile) ? $changelogFile : null;
+    }
+
     /**
      * @return string
      */

+ 0 - 1
tests/AutoReview/ProjectCodeTest.php

@@ -38,7 +38,6 @@ final class ProjectCodeTest extends TestCase
         'PhpCsFixer\ConfigurationException\InvalidConfigurationException',
         'PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException',
         'PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException',
-        'PhpCsFixer\Console\Command\HelpCommand',
         'PhpCsFixer\Console\Command\DescribeNameNotFoundException',
         'PhpCsFixer\Console\Command\SelfUpdateCommand',
         'PhpCsFixer\Console\Output\NullOutput',

+ 39 - 0
tests/Console/Command/HelpCommandTest.php

@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * This file is part of PHP CS Fixer.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *     Dariusz Rumiński <dariusz.ruminski@gmail.com>
+ *
+ * This source file is subject to the MIT license that is bundled
+ * with this source code in the file LICENSE.
+ */
+
+namespace PhpCsFixer\Tests\Console\Command;
+
+use PhpCsFixer\Console\Application;
+use PhpCsFixer\Console\Command\HelpCommand;
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @internal
+ *
+ * @covers \PhpCsFixer\Console\Command\HelpCommand
+ */
+final class HelpCommandTest extends TestCase
+{
+    public function testGetLatestReleaseVersionFromChangeLog()
+    {
+        $helpVersion = HelpCommand::getLatestReleaseVersionFromChangeLog();
+        $appVersion = Application::VERSION;
+        $this->assertTrue(
+            version_compare($helpVersion, $appVersion, '<='),
+            sprintf(
+                'Expected version from change log "%s" <= as application version "%s".',
+                $helpVersion,
+                $appVersion
+            )
+        );
+    }
+}