Ejemplo n.º 1
0
 /**
  * @dataProvider getParseDataSet
  */
 public function testParse($input, $expected)
 {
     $version = new Version($input);
     $this->assertSame($expected['major'], $version->getMajor());
     $this->assertSame($expected['minor'], $version->getMinor());
     $this->assertSame($expected['patch'], $version->getPatch());
     $this->assertSame($expected['pre'], $version->getPreRelease());
     $this->assertSame($expected['build'], $version->getBuild());
 }
Ejemplo n.º 2
0
 /**
  * Compares one version to another.
  *
  * @param Version $version Another version.
  *
  * @return -1 If this one is greater, 0 if equal, or 1 if $version is greater.
  *
  * @api
  */
 public function compareTo($version)
 {
     $major = $version->getMajor();
     $minor = $version->getMinor();
     $patch = $version->getPatch();
     $pre = $version->getPreRelease();
     $build = $version->getBuild();
     switch (true) {
         case $this->major < $major:
             return 1;
         case $this->major > $major:
             return -1;
         case $this->minor > $minor:
             return -1;
         case $this->minor < $minor:
             return 1;
         case $this->patch > $patch:
             return -1;
         case $this->patch < $patch:
             return 1;
             // @codeCoverageIgnoreStart
     }
     // @codeCoverageIgnoreEnd
     if ($pre || $this->pre) {
         if (empty($this->pre) && $pre) {
             return -1;
         }
         if ($this->pre && empty($pre)) {
             return 1;
         }
         if (0 !== ($weight = $this->precedence($this->pre, $pre))) {
             return $weight;
         }
     }
     if ($build || $this->build) {
         if (null === $this->build && $build) {
             return 1;
         }
         if ($this->build && null === $build) {
             return -1;
         }
         return $this->precedence($this->build, $build);
     }
     return 0;
 }