pax_global_header00006660000000000000000000000064130570464170014521gustar00rootroot0000000000000052 comment=a70c0ced4be299a63d32fa96d9281d03e94041df version-1.0.1/000077500000000000000000000000001305704641700132055ustar00rootroot00000000000000version-1.0.1/.gitignore000066400000000000000000000001071305704641700151730ustar00rootroot00000000000000/.idea /.php_cs.cache /composer.lock /src/autoload.php /tools /vendor version-1.0.1/.php_cs000066400000000000000000000036251305704641700144700ustar00rootroot00000000000000files() ->in('src') ->in('tests') ->name('*.php'); return Symfony\CS\Config\Config::create() ->setUsingCache(true) ->level(\Symfony\CS\FixerInterface::NONE_LEVEL) ->fixers( array( 'align_double_arrow', 'align_equals', 'concat_with_spaces', 'duplicate_semicolon', 'elseif', 'empty_return', 'encoding', 'eof_ending', 'extra_empty_lines', 'function_call_space', 'function_declaration', 'indentation', 'join_function', 'line_after_namespace', 'linefeed', 'list_commas', 'lowercase_constants', 'lowercase_keywords', 'method_argument_space', 'multiple_use', 'namespace_no_leading_whitespace', 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'parenthesis', 'php_closing_tag', 'phpdoc_indent', 'phpdoc_no_access', 'phpdoc_no_empty_return', 'phpdoc_no_package', 'phpdoc_params', 'phpdoc_scalar', 'phpdoc_separation', 'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_types', 'phpdoc_var_without_name', 'remove_lines_between_uses', 'return', 'self_accessor', 'short_array_syntax', 'short_tag', 'single_line_after_imports', 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'ternary_spaces', 'trailing_spaces', 'trim_array_spaces', 'unused_use', 'visibility', 'whitespacy_lines' ) ) ->finder($finder); version-1.0.1/.travis.yml000066400000000000000000000010251305704641700153140ustar00rootroot00000000000000os: - linux language: php before_install: - wget https://phar.io/releases/phive.phar - wget https://phar.io/releases/phive.phar.asc - gpg --keyserver hkps.pool.sks-keyservers.net --recv-keys 0x9B2D5D79 - gpg --verify phive.phar.asc phive.phar - chmod +x phive.phar - sudo mv phive.phar /usr/bin/phive install: - ant setup script: ./tools/phpunit php: - 5.6 - 7.0 - 7.1 - 7.0snapshot - 7.1snapshot - master matrix: allow_failures: - php: master fast_finish: true notifications: email: false version-1.0.1/LICENSE000066400000000000000000000030611305704641700142120ustar00rootroot00000000000000phar-io/version Copyright (c) 2016-2017 Arne Blankerts , Sebastian Heuer and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Arne Blankerts nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. version-1.0.1/README.md000066400000000000000000000010571305704641700144670ustar00rootroot00000000000000# Version Library for handling version information and constraints [![Build Status](https://travis-ci.org/phar-io/version.svg?branch=master)](https://travis-ci.org/phar-io/version) ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): composer require phar-io/version If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: composer require --dev phar-io/version version-1.0.1/build.xml000066400000000000000000000031151305704641700150260ustar00rootroot00000000000000 version-1.0.1/composer.json000066400000000000000000000012411305704641700157250ustar00rootroot00000000000000{ "name": "phar-io/version", "description": "Library for handling version information and constraints", "license": "BSD-3-Clause", "authors": [ { "name": "Arne Blankerts", "email": "arne@blankerts.de", "role": "Developer" }, { "name": "Sebastian Heuer", "email": "sebastian@phpeople.de", "role": "Developer" }, { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de", "role": "Developer" } ], "support": { "issues": "https://github.com/phar-io/version/issues" }, "require": { "php": "^5.6 || ^7.0" }, "autoload": { "classmap": [ "src/" ] } } version-1.0.1/phive.xml000066400000000000000000000004021305704641700150360ustar00rootroot00000000000000 version-1.0.1/phpunit.xml000066400000000000000000000012651305704641700154220ustar00rootroot00000000000000 tests src version-1.0.1/src/000077500000000000000000000000001305704641700137745ustar00rootroot00000000000000version-1.0.1/src/AbstractVersionConstraint.php000066400000000000000000000013611305704641700216640ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; abstract class AbstractVersionConstraint implements VersionConstraint { /** * @var string */ private $originalValue = ''; /** * @param string $originalValue */ public function __construct($originalValue) { $this->originalValue = $originalValue; } /** * @return string */ public function asString() { return $this->originalValue; } } version-1.0.1/src/AndVersionConstraintGroup.php000066400000000000000000000020671305704641700216440ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class AndVersionConstraintGroup extends AbstractVersionConstraint { /** * @var VersionConstraint[] */ private $constraints = []; /** * @param string $originalValue * @param VersionConstraint[] $constraints */ public function __construct($originalValue, array $constraints) { parent::__construct($originalValue); $this->constraints = $constraints; } /** * @param Version $version * * @return bool */ public function complies(Version $version) { foreach ($this->constraints as $constraint) { if (!$constraint->complies($version)) { return false; } } return true; } } version-1.0.1/src/AnyVersionConstraint.php000066400000000000000000000012101305704641700206410ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class AnyVersionConstraint implements VersionConstraint { /** * @param Version $version * * @return bool */ public function complies(Version $version) { return true; } /** * @return string */ public function asString() { return '*'; } } version-1.0.1/src/ExactVersionConstraint.php000066400000000000000000000011321305704641700211610ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class ExactVersionConstraint extends AbstractVersionConstraint { /** * @param Version $version * * @return bool */ public function complies(Version $version) { return $this->asString() == $version->getVersionString(); } } version-1.0.1/src/Exception.php000066400000000000000000000005541305704641700164470ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; interface Exception { } version-1.0.1/src/GreaterThanOrEqualToVersionConstraint.php000066400000000000000000000020111305704641700241120ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class GreaterThanOrEqualToVersionConstraint extends AbstractVersionConstraint { /** * @var Version */ private $minimalVersion; /** * @param string $originalValue * @param Version $minimalVersion */ public function __construct($originalValue, Version $minimalVersion) { parent::__construct($originalValue); $this->minimalVersion = $minimalVersion; } /** * @param Version $version * * @return bool */ public function complies(Version $version) { return $version->getVersionString() == $this->minimalVersion->getVersionString() || $version->isGreaterThan($this->minimalVersion); } } version-1.0.1/src/InvalidVersionException.php000066400000000000000000000001721305704641700213200ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class OrVersionConstraintGroup extends AbstractVersionConstraint { /** * @var VersionConstraint[] */ private $constraints = []; /** * @param string $originalValue * @param VersionConstraint[] $constraints */ public function __construct($originalValue, array $constraints) { parent::__construct($originalValue); $this->constraints = $constraints; } /** * @param Version $version * * @return bool */ public function complies(Version $version) { foreach ($this->constraints as $constraint) { if ($constraint->complies($version)) { return true; } } return false; } } version-1.0.1/src/PreReleaseSuffix.php000066400000000000000000000011361305704641700177220ustar00rootroot00000000000000value = $value; $this->number = $number; } /** * @return string */ public function getValue() { return $this->value; } /** * @return int|null */ public function getNumber() { return $this->number; } } version-1.0.1/src/SpecificMajorAndMinorVersionConstraint.php000066400000000000000000000021411305704641700242640ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class SpecificMajorAndMinorVersionConstraint extends AbstractVersionConstraint { /** * @var int */ private $major = 0; /** * @var int */ private $minor = 0; /** * @param string $originalValue * @param int $major * @param int $minor */ public function __construct($originalValue, $major, $minor) { parent::__construct($originalValue); $this->major = $major; $this->minor = $minor; } /** * @param Version $version * * @return bool */ public function complies(Version $version) { if ($version->getMajor()->getValue() != $this->major) { return false; } return $version->getMinor()->getValue() == $this->minor; } } version-1.0.1/src/SpecificMajorVersionConstraint.php000066400000000000000000000015701305704641700226410ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class SpecificMajorVersionConstraint extends AbstractVersionConstraint { /** * @var int */ private $major = 0; /** * @param string $originalValue * @param int $major */ public function __construct($originalValue, $major) { parent::__construct($originalValue); $this->major = $major; } /** * @param Version $version * * @return bool */ public function complies(Version $version) { return $version->getMajor()->getValue() == $this->major; } } version-1.0.1/src/UnsupportedVersionConstraintException.php000066400000000000000000000006711305704641700243330ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; final class UnsupportedVersionConstraintException extends \RuntimeException implements Exception { } version-1.0.1/src/Version.php000066400000000000000000000073731305704641700161440ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class Version { /** * @var VersionNumber */ private $major; /** * @var VersionNumber */ private $minor; /** * @var VersionNumber */ private $patch; /** * @var PreReleaseSuffix */ private $preReleaseSuffix; /** * @var string */ private $versionString = ''; /** * @param string $versionString */ public function __construct($versionString) { $this->ensureVersionStringIsValid($versionString); $this->versionString = $versionString; } /** * @param array $matches */ private function parseVersion(array $matches) { $this->major = new VersionNumber($matches['Major']); $this->minor = new VersionNumber($matches['Minor']); $this->patch = isset($matches['Patch']) ? new VersionNumber($matches['Patch']) : new VersionNumber(null); if (isset($matches['ReleaseType'])) { $preReleaseNumber = isset($matches['ReleaseTypeCount']) ? (int) $matches['ReleaseTypeCount'] : null; $this->preReleaseSuffix = new PreReleaseSuffix($matches['ReleaseType'], $preReleaseNumber); } } /** * @return PreReleaseSuffix */ public function getPreReleaseSuffix() { return $this->preReleaseSuffix; } /** * @return string */ public function getVersionString() { return $this->versionString; } /** * @param Version $version * * @return bool */ public function isGreaterThan(Version $version) { if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) { return false; } if ($version->getMajor()->getValue() < $this->getMajor()->getValue()) { return true; } if ($version->getMinor()->getValue() > $this->getMinor()->getValue()) { return false; } if ($version->getMinor()->getValue() < $this->getMinor()->getValue()) { return true; } if ($version->getPatch()->getValue() >= $this->getPatch()->getValue()) { return false; } if ($version->getPatch()->getValue() < $this->getPatch()->getValue()) { return true; } return false; } /** * @return VersionNumber */ public function getMajor() { return $this->major; } /** * @return VersionNumber */ public function getMinor() { return $this->minor; } /** * @return VersionNumber */ public function getPatch() { return $this->patch; } /** * @param string $version * * @throws InvalidVersionException */ private function ensureVersionStringIsValid($version) { $regex = '/^v? (?(0|(?:[1-9][0-9]*))) \\. (?(0|(?:[1-9][0-9]*))) (\\. (?(0|(?:[1-9][0-9]*))) )? (?: - (?(?:(dev|beta|b|RC|alpha|a|patch|p))) (?: (?[0-9]) )? )? $/x'; if (preg_match($regex, $version, $matches) !== 1) { throw new InvalidVersionException( sprintf("Version string '%s' does not follow SemVer semantics", $version) ); } $this->parseVersion($matches); } } version-1.0.1/src/VersionConstraint.php000066400000000000000000000010661305704641700202020ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; interface VersionConstraint { /** * @param Version $version * * @return bool */ public function complies(Version $version); /** * @return string */ public function asString(); } version-1.0.1/src/VersionConstraintParser.php000066400000000000000000000065311305704641700213610ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class VersionConstraintParser { /** * @param string $value * * @return VersionConstraint * * @throws UnsupportedVersionConstraintException */ public function parse($value) { if (strpos($value, '||') !== false) { return $this->handleOrGroup($value); } if (!preg_match('/^[\^~\*]?[\d.\*]+$/', $value)) { throw new UnsupportedVersionConstraintException( sprintf('Version constraint %s is not supported.', $value) ); } switch ($value[0]) { case '~': return $this->handleTildeOperator($value); case '^': return $this->handleCaretOperator($value); } $version = new VersionConstraintValue($value); if ($version->getMajor()->isAny()) { return new AnyVersionConstraint(); } if ($version->getMinor()->isAny()) { return new SpecificMajorVersionConstraint( $value, $version->getMajor()->getValue() ); } if ($version->getPatch()->isAny()) { return new SpecificMajorAndMinorVersionConstraint( $value, $version->getMajor()->getValue(), $version->getMinor()->getValue() ); } return new ExactVersionConstraint($value); } /** * @param $value * * @return OrVersionConstraintGroup */ private function handleOrGroup($value) { $constraints = []; foreach (explode('||', $value) as $groupSegment) { $constraints[] = $this->parse(trim($groupSegment)); } return new OrVersionConstraintGroup($value, $constraints); } /** * @param string $value * * @return AndVersionConstraintGroup */ private function handleTildeOperator($value) { $version = new Version(substr($value, 1)); $constraints = [ new GreaterThanOrEqualToVersionConstraint($value, $version) ]; if ($version->getPatch()->isAny()) { $constraints[] = new SpecificMajorVersionConstraint( $value, $version->getMajor()->getValue() ); } else { $constraints[] = new SpecificMajorAndMinorVersionConstraint( $value, $version->getMajor()->getValue(), $version->getMinor()->getValue() ); } return new AndVersionConstraintGroup($value, $constraints); } /** * @param string $value * * @return AndVersionConstraintGroup */ private function handleCaretOperator($value) { $version = new Version(substr($value, 1)); return new AndVersionConstraintGroup( $value, [ new GreaterThanOrEqualToVersionConstraint($value, $version), new SpecificMajorVersionConstraint($value, $version->getMajor()->getValue()) ] ); } } version-1.0.1/src/VersionConstraintValue.php000066400000000000000000000050271305704641700212000ustar00rootroot00000000000000versionString = $versionString; $this->parseVersion($versionString); } /** * @param $versionString */ private function parseVersion($versionString) { $this->extractBuildMetaData($versionString); $this->extractLabel($versionString); $versionSegments = explode('.', $versionString); $this->major = new VersionNumber($versionSegments[0]); $minorValue = isset($versionSegments[1]) ? $versionSegments[1] : null; $patchValue = isset($versionSegments[2]) ? $versionSegments[2] : null; $this->minor = new VersionNumber($minorValue); $this->patch = new VersionNumber($patchValue); } /** * @param string $versionString */ private function extractBuildMetaData(&$versionString) { if (preg_match('/\+(.*)/', $versionString, $matches) == 1) { $this->buildMetaData = $matches[1]; $versionString = str_replace($matches[0], '', $versionString); } } /** * @param string $versionString */ private function extractLabel(&$versionString) { if (preg_match('/\-(.*)/', $versionString, $matches) == 1) { $this->label = $matches[1]; $versionString = str_replace($matches[0], '', $versionString); } } /** * @return string */ public function getLabel() { return $this->label; } /** * @return string */ public function getBuildMetaData() { return $this->buildMetaData; } /** * @return string */ public function getVersionString() { return $this->versionString; } /** * @return VersionNumber */ public function getMajor() { return $this->major; } /** * @return VersionNumber */ public function getMinor() { return $this->minor; } /** * @return VersionNumber */ public function getPatch() { return $this->patch; } } version-1.0.1/src/VersionNumber.php000066400000000000000000000014421305704641700173040ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; class VersionNumber { /** * @var int */ private $value; /** * @param mixed $value */ public function __construct($value) { if (is_numeric($value)) { $this->value = $value; } } /** * @return bool */ public function isAny() { return $this->value === null; } /** * @return int */ public function getValue() { return $this->value; } } version-1.0.1/tests/000077500000000000000000000000001305704641700143475ustar00rootroot00000000000000version-1.0.1/tests/Integration/000077500000000000000000000000001305704641700166325ustar00rootroot00000000000000version-1.0.1/tests/Integration/VersionConstraintParserTest.php000066400000000000000000000100711305704641700250510ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers \PharIo\Version\VersionConstraintParser */ class VersionConstraintParserTest extends TestCase { /** * @dataProvider versionStringProvider * * @param string $versionString * @param VersionConstraint $expectedConstraint */ public function testReturnsExpectedConstraint($versionString, VersionConstraint $expectedConstraint) { $parser = new VersionConstraintParser; $this->assertEquals($expectedConstraint, $parser->parse($versionString)); } /** * @dataProvider unsupportedVersionStringProvider * * @param string $versionString */ public function testThrowsExceptionIfVersionStringIsNotSupported($versionString) { $parser = new VersionConstraintParser; $this->expectException(UnsupportedVersionConstraintException::class); $parser->parse($versionString); } /** * @return array */ public function versionStringProvider() { return [ ['1.0.2', new ExactVersionConstraint('1.0.2')], [ '~4.6', new AndVersionConstraintGroup( '~4.6', [ new GreaterThanOrEqualToVersionConstraint('~4.6', new Version('4.6')), new SpecificMajorVersionConstraint('~4.6', 4) ] ) ], [ '~4.6.2', new AndVersionConstraintGroup( '~4.6.2', [ new GreaterThanOrEqualToVersionConstraint('~4.6.2', new Version('4.6.2')), new SpecificMajorAndMinorVersionConstraint('~4.6.2', 4, 6) ] ) ], [ '^2.6.1', new AndVersionConstraintGroup( '^2.6.1', [ new GreaterThanOrEqualToVersionConstraint('^2.6.1', new Version('2.6.1')), new SpecificMajorVersionConstraint('^2.6.1', 2) ] ) ], ['5.1.*', new SpecificMajorAndMinorVersionConstraint('5.1.*', 5, 1)], ['5.*', new SpecificMajorVersionConstraint('5.*', 5)], ['*', new AnyVersionConstraint()], [ '1.0.2 || 1.0.5', new OrVersionConstraintGroup( '1.0.2 || 1.0.5', [ new ExactVersionConstraint('1.0.2'), new ExactVersionConstraint('1.0.5') ] ) ], [ '^5.6 || ^7.0', new OrVersionConstraintGroup( '^5.6 || ^7.0', [ new AndVersionConstraintGroup( '^5.6', [ new GreaterThanOrEqualToVersionConstraint('^5.6', new Version('5.6')), new SpecificMajorVersionConstraint('^5.6', 5) ] ), new AndVersionConstraintGroup( '^7.0', [ new GreaterThanOrEqualToVersionConstraint('^7.0', new Version('7.0')), new SpecificMajorVersionConstraint('^7.0', 7) ] ) ] ) ] ]; } public function unsupportedVersionStringProvider() { return [ ['foo'], ['+1.0.2'], ['>=2.0'], ['^5.6 || >= 7.0'], ['2.0 || foo'] ]; } } version-1.0.1/tests/Unit/000077500000000000000000000000001305704641700152665ustar00rootroot00000000000000version-1.0.1/tests/Unit/AbstractVersionConstraintTest.php000066400000000000000000000014261305704641700240200ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers \PharIo\Version\AbstractVersionConstraint */ class AbstractVersionConstraintTest extends TestCase { public function testAsString() { /** @var AbstractVersionConstraint|\PHPUnit_Framework_MockObject_MockObject $constraint */ $constraint = $this->getMockForAbstractClass(AbstractVersionConstraint::class, ['foo']); $this->assertSame('foo', $constraint->asString()); } } version-1.0.1/tests/Unit/AndVersionConstraintGroupTest.php000066400000000000000000000033601305704641700237730ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\AndVersionConstraintGroup */ class AndVersionConstraintGroupTest extends TestCase { public function testReturnsFalseIfOneConstraintReturnsFalse() { $firstConstraint = $this->createMock(VersionConstraint::class); $secondConstraint = $this->createMock(VersionConstraint::class); $firstConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(true)); $secondConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(false)); $group = new AndVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]); $this->assertFalse($group->complies(new Version('1.0.0'))); } public function testReturnsTrueIfAllConstraintsReturnsTrue() { $firstConstraint = $this->createMock(VersionConstraint::class); $secondConstraint = $this->createMock(VersionConstraint::class); $firstConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(true)); $secondConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(true)); $group = new AndVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]); $this->assertTrue($group->complies(new Version('1.0.0'))); } } version-1.0.1/tests/Unit/AnyVersionConstraintTest.php000066400000000000000000000020241305704641700227770ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\AnyVersionConstraint */ class AnyVersionConstraintTest extends TestCase { public function versionProvider() { return [ [new Version('1.0.2')], [new Version('4.8')], [new Version('0.1.1-dev')] ]; } /** * @dataProvider versionProvider * * @param Version $version */ public function testReturnsTrue(Version $version) { $constraint = new AnyVersionConstraint; $this->assertTrue($constraint->complies($version)); } public function testAsString() { $this->assertSame('*', (new AnyVersionConstraint())->asString()); } } version-1.0.1/tests/Unit/ExactVersionConstraintTest.php000066400000000000000000000031761305704641700233250ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\ExactVersionConstraint */ class ExactVersionConstraintTest extends TestCase { public function compliantVersionProvider() { return [ ['1.0.2', new Version('1.0.2')], ['4.8.9', new Version('4.8.9')], ['4.8', new Version('4.8')], ]; } public function nonCompliantVersionProvider() { return [ ['1.0.2', new Version('1.0.3')], ['4.8.9', new Version('4.7.9')], ['4.8', new Version('4.8.5')], ]; } /** * @dataProvider compliantVersionProvider * * @param string $constraintValue * @param Version $version */ public function testReturnsTrueForCompliantVersion($constraintValue, Version $version) { $constraint = new ExactVersionConstraint($constraintValue); $this->assertTrue($constraint->complies($version)); } /** * @dataProvider nonCompliantVersionProvider * * @param string $constraintValue * @param Version $version */ public function testReturnsFalseForNonCompliantVersion($constraintValue, Version $version) { $constraint = new ExactVersionConstraint($constraintValue); $this->assertFalse($constraint->complies($version)); } } version-1.0.1/tests/Unit/GreaterThanOrEqualToVersionConstraintTest.php000066400000000000000000000032541305704641700262560ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\GreaterThanOrEqualToVersionConstraint */ class GreaterThanOrEqualToVersionConstraintTest extends TestCase { public function versionProvider() { return [ // compliant versions [new Version('1.0.2'), new Version('1.0.2'), true], [new Version('1.0.2'), new Version('1.0.3'), true], [new Version('1.0.2'), new Version('1.1.1'), true], [new Version('1.0.2'), new Version('2.0.0'), true], [new Version('1.0.2'), new Version('1.0.3'), true], // non-compliant versions [new Version('1.0.2'), new Version('1.0.1'), false], [new Version('1.9.8'), new Version('0.9.9'), false], [new Version('2.3.1'), new Version('2.2.3'), false], [new Version('3.0.2'), new Version('2.9.9'), false], ]; } /** * @dataProvider versionProvider * * @param Version $constraintVersion * @param Version $version * @param bool $expectedResult */ public function testReturnsTrueForCompliantVersions(Version $constraintVersion, Version $version, $expectedResult) { $constraint = new GreaterThanOrEqualToVersionConstraint('foo', $constraintVersion); $this->assertSame($expectedResult, $constraint->complies($version)); } } version-1.0.1/tests/Unit/OrVersionConstraintGroupTest.php000066400000000000000000000043561305704641700236570ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\OrVersionConstraintGroup */ class OrVersionConstraintGroupTest extends TestCase { public function testReturnsTrueIfOneConstraintReturnsFalse() { $firstConstraint = $this->createMock(VersionConstraint::class); $secondConstraint = $this->createMock(VersionConstraint::class); $firstConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(false)); $secondConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(true)); $group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]); $this->assertTrue($group->complies(new Version('1.0.0'))); } public function testReturnsTrueIfAllConstraintsReturnsTrue() { $firstConstraint = $this->createMock(VersionConstraint::class); $secondConstraint = $this->createMock(VersionConstraint::class); $firstConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(true)); $group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]); $this->assertTrue($group->complies(new Version('1.0.0'))); } public function testReturnsFalseIfAllConstraintsReturnsFalse() { $firstConstraint = $this->createMock(VersionConstraint::class); $secondConstraint = $this->createMock(VersionConstraint::class); $firstConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(false)); $secondConstraint->expects($this->once()) ->method('complies') ->will($this->returnValue(false)); $group = new OrVersionConstraintGroup('foo', [$firstConstraint, $secondConstraint]); $this->assertFalse($group->complies(new Version('1.0.0'))); } } version-1.0.1/tests/Unit/SpecificMajorAndMinorVersionConstraintTest.php000066400000000000000000000026171305704641700264260ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\SpecificMajorAndMinorVersionConstraint */ class SpecificMajorAndMinorVersionConstraintTest extends TestCase { public function versionProvider() { return [ // compliant versions [1, 0, new Version('1.0.2'), true], [1, 0, new Version('1.0.3'), true], [1, 1, new Version('1.1.1'), true], // non-compliant versions [2, 9, new Version('0.9.9'), false], [3, 2, new Version('2.2.3'), false], [2, 8, new Version('2.9.9'), false], ]; } /** * @dataProvider versionProvider * * @param int $major * @param int $minor * @param Version $version * @param bool $expectedResult */ public function testReturnsTrueForCompliantVersions($major, $minor, Version $version, $expectedResult) { $constraint = new SpecificMajorAndMinorVersionConstraint('foo', $major, $minor); $this->assertSame($expectedResult, $constraint->complies($version)); } } version-1.0.1/tests/Unit/SpecificMajorVersionConstraintTest.php000066400000000000000000000024701305704641700247730ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers PharIo\Version\SpecificMajorVersionConstraint */ class SpecificMajorVersionConstraintTest extends TestCase { public function versionProvider() { return [ // compliant versions [1, new Version('1.0.2'), true], [1, new Version('1.0.3'), true], [1, new Version('1.1.1'), true], // non-compliant versions [2, new Version('0.9.9'), false], [3, new Version('2.2.3'), false], [3, new Version('2.9.9'), false], ]; } /** * @dataProvider versionProvider * * @param int $major * @param Version $version * @param bool $expectedResult */ public function testReturnsTrueForCompliantVersions($major, Version $version, $expectedResult) { $constraint = new SpecificMajorVersionConstraint('foo', $major); $this->assertSame($expectedResult, $constraint->complies($version)); } } version-1.0.1/tests/Unit/VersionTest.php000066400000000000000000000065421305704641700202730ustar00rootroot00000000000000, Sebastian Heuer , Sebastian Bergmann * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PharIo\Version; use PHPUnit\Framework\TestCase; /** * @covers \PharIo\Version\Version */ class VersionTest extends TestCase { /** * @dataProvider versionProvider * * @param string $versionString * @param string $expectedMajor * @param string $expectedMinor * @param string $expectedPatch * @param string $expectedPreReleaseValue * @param int $expectedReleaseCount */ public function testParsesVersionNumbers($versionString, $expectedMajor, $expectedMinor, $expectedPatch, $expectedPreReleaseValue = '', $expectedReleaseCount = 0) { $version = new Version($versionString); $this->assertSame($expectedMajor, $version->getMajor()->getValue()); $this->assertSame($expectedMinor, $version->getMinor()->getValue()); $this->assertSame($expectedPatch, $version->getPatch()->getValue()); if ($expectedPreReleaseValue !== '') { $this->assertSame($expectedPreReleaseValue, $version->getPreReleaseSuffix()->getValue()); } if ($expectedReleaseCount !== 0) { $this->assertSame($expectedReleaseCount, $version->getPreReleaseSuffix()->getNumber()); } $this->assertSame($versionString, $version->getVersionString()); } public function versionProvider() { return [ ['0.0.1', '0', '0', '1'], ['0.1.2', '0', '1', '2'], ['1.0.0-alpha', '1', '0', '0', 'alpha'], ['3.4.12-dev3', '3', '4', '12', 'dev', 3], ]; } /** * @dataProvider versionGreaterThanProvider * * @param Version $versionA * @param Version $versionB * @param bool $expectedResult */ public function testIsGreaterThan(Version $versionA, Version $versionB, $expectedResult) { $this->assertSame($expectedResult, $versionA->isGreaterThan($versionB)); } /** * @return array */ public function versionGreaterThanProvider() { return [ [new Version('1.0.0'), new Version('1.0.1'), false], [new Version('1.0.1'), new Version('1.0.0'), true], [new Version('1.1.0'), new Version('1.0.1'), true], [new Version('1.1.0'), new Version('2.0.1'), false], [new Version('1.1.0'), new Version('1.1.0'), false], [new Version('2.5.8'), new Version('1.6.8'), true], [new Version('2.5.8'), new Version('2.6.8'), false], [new Version('2.5.8'), new Version('3.1.2'), false], ]; } /** * @dataProvider invalidVersionStringProvider * * @param string $versionString */ public function testThrowsExceptionIfVersionStringDoesNotFollowSemVer($versionString) { $this->expectException(InvalidVersionException::class); new Version($versionString); } /** * @return array */ public function invalidVersionStringProvider() { return [ ['foo'], ['0.0.1-dev+ABC', '0', '0', '1', 'dev', 'ABC'], ['1.0.0-x.7.z.92', '1', '0', '0', 'x.7.z.92'] ]; } }