Skip to content

Commit

Permalink
Added isMajorRelease(), isMinorRelease(), isPatchRelease() and …
Browse files Browse the repository at this point in the history
…`isPreRelease()` to `SemanticVersionInterface`
  • Loading branch information
Rayne committed Feb 13, 2017
1 parent 5d01f4b commit 9d69bab
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 15 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ This project *surprisingly* adheres to [Semantic Versioning](http://semver.org).

No notable changes.

## [1.1.0] - 2017-02-13

### Added

* `SemanticVersionInterface->isMajorRelease()`
* `SemanticVersionInterface->isMinorRelease()`
* `SemanticVersionInterface->isPatchRelease()`
* `SemanticVersionInterface->isPreRelease()`

## [1.0.0] - 2016-07-24

### Removed
Expand Down Expand Up @@ -35,5 +44,6 @@ No notable changes.
* Renamed `NoSemanticVersionException` to `InvalidVersionException`

[Unreleased]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0...HEAD
[1.1.0]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0...1.1.0
[1.0.0]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0-rc.3...1.0.0
[1.0.0-rc.3]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0-rc.2...1.0.0-rc.3
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,25 @@ A tiny independent library for parsing and comparing semantic versions which is
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/?branch=master)
[![License](https://poser.pugx.org/rayne/semantic-versioning/license)](https://packagist.org/packages/rayne/semantic-versioning)

# Dependencies
## Dependencies

## Production
### Production

* PHP 5.6 or better

## Development
### Development

* Composer
* Git
* PHPUnit

# Setup
## Setup

[Download Composer](https://getcomposer.org/download) and install `rayne/semantic-versioning`.

composer require rayne/semantic-versioning ~1.0

Set the `@dev` stability flag to install the latest development version.

composer require rayne/semantic-versioning @dev

# Tests
## Tests

1. Clone the repository

Expand All @@ -45,7 +41,7 @@ Set the `@dev` stability flag to install the latest development version.

./vendor/bin/phpunit

# Examples
## Examples

The library contains the following classes:

Expand All @@ -58,7 +54,7 @@ The library contains the following classes:
The examples are part of the test suite.
Have a look at the `tests` directory for more information.

## Interpret semantic versions
### Interpret semantic versions

```php
use Rayne\SemanticVersioning\SemanticVersion;
Expand All @@ -72,9 +68,14 @@ assert( 0 === $version->getPatch());
assert( 'beta' === $version->getPre());
assert( 'exp.sha.5114f85' === $version->getMeta());
assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion());

assert(true === $version->isMajorRelease());
assert(false === $version->isMinorRelease());
assert(false === $version->isPatchRelease());
assert(true === $version->isPreRelease());
```

## Compare semantic versions
### Compare semantic versions

```php
use Rayne\SemanticVersioning\SemanticComparator;
Expand All @@ -100,7 +101,7 @@ assert($comparator($release, $candidate) > 0);
assert($comparator->compare($release, $candidate) > 0);
```

## Sort semantic versions
### Sort semantic versions

```php
use Rayne\SemanticVersioning\SemanticComparator;
Expand Down
32 changes: 32 additions & 0 deletions src/SemanticVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,36 @@ public function getVersion()
{
return $this->version;
}

/**
* @inheritdoc
*/
public function isMajorRelease()
{
return $this->minor == 0 && $this->patch == 0;
}

/**
* @inheritdoc
*/
public function isMinorRelease()
{
return $this->minor > 0 && $this->patch == 0;
}

/**
* @inheritdoc
*/
public function isPatchRelease()
{
return $this->patch > 0;
}

/**
* @inheritdoc
*/
public function isPreRelease()
{
return $this->pre !== '';
}
}
26 changes: 24 additions & 2 deletions src/SemanticVersionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function getPre();

/**
* @return string[]
*
* @since 1.0.0-rc.2
*/
public function getPreStack();
Expand All @@ -56,7 +55,6 @@ public function getMeta();

/**
* @return string[]
*
* @since 1.0.0-rc.2
*/
public function getMetaStack();
Expand All @@ -65,4 +63,28 @@ public function getMetaStack();
* @return string
*/
public function getVersion();

/**
* @return bool
* @since 1.1.0-rc.1
*/
public function isMajorRelease();

/**
* @return bool
* @since 1.1.0-rc.1
*/
public function isMinorRelease();

/**
* @return bool
* @since 1.1.0-rc.1
*/
public function isPatchRelease();

/**
* @return bool
* @since 1.1.0-rc.1
*/
public function isPreRelease();
}
5 changes: 5 additions & 0 deletions tests/Examples/ExamplesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public function testAttributes()
assert('beta' === $version->getPre());
assert('exp.sha.5114f85' === $version->getMeta());
assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion());

assert(true === $version->isMajorRelease());
assert(false === $version->isMinorRelease());
assert(false === $version->isPatchRelease());
assert(true === $version->isPreRelease());
}

public function testCompare()
Expand Down
50 changes: 50 additions & 0 deletions tests/SemanticVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,54 @@ public function testInvalidVersion($version)
{
new SemanticVersion($version);
}

public function provideReleaseTypes()
{
return [
// Major, Minor, Patch
['0.0.0', true, false, false, false],
['0.1.0', false, true, false, false],
['0.1.1', false, false, true, false],

['1.0.0', true, false, false, false],
['1.1.0', false, true, false, false],
['1.1.1', false, false, true, false],

// Major, Minor, Patch + Pre-Release
['0.0.0-pre', true, false, false, true],
['0.1.0-pre', false, true, false, true],
['0.1.1-pre', false, false, true, true],

['1.0.0-pre', true, false, false, true],
['1.1.0-pre', false, true, false, true],
['1.1.1-pre', false, false, true, true],

// Major, Minor Patch + Meta-Release
['0.0.0+meta', true, false, false, false],
['0.1.0+meta', false, true, false, false],
['0.1.1+meta', false, false, true, false],

['1.0.0+meta', true, false, false, false],
['1.1.0+meta', false, true, false, false],
['1.1.1+meta', false, false, true, false],
];
}

/**
* @dataProvider provideReleaseTypes
* @param string $version
* @param bool $isMajorRelease
* @param bool $isMinorRelease
* @param bool $isPatchRelease
* @param bool $isPreRelease
*/
public function testReleaseTypes($version, $isMajorRelease, $isMinorRelease, $isPatchRelease, $isPreRelease)
{
$object = new SemanticVersion($version);

$this->assertSame($isMajorRelease, $object->isMajorRelease());
$this->assertSame($isMinorRelease, $object->isMinorRelease());
$this->assertSame($isPatchRelease, $object->isPatchRelease());
$this->assertSame($isPreRelease, $object->isPreRelease());
}
}

0 comments on commit 9d69bab

Please sign in to comment.