├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist └── src ├── lib └── KevinGH │ └── Version │ └── Version.php └── tests ├── KevinGH └── Version │ └── VersionTest.php └── load.php /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | !.gitignore 3 | !.travis.yml 4 | composer.lock 5 | coverage/ 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Kevin Herrera 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 7 | of the Software, and to permit persons to whom the Software is furnished to do 8 | so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Version 2 | 3 | > I am no longer maintaining this library. This project has been deprecated in favor of [Herrera.io php-version](https://github.com/herrera-io/php-version). If you would like to take over development of this project, please email me. 4 | 5 | [![Build Status](https://secure.travis-ci.org/kherge/Version.png?branch=master)](http://travis-ci.org/kherge/Version) 6 | 7 | A parsing and comparison library for [semantic versioning](http://semver.org/). 8 | 9 | ## Installing 10 | 11 | To install Version, you must add it to the list of dependencies in your [`composer.json`][Composer] file. 12 | 13 | $ php composer.phar require kherge/version=1.* 14 | 15 | If you are not using Composer to manage your dependencies, you may use any [PSR-0][PSR-0] class loader to load it from the `src/lib` directory. 16 | 17 | ## Usage 18 | 19 | Please see [the wiki][wiki] for detail usage information. 20 | 21 | [Composer]: http://getcomposer.org/ 22 | [PSR-0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md 23 | [wiki]: https://github.com/kherge/Version/wiki/API 24 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "library", 3 | "name": "kherge/version", 4 | "description": "A parsing and comparison library for semantic versioning.", 5 | "homepage": "http://github.com/kherge/Version", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Kevin Herrera", 10 | "email": "me@kevingh.com" 11 | } 12 | ], 13 | 14 | "require": { 15 | "php": ">=5.3.3" 16 | }, 17 | 18 | "autoload": { 19 | "psr-0": { 20 | "KevinGH\\Version": "src/lib/" 21 | } 22 | }, 23 | 24 | "extra": { 25 | "branch-alias": { 26 | "dev-master": "1.0-dev" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | src/lib/ 15 | 16 | 17 | 18 | 19 | src/tests/ 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/lib/KevinGH/Version/Version.php: -------------------------------------------------------------------------------- 1 | 20 | */ 21 | class Version 22 | { 23 | /** 24 | * The semantic version regular expression. 25 | * 26 | * @var string 27 | */ 28 | const REGEX = '/^\d+\.\d+\.\d+(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?$/'; 29 | 30 | /** 31 | * The build information. 32 | * 33 | * @var array 34 | */ 35 | private $build; 36 | 37 | /** 38 | * The major version number. 39 | * 40 | * @var integer 41 | */ 42 | private $major = 0; 43 | 44 | /** 45 | * The minor version number. 46 | * 47 | * @var integer 48 | */ 49 | private $minor = 0; 50 | 51 | /** 52 | * The patch number. 53 | * 54 | * @var integer 55 | */ 56 | private $patch = 0; 57 | 58 | /** 59 | * The pre-release information. 60 | * 61 | * @var array 62 | */ 63 | private $pre; 64 | 65 | /** 66 | * Parses the string representation of the version information. 67 | * 68 | * @param string $string The string representation. 69 | */ 70 | public function __construct($string = '') 71 | { 72 | if (false === empty($string)) { 73 | $this->parseString($string); 74 | } 75 | } 76 | 77 | /** 78 | * Generates a string using the current version information. 79 | * 80 | * @return string The string representation of the information. 81 | * 82 | * @api 83 | */ 84 | public function __toString() 85 | { 86 | $string = sprintf('%d.%d.%d', $this->major, $this->minor, $this->patch); 87 | 88 | if ($this->pre) { 89 | $string .= '-' . join('.', $this->pre); 90 | } 91 | 92 | if ($this->build) { 93 | $string .= '+' . join('.', $this->build); 94 | } 95 | 96 | return $string; 97 | } 98 | 99 | /** 100 | * Compares one version to another. 101 | * 102 | * @param Version $version Another version. 103 | * 104 | * @return -1 If this one is greater, 0 if equal, or 1 if $version is greater. 105 | * 106 | * @api 107 | */ 108 | public function compareTo($version) 109 | { 110 | $major = $version->getMajor(); 111 | $minor = $version->getMinor(); 112 | $patch = $version->getPatch(); 113 | $pre = $version->getPreRelease(); 114 | $build = $version->getBuild(); 115 | 116 | switch (true) { 117 | case ($this->major < $major): 118 | return 1; 119 | case ($this->major > $major): 120 | return -1; 121 | case ($this->minor > $minor): 122 | return -1; 123 | case ($this->minor < $minor): 124 | return 1; 125 | case ($this->patch > $patch): 126 | return -1; 127 | case ($this->patch < $patch): 128 | return 1; 129 | // @codeCoverageIgnoreStart 130 | } 131 | // @codeCoverageIgnoreEnd 132 | 133 | if ($pre || $this->pre) { 134 | if (empty($this->pre) && $pre) { 135 | return -1; 136 | } 137 | 138 | if ($this->pre && empty($pre)) { 139 | return 1; 140 | } 141 | 142 | if (0 !== ($weight = $this->precedence($this->pre, $pre))) { 143 | return $weight; 144 | } 145 | } 146 | 147 | if ($build || $this->build) { 148 | if ((null === $this->build) && $build) { 149 | return 1; 150 | } 151 | 152 | if ($this->build && (null === $build)) { 153 | return -1; 154 | } 155 | 156 | return $this->precedence($this->build, $build); 157 | } 158 | 159 | return 0; 160 | } 161 | 162 | /** 163 | * Creates a new Version instance. 164 | * 165 | * @param string $string The string representation. 166 | * 167 | * @return Version The Version instance. 168 | * 169 | * @api 170 | */ 171 | public static function create($string = '') 172 | { 173 | return new static($string); 174 | } 175 | 176 | /** 177 | * Checks if the version is equal to the given one. 178 | * 179 | * @param Version $version The version to compare against. 180 | * 181 | * @return boolean TRUE if equal, FALSE if not. 182 | * 183 | * @api 184 | */ 185 | public function isEqualTo(Version $version) 186 | { 187 | return ((string)$this == (string)$version); 188 | } 189 | 190 | /** 191 | * Checks if this version is greater than the given one. 192 | * 193 | * @param Version $version The version to compare against. 194 | * 195 | * @return boolean TRUE if greater, FALSE if not. 196 | */ 197 | public function isGreaterThan(Version $version) 198 | { 199 | return (0 > $this->compareTo($version)); 200 | } 201 | 202 | /** 203 | * Checks if this version is less than the given one. 204 | * 205 | * @param Version $version The version to compare against. 206 | * 207 | * @return boolean TRUE if less than, FALSE if not. 208 | * 209 | * @api 210 | */ 211 | public function isLessThan(Version $version) 212 | { 213 | return (0 < $this->compareTo($version)); 214 | } 215 | 216 | /** 217 | * Checks if the version is for a stable release. 218 | * 219 | * @return boolean TRUE if stable, FALSE if not. 220 | */ 221 | public function isStable() 222 | { 223 | return empty($this->pre); 224 | } 225 | 226 | /** 227 | * Checks if the string is a valid string representation of a version. 228 | * 229 | * @param string $string The string. 230 | * 231 | * @return boolean TRUE if valid, FALSE if not. 232 | * 233 | * @api 234 | */ 235 | public static function isValid($string) 236 | { 237 | return (bool) preg_match(static::REGEX, $string); 238 | } 239 | 240 | /** 241 | * Returns the build version information. 242 | * 243 | * @return array|null The build version information. 244 | * 245 | * @api 246 | */ 247 | public function getBuild() 248 | { 249 | return $this->build; 250 | } 251 | 252 | /** 253 | * Returns the pre-release version information. 254 | * 255 | * @return array|null The pre-release version information. 256 | * 257 | * @api 258 | */ 259 | public function getPreRelease() 260 | { 261 | return $this->pre; 262 | } 263 | 264 | /** 265 | * Returns the major version number. 266 | * 267 | * @return integer The major version number. 268 | * 269 | * @api 270 | */ 271 | public function getMajor() 272 | { 273 | return $this->major; 274 | } 275 | 276 | /** 277 | * Returns the minor version number. 278 | * 279 | * @return integer The minor version number. 280 | * 281 | * @api 282 | */ 283 | public function getMinor() 284 | { 285 | return $this->minor; 286 | } 287 | 288 | /** 289 | * Returns the patch version number. 290 | * 291 | * @api 292 | * @return integer The patch version number. 293 | */ 294 | public function getPatch() 295 | { 296 | return $this->patch; 297 | } 298 | 299 | /** 300 | * Sets the build version information. 301 | * 302 | * @param array|integer|string $build The build version information. 303 | * 304 | * @api 305 | */ 306 | public function setBuild($build) 307 | { 308 | $this->build = array_values((array)$build); 309 | 310 | array_walk( 311 | $this->build, 312 | function (&$v) { 313 | if (preg_match('/^[0-9]+$/', $v)) { 314 | $v = (int)$v; 315 | } 316 | } 317 | ); 318 | } 319 | 320 | /** 321 | * Sets the pre-release version information. 322 | * 323 | * @param array|integer|string $pre The pre-release version information. 324 | * 325 | * @api 326 | */ 327 | public function setPreRelease($pre) 328 | { 329 | $this->pre = array_values((array)$pre); 330 | 331 | array_walk( 332 | $this->pre, 333 | function (&$v) { 334 | if (preg_match('/^[0-9]+$/', $v)) { 335 | $v = (int)$v; 336 | } 337 | } 338 | ); 339 | } 340 | 341 | /** 342 | * Sets the major version number. 343 | * 344 | * @param integer|string $major The major version number. 345 | * 346 | * @api 347 | */ 348 | public function setMajor($major) 349 | { 350 | $this->major = (int)$major; 351 | } 352 | 353 | /** 354 | * Sets the minor version number. 355 | * 356 | * @param integer|string $minor The minor version number. 357 | * 358 | * @api 359 | */ 360 | public function setMinor($minor) 361 | { 362 | $this->minor = (int)$minor; 363 | } 364 | 365 | /** 366 | * Sets the patch version number. 367 | * 368 | * @param integer|string $patch The patch version number. 369 | * 370 | * @api 371 | */ 372 | public function setPatch($patch) 373 | { 374 | $this->patch = (int)$patch; 375 | } 376 | 377 | /** 378 | * Parses the version string, replacing current any data. 379 | * 380 | * @param string $string The string representation. 381 | * 382 | * @throws InvalidArgumentException If the string is invalid. 383 | */ 384 | protected function parseString($string) 385 | { 386 | $this->build = null; 387 | $this->major = 0; 388 | $this->minor = 0; 389 | $this->patch = 0; 390 | $this->pre = null; 391 | 392 | if (false === static::isValid($string)) { 393 | throw new InvalidArgumentException(sprintf('The version string "%s" is invalid.', $string)); 394 | } 395 | 396 | if (false !== strpos($string, '+')) { 397 | list($string, $build) = explode('+', $string); 398 | 399 | $this->setBuild(explode('.', $build)); 400 | } 401 | 402 | if (false !== strpos($string, '-')) { 403 | list($string, $pre) = explode('-', $string); 404 | 405 | $this->setPreRelease(explode('.', $pre)); 406 | } 407 | 408 | $version = explode('.', $string); 409 | 410 | $this->major = (int)$version[0]; 411 | 412 | if (isset($version[1])) { 413 | $this->minor = (int)$version[1]; 414 | } 415 | 416 | if (isset($version[2])) { 417 | $this->patch = (int)$version[2]; 418 | } 419 | } 420 | 421 | /** 422 | * Checks the precedence of each data set. 423 | * 424 | * @param array $a A data set. 425 | * @param array $b A data set. 426 | * 427 | * @return integer -1 if $a > $b, 0 if $a = $b, 1 if $a < $b. 428 | */ 429 | protected function precedence($a, $b) 430 | { 431 | if (count($a) > count($b)) { 432 | $l = -1; 433 | $r = 1; 434 | $x = $a; 435 | $y = $b; 436 | } else { 437 | $l = 1; 438 | $r = -1; 439 | $x = $b; 440 | $y = $a; 441 | } 442 | 443 | foreach (array_keys($x) as $i) { 444 | if (false === isset($y[$i])) { 445 | return $l; 446 | } 447 | 448 | if ($x[$i] === $y[$i]) { 449 | continue; 450 | } 451 | 452 | $xi = is_integer($x[$i]); 453 | $yi = is_integer($y[$i]); 454 | 455 | if ($xi && $yi) { 456 | return ($x[$i] > $y[$i]) ? $l : $r; 457 | } elseif ((false === $xi) && (false === $yi)) { 458 | return (max($x[$i], $y[$i]) == $x[$i]) ? $l : $r; 459 | } else { 460 | return $xi ? $r : $l; 461 | } 462 | } 463 | 464 | return 0; 465 | } 466 | } 467 | 468 | -------------------------------------------------------------------------------- /src/tests/KevinGH/Version/VersionTest.php: -------------------------------------------------------------------------------- 1 | assertInstanceOf('KevinGH\Version\Version', $version = Version::create('1.0.0')); 21 | 22 | $this->assertEquals(1, $version->getMajor()); 23 | $this->assertEquals(0, $version->getMinor()); 24 | $this->assertEquals(0, $version->getPatch()); 25 | $this->assertNull($version->getPreRelease()); 26 | $this->assertNull($version->getBuild()); 27 | } 28 | 29 | /** 30 | * @dataProvider getGoodVersions 31 | */ 32 | public function testIsValid($string) 33 | { 34 | $this->assertTrue(Version::isValid($string)); 35 | } 36 | 37 | /** 38 | * @dataProvider getBadVersions 39 | */ 40 | public function testIsValidInvalid($string) 41 | { 42 | $this->assertFalse(Version::isValid($string)); 43 | } 44 | 45 | public function testDefaults() 46 | { 47 | $version = new Version; 48 | 49 | $this->assertEquals(0, $version->getMajor()); 50 | $this->assertEquals(0, $version->getMinor()); 51 | $this->assertEquals(0, $version->getPatch()); 52 | $this->assertNull($version->getPreRelease()); 53 | $this->assertNull($version->getBuild()); 54 | } 55 | 56 | /** 57 | * @dataProvider getParseDataSet 58 | */ 59 | public function testParse($input, $expected) 60 | { 61 | $version = new Version($input); 62 | 63 | $this->assertSame($expected['major'], $version->getMajor()); 64 | $this->assertSame($expected['minor'], $version->getMinor()); 65 | $this->assertSame($expected['patch'], $version->getPatch()); 66 | $this->assertSame($expected['pre'], $version->getPreRelease()); 67 | $this->assertSame($expected['build'], $version->getBuild()); 68 | } 69 | 70 | /** 71 | * @expectedException InvalidArgumentException 72 | * @expectedExceptionMessage The version string "a.0.0" is invalid. 73 | */ 74 | public function testParseInvalid() 75 | { 76 | $version = new Version('a.0.0'); 77 | } 78 | 79 | /** 80 | * @dataProvider getCompareDataSet 81 | */ 82 | public function testCompare($left, $right, $result) 83 | { 84 | $left = new Version($left); 85 | $right = new Version($right); 86 | 87 | $this->assertSame($result, $left->compareTo($right)); 88 | } 89 | 90 | /** 91 | * @dataProvider getEqualDataSet 92 | */ 93 | public function testEqualTo($left, $right, $result) 94 | { 95 | $left = new Version($left); 96 | $right = new Version($right); 97 | 98 | $this->assertTrue($left->isEqualTo($right)); 99 | } 100 | 101 | /** 102 | * @dataProvider getGreaterDataSet 103 | */ 104 | public function testGreaterThan($left, $right, $reuslt) 105 | { 106 | $left = new Version($left); 107 | $right = new Version($right); 108 | 109 | $this->assertTrue($left->isGreaterThan($right)); 110 | } 111 | 112 | /** 113 | * @dataProvider getLessDataSet 114 | */ 115 | public function testLessThan($left, $right, $reuslt) 116 | { 117 | $left = new Version($left); 118 | $right = new Version($right); 119 | 120 | $this->assertTrue($left->isLessThan($right)); 121 | } 122 | 123 | /** 124 | * @dataProvider getGoodVersions 125 | */ 126 | public function testStable($version) 127 | { 128 | $stable = !(bool) strpos($version, '-'); 129 | 130 | $version = new Version($version); 131 | 132 | $this->assertSame($stable, $version->isStable()); 133 | } 134 | 135 | /** 136 | * @depends testDefaults 137 | */ 138 | public function testSetMajor() 139 | { 140 | $version = new Version; 141 | 142 | $version->setMajor(1); 143 | 144 | $this->assertSame(1, $version->getMajor()); 145 | } 146 | 147 | /** 148 | * @depends testDefaults 149 | */ 150 | public function testSetMinor() 151 | { 152 | $version = new Version; 153 | 154 | $version->setMinor(1); 155 | 156 | $this->assertSame(1, $version->getMinor()); 157 | } 158 | 159 | /** 160 | * @depends testDefaults 161 | */ 162 | public function testSetPatch() 163 | { 164 | $version = new Version; 165 | 166 | $version->setPatch(1); 167 | 168 | $this->assertSame(1, $version->getPatch()); 169 | } 170 | 171 | public function getBadVersions() 172 | { 173 | return array( 174 | array('x.0.0-0.x.1.b'), 175 | array('0.0.0-'), 176 | array('0.0.0-1.'), 177 | array('1.x.0-0.x.1.b+build.123.abcdef1'), 178 | array('1.0.x-alpha'), 179 | array('1.0.0-!.1'), 180 | array('1.0.0-beta!2'), 181 | array('1.0.0-rc.1!build.1'), 182 | array('1.0.0+'), 183 | array('1.0.0!0.3.7'), 184 | array('1.3.7!build'), 185 | array('1.3.7+build.1.'), 186 | array('1.3.7+build.11!e0f985a') 187 | ); 188 | } 189 | 190 | public function getCompareDataSet() 191 | { 192 | return array_merge($this->getLessDataSet(), $this->getGreaterDataSet(), $this->getEqualDataSet()); 193 | } 194 | 195 | public function getEqualDataSet() 196 | { 197 | return array( 198 | array( 199 | '0.0.0-alpha', 200 | '0.0.0-alpha', 201 | 0 202 | ), 203 | array( 204 | '0.1.0-alpha', 205 | '0.1.0-alpha', 206 | 0 207 | ), 208 | array( 209 | '1.0.0-alpha', 210 | '1.0.0-alpha', 211 | 0 212 | ), 213 | array( 214 | '1.0.0-alpha.1', 215 | '1.0.0-alpha.1', 216 | 0 217 | ), 218 | array( 219 | '1.0.0-beta.2', 220 | '1.0.0-beta.2', 221 | 0 222 | ), 223 | array( 224 | '1.0.0-beta.11', 225 | '1.0.0-beta.11', 226 | 0 227 | ), 228 | array( 229 | '1.0.0-rc.1', 230 | '1.0.0-rc.1', 231 | 0 232 | ), 233 | array( 234 | '1.0.0-rc.1+build.1', 235 | '1.0.0-rc.1+build.1', 236 | 0 237 | ), 238 | array( 239 | '1.0.0', 240 | '1.0.0', 241 | 0 242 | ), 243 | array( 244 | '1.0.0+0.3.7', 245 | '1.0.0+0.3.7', 246 | 0 247 | ), 248 | array( 249 | '1.3.7+build', 250 | '1.3.7+build', 251 | 0 252 | ), 253 | array( 254 | '1.3.7+build.2.b8f12d7', 255 | '1.3.7+build.2.b8f12d7', 256 | 0 257 | ), 258 | array( 259 | '1.3.7+build.11.e0f985a', 260 | '1.3.7+build.11.e0f985a', 261 | 0 262 | ) 263 | ); 264 | } 265 | 266 | public function getLessDataSet() 267 | { 268 | return array( 269 | array( 270 | '0.1.0-alpha.1', 271 | '0.1.1-alpha.1', 272 | 1 273 | ), 274 | array( 275 | '0.1.0-alpha.1', 276 | '1.0.0-alpha.1', 277 | 1 278 | ), 279 | array( 280 | '1.0.0-alpha', 281 | '1.0.0-alpha.1', 282 | 1 283 | ), 284 | array( 285 | '1.0.0-alpha.1', 286 | '1.0.0-alpha.1.1', 287 | 1 288 | ), 289 | array( 290 | '1.0.0-alpha.1', 291 | '1.0.0-beta.2', 292 | 1 293 | ), 294 | array( 295 | '1.0.0-beta.2', 296 | '1.0.0-beta.11', 297 | 1 298 | ), 299 | array( 300 | '1.0.0-beta.11', 301 | '1.0.0-rc.1', 302 | 1 303 | ), 304 | array( 305 | '1.0.0-rc.1', 306 | '1.0.0-rc.1+build.1', 307 | 1 308 | ), 309 | array( 310 | '1.0.0-rc.1+build.1', 311 | '1.0.0', 312 | 1 313 | ), 314 | array( 315 | '1.0.0', 316 | '1.0.0+0.3.7', 317 | 1 318 | ), 319 | array( 320 | '1.0.0+0.3.7', 321 | '1.3.7+build', 322 | 1 323 | ), 324 | array( 325 | '1.3.7+build', 326 | '1.3.7+build.2.b8f12d7', 327 | 1 328 | ), 329 | array( 330 | '1.3.7+build.2.b8f12d7', 331 | '1.3.7+build.11.e0f985a', 332 | 1 333 | ), 334 | array( 335 | '1.3.7+1', 336 | '1.3.7+build.2', 337 | 1 338 | ), 339 | ); 340 | } 341 | 342 | public function getGoodVersions() 343 | { 344 | return array( 345 | array('1.0.0-0.x.1.b'), 346 | array('1.0.0-0.x.1.b+build.123.abcdef1'), 347 | array('1.0.0-alpha'), 348 | array('1.0.0-alpha.1'), 349 | array('1.0.0-beta.2'), 350 | array('1.0.0-beta.11'), 351 | array('1.0.0-rc.1'), 352 | array('1.0.0-rc.1+build.1'), 353 | array('1.0.0'), 354 | array('1.0.0+0.3.7'), 355 | array('1.3.7+build'), 356 | array('1.3.7+build.2.b8f12d7'), 357 | array('1.3.7+build.11.e0f985a') 358 | ); 359 | } 360 | 361 | public function getGreaterDataSet() 362 | { 363 | return array( 364 | array( 365 | '0.1.1-alpha.1', 366 | '0.1.0-alpha.1', 367 | -1 368 | ), 369 | array( 370 | '1.0.0-alpha.1', 371 | '0.1.0-alpha.1', 372 | -1 373 | ), 374 | array( 375 | '1.0.0-alpha.1', 376 | '1.0.0-alpha', 377 | -1 378 | ), 379 | array( 380 | '1.0.0-beta.2', 381 | '1.0.0-alpha.1', 382 | -1 383 | ), 384 | array( 385 | '1.0.0-beta.11', 386 | '1.0.0-beta.2', 387 | -1 388 | ), 389 | array( 390 | '1.0.0-rc.1', 391 | '1.0.0-beta.11', 392 | -1 393 | ), 394 | array( 395 | '1.0.0-rc.1+build.1', 396 | '1.0.0-rc.1', 397 | -1 398 | ), 399 | array( 400 | '1.0.0', 401 | '1.0.0-rc.1+build.1', 402 | -1 403 | ), 404 | array( 405 | '1.0.0+0.3.7', 406 | '1.0.0', 407 | -1 408 | ), 409 | array( 410 | '1.3.7+build', 411 | '1.0.0+0.3.7', 412 | -1 413 | ), 414 | array( 415 | '1.3.7+build.2.b8f12d7', 416 | '1.3.7+build', 417 | -1 418 | ), 419 | array( 420 | '1.3.7+build.11.e0f985a', 421 | '1.3.7+build.2.b8f12d7', 422 | -1 423 | ), 424 | array( 425 | '1.3.7+build.2', 426 | '1.3.7+1', 427 | -1 428 | ), 429 | ); 430 | } 431 | 432 | public function getParseDataSet() 433 | { 434 | return array( 435 | array( 436 | '1.0.0-0.x.1.b', 437 | array( 438 | 'major' => 1, 439 | 'minor' => 0, 440 | 'patch' => 0, 441 | 'pre' => array( 442 | 0, 443 | 'x', 444 | 1, 445 | 'b' 446 | ), 447 | 'build' => null 448 | ) 449 | ), 450 | array( 451 | '1.0.0-0.x.1.b+build.123.abcdef1', 452 | array( 453 | 'major' => 1, 454 | 'minor' => 0, 455 | 'patch' => 0, 456 | 'pre' => array( 457 | 0, 458 | 'x', 459 | 1, 460 | 'b' 461 | ), 462 | 'build' => array( 463 | 'build', 464 | 123, 465 | 'abcdef1' 466 | ) 467 | ) 468 | ), 469 | array( 470 | '1.0.0-alpha', 471 | array( 472 | 'major' => 1, 473 | 'minor' => 0, 474 | 'patch' => 0, 475 | 'pre' => array('alpha'), 476 | 'build' => null 477 | ) 478 | ), 479 | array( 480 | '1.0.0-alpha.1', 481 | array( 482 | 'major' => 1, 483 | 'minor' => 0, 484 | 'patch' => 0, 485 | 'pre' => array( 486 | 'alpha', 487 | 1 488 | ), 489 | 'build' => null 490 | ) 491 | ), 492 | array( 493 | '1.0.0-beta.2', 494 | array( 495 | 'major' => 1, 496 | 'minor' => 0, 497 | 'patch' => 0, 498 | 'pre' => array( 499 | 'beta', 500 | 2 501 | ), 502 | 'build' => null 503 | ) 504 | ), 505 | array( 506 | '1.0.0-beta.11', 507 | array( 508 | 'major' => 1, 509 | 'minor' => 0, 510 | 'patch' => 0, 511 | 'pre' => array( 512 | 'beta', 513 | 11 514 | ), 515 | 'build' => null 516 | ) 517 | ), 518 | array( 519 | '1.0.0-rc.1', 520 | array( 521 | 'major' => 1, 522 | 'minor' => 0, 523 | 'patch' => 0, 524 | 'pre' => array( 525 | 'rc', 526 | 1 527 | ), 528 | 'build' => null 529 | ) 530 | ), 531 | array( 532 | '1.0.0-rc.1+build.1', 533 | array( 534 | 'major' => 1, 535 | 'minor' => 0, 536 | 'patch' => 0, 537 | 'pre' => array( 538 | 'rc', 539 | 1 540 | ), 541 | 'build' => array( 542 | 'build', 543 | 1 544 | ) 545 | ) 546 | ), 547 | array( 548 | '1.0.0', 549 | array( 550 | 'major' => 1, 551 | 'minor' => 0, 552 | 'patch' => 0, 553 | 'pre' => null, 554 | 'build' => null 555 | ) 556 | ), 557 | array( 558 | '1.0.0+0.3.7', 559 | array( 560 | 'major' => 1, 561 | 'minor' => 0, 562 | 'patch' => 0, 563 | 'pre' => null, 564 | 'build' => array( 565 | 0, 566 | 3, 567 | 7 568 | ) 569 | ) 570 | ), 571 | array( 572 | '1.3.7+build', 573 | array( 574 | 'major' => 1, 575 | 'minor' => 3, 576 | 'patch' => 7, 577 | 'pre' => null, 578 | 'build' => array('build') 579 | ) 580 | ), 581 | array( 582 | '1.3.7+build.2.b8f12d7', 583 | array( 584 | 'major' => 1, 585 | 'minor' => 3, 586 | 'patch' => 7, 587 | 'pre' => null, 588 | 'build' => array( 589 | 'build', 590 | 2, 591 | 'b8f12d7' 592 | ) 593 | ) 594 | ), 595 | array( 596 | '1.3.7+build.11.e0f985a', 597 | array( 598 | 'major' => 1, 599 | 'minor' => 3, 600 | 'patch' => 7, 601 | 'pre' => null, 602 | 'build' => array( 603 | 'build', 604 | 11, 605 | 'e0f985a' 606 | ) 607 | ) 608 | ) 609 | ); 610 | } 611 | } 612 | 613 | -------------------------------------------------------------------------------- /src/tests/load.php: -------------------------------------------------------------------------------- 1 |