diff --git a/src/Composer/Package/AliasPackage.php b/src/Composer/Package/AliasPackage.php index cb40486aa..1b6481d8e 100644 --- a/src/Composer/Package/AliasPackage.php +++ b/src/Composer/Package/AliasPackage.php @@ -16,6 +16,7 @@ use Composer\Package\LinkConstraint\LinkConstraintInterface; use Composer\Package\LinkConstraint\VersionConstraint; use Composer\Repository\RepositoryInterface; use Composer\Repository\PlatformRepository; +use Composer\Package\Version\VersionParser; /** * @author Jordi Boggiano @@ -41,14 +42,14 @@ class AliasPackage extends BasePackage * @param string $version The version the alias must report * @param string $prettyVersion The alias's non-normalized version */ - public function __construct($aliasOf, $version, $prettyVersion) + public function __construct(PackageInterface $aliasOf, $version, $prettyVersion) { parent::__construct($aliasOf->getName()); $this->version = $version; $this->prettyVersion = $prettyVersion; $this->aliasOf = $aliasOf; - $this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4); + $this->dev = VersionParser::isDev($version); // replace self.version dependencies foreach (array('requires', 'recommends', 'suggests') as $type) { diff --git a/src/Composer/Package/MemoryPackage.php b/src/Composer/Package/MemoryPackage.php index e266f754c..2c3502502 100644 --- a/src/Composer/Package/MemoryPackage.php +++ b/src/Composer/Package/MemoryPackage.php @@ -12,6 +12,8 @@ namespace Composer\Package; +use Composer\Package\Version\VersionParser; + /** * A package with setters for all members to create it dynamically in memory * @@ -69,7 +71,7 @@ class MemoryPackage extends BasePackage $this->version = $version; $this->prettyVersion = $prettyVersion; - $this->dev = 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4); + $this->dev = VersionParser::isDev($version); } /** diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php index 19cd240a8..763929613 100644 --- a/src/Composer/Package/Version/VersionParser.php +++ b/src/Composer/Package/Version/VersionParser.php @@ -24,6 +24,17 @@ class VersionParser { private $modifierRegex = '[.-]?(?:(beta|RC|alpha|patch|pl|p)(?:[.-]?(\d+))?)?([.-]?dev)?'; + /** + * Checks if a version is dev or not + * + * @param string $version + * @return Boolean + */ + static public function isDev($version) + { + return 'dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4); + } + /** * Normalizes a version string to be able to perform comparisons on it * diff --git a/tests/Composer/Test/Package/Version/VersionParserTest.php b/tests/Composer/Test/Package/Version/VersionParserTest.php index f45d0a0dc..c33bb2860 100644 --- a/tests/Composer/Test/Package/Version/VersionParserTest.php +++ b/tests/Composer/Test/Package/Version/VersionParserTest.php @@ -187,4 +187,23 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase 'invalid version' => array('1.0.0-meh'), ); } + + /** + * @dataProvider dataIsDev + */ + public function testIsDev($expected, $version) + { + $this->assertSame($expected, VersionParser::isDev($version)); + } + + public function dataIsDev() + { + return array( + array(false, '1.0'), + array(false, 'v2.0.*'), + array(false, '3.0dev'), + array(true, 'dev-master'), + array(true, '3.1.2-dev'), + ); + } }