Skip to content

Commit

Permalink
Merge pull request #257 from elliotchance/1.7.2/257-version-name
Browse files Browse the repository at this point in the history
Show version name in CLI
  • Loading branch information
elliotchance committed Mar 12, 2015
2 parents d5a4b29 + 62e0cea commit c37798b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
8 changes: 6 additions & 2 deletions bin/concise
Expand Up @@ -4,9 +4,13 @@
require_once('vendor/autoload.php');

use Concise\Console\Command;
use Concise\Version;

$version = new \Concise\Version();
echo trim("Concise " . $version->getConciseVersion()) . " by Elliot Chance.\n\n";
$version = new Version();
$versionNumber = $version->getConciseVersion();
$versionName = $version->getVersionNameForVersion($versionNumber);
echo trim("Concise " . $versionNumber . ' ' . $versionName);
echo " by Elliot Chance.\n\n";

$command = new Command();
$command->run($_SERVER['argv'], true);
21 changes: 21 additions & 0 deletions src/Concise/Version.php
Expand Up @@ -49,4 +49,25 @@ public function getConciseVersion()
{
return $this->getVersionForPackage('elliotchance/concise');
}

public function getVersionNameForVersion($version)
{
$names = array(
'Big Bang',
'Dark Matter',
'String Theory',
'Supernova',
'Quantum',
'Antimatter',
'Entropy',
'Multiverse',
);

$version = ltrim($version, 'v');
if (strlen($version) < 3) {
return '';
}

return $names[substr($version, 2, 1)];
}
}
42 changes: 40 additions & 2 deletions tests/Concise/VersionTest.php
Expand Up @@ -17,12 +17,20 @@ public function testAnEmptyStringWillBeReturnedIfThePackageCanNotBeFound()

public function testVersionCanBeExtractedForAPackageName()
{
$this->assert($this->version->getVersionForPackage('sebastian/version'), matches_regex, '/^\\d\.\\d+/');
$this->assert(
$this->version->getVersionForPackage('sebastian/version'),
matches_regex,
'/^\\d\.\\d+/'
);
}

public function testWeCanEasilyGetTheConciseVersion()
{
$this->assert($this->version->getConciseVersion(), equals, $this->version->getVersionForPackage('elliotchance/concise'));
$this->assert(
$this->version->getConciseVersion(),
equals,
$this->version->getVersionForPackage('elliotchance/concise')
);
}

public function testFindingVendorFolder()
Expand All @@ -45,4 +53,34 @@ public function testFindVendorFolderWillReturnNullIfTheVendorFolderCouldNotBeFou
->get();
$this->assert($version->findVendorFolder('/tmp'), is_null);
}

public function versionData()
{
return array(
// Edge cases.
'unknown version is blank' => array('', ''),
'version can be prefixed with v' => array('v1.1', 'Dark Matter'),
'patch version' => array('1.2.3', 'String Theory'),

// Specific versions.
array('1.0', 'Big Bang'),
array('1.1', 'Dark Matter'),
array('1.2', 'String Theory'),
array('1.3', 'Supernova'),
array('1.4', 'Quantum'),
array('1.5', 'Antimatter'),
array('1.6', 'Entropy'),
array('1.7', 'Multiverse'),
);
}

/**
* @group #257
* @dataProvider versionData
*/
public function testVersionName($version, $expectedName)
{
$name = $this->version->getVersionNameForVersion($version);
$this->assert($name, equals, $expectedName);
}
}

0 comments on commit c37798b

Please sign in to comment.