Пример #1
0
 function it_should_be_compared_correctly_with_another_version(VersionInterface $smaller, VersionInterface $equal, VersionInterface $bigger)
 {
     $smaller->getMajorVersion()->willReturn(0);
     $smaller->getMinorVersion()->willReturn(5);
     $smaller->getReleaseVersion()->willReturn(3);
     $equal->getMajorVersion()->willReturn(2);
     $equal->getMinorVersion()->willReturn(0);
     $equal->getReleaseVersion()->willReturn(1);
     $bigger->getMajorVersion()->willReturn(4);
     $bigger->getMinorVersion()->willReturn(3);
     $bigger->getReleaseVersion()->willReturn(0);
     $this->compare($smaller)->shouldReturn(1);
     $this->compare($equal)->shouldReturn(0);
     $this->compare($bigger)->shouldReturn(-1);
 }
Пример #2
0
 /**
  * Compare with another version
  *
  * @param VersionInterface $version
  *
  * @return int (-1,0,1)
  */
 public function compare(VersionInterface $version)
 {
     if ($this->getMajorVersion() < $version->getMajorVersion()) {
         return -1;
     } elseif ($this->getMajorVersion() > $version->getMajorVersion()) {
         return 1;
     } else {
         if ($this->getMinorVersion() < $version->getMinorVersion()) {
             return -1;
         } elseif ($this->getMinorVersion() > $version->getMinorVersion()) {
             return 1;
         } else {
             if ($this->getReleaseVersion() < $version->getReleaseVersion()) {
                 return -1;
             } elseif ($this->getReleaseVersion() > $version->getReleaseVersion()) {
                 return 1;
             } else {
                 return 0;
             }
         }
     }
 }