public function testCompoundExpression()
 {
     $expression = new CompoundExpression(CompoundExpression::DISJUNCTIVE, [new Primitive('1.0.0', Primitive::OPERATOR_EQ), '>2.3.4']);
     $this->assertTrue($expression->matches(Version::fromString('1.0.0')));
     $this->assertTrue($expression->matches(Version::fromString('3.0.0')));
     $this->assertTrue($expression->matches(Version::fromString('2.3.5')));
     $this->assertFalse($expression->matches(Version::fromString('1.0.0-alpha')));
     $this->assertFalse($expression->matches(Version::fromString('2.3.4')));
     $this->assertFalse($expression->matches(Version::fromString('0.9.9')));
 }
Beispiel #2
0
 public function generateTildePrimitives(Version $lbound, array $ubound, array $nrs)
 {
     if (count($nrs) == 1) {
         $upper = Version::fromString($nrs[0] + 1);
     } else {
         ++$nrs[1];
         $upper = Version::fromString(implode('.', array_slice($nrs, 0, 2)));
     }
     return self::between($lbound, $ubound ? Version::highest($upper, Version::fromString(implode('.', $ubound))) : $upper);
 }
Beispiel #3
0
 public function expressionDataProvider()
 {
     $data = json_decode(file_get_contents(FIXTURES_PATH . '/Expressions/ExpressionMatches.json'), JSON_OBJECT_AS_ARRAY);
     foreach ($data as $expression => $tests) {
         foreach ($tests as $type => $versions) {
             foreach ($versions as $version) {
                 (yield "{$expression} {$type} {$version}" => [$expression, $type, Version::fromString($version)]);
             }
         }
     }
 }
Beispiel #4
0
 public function testVersionList()
 {
     $list = new VersionList();
     foreach ($this->random as $item) {
         $list[] = $item;
     }
     $list->sort();
     $this->assertEquals($this->normalizedSorted, $list->getStringValues());
     $this->assertEquals($this->normalizedSorted[5], $list[5]);
     $list->each(function (Version $version) {
         /** @var Version $last */
         static $last;
         if ($last) {
             $this->assertTrue($last->lessThan($version));
         }
         $last = $version;
     });
     $list->rsort();
     $this->assertEquals($this->normalizedReverse, $list->getStringValues());
     $this->assertEquals($this->normalizedReverse[3], $list[3]);
     $list->each(function (Version $version) {
         /** @var Version $last */
         static $last;
         if ($last) {
             $this->assertTrue($last->greaterThanOrEqual($version));
         }
         $last = $version;
     });
     // Iterable behaviours
     foreach ($list as $idx => $version) {
         $this->assertEquals($this->normalizedReverse[$idx], (string) $version);
     }
     // Count/unset behaviours on arrays
     $this->assertEquals(count($this->sorted), count($list));
     $sampleKey = (int) (count($this->sorted) / 2);
     $this->assertTrue(isset($list[$sampleKey]));
     unset($list[$sampleKey]);
     $this->assertEquals(count($this->sorted) - 1, count($list));
     $before = $list->getStringValues();
     $list[3] = Version::fromString('6.8.4');
     $before[3] = '6.8.4';
     $this->assertSame($before, $list->getStringValues());
 }
Beispiel #5
0
 /**
  * {@inheritdoc}
  */
 public function offsetSet($offset, $value)
 {
     if (is_null($offset)) {
         $this->data[] = [Version::fromString($value)];
     } else {
         $this->data[$offset] = [Version::fromString($value)];
     }
 }
Beispiel #6
0
 /**
  * @param mixed $offset
  * @param mixed $value
  */
 public function offsetSet($offset, $value)
 {
     $version = $offset instanceof Version ? $offset : Version::fromString($offset);
     $this->data[(string) $offset] = [$version, $value];
 }
Beispiel #7
0
 /**
  * Splits a single partial into bounds if wildcards are included.
  *
  * @param string $partial
  * @param string $qualifier
  * @return array
  */
 private static function expandXRs($partial, $qualifier)
 {
     $xrs = explode('.', $partial);
     if ($wildcard = array_search('*', $xrs, true)) {
         $xrs = array_slice($xrs, 0, $wildcard);
     } elseif (count($xrs) < 3) {
         $wildcard = count($xrs);
     } else {
         return [Version::fromString($partial . $qualifier), [], $xrs];
     }
     $low = $high = array_pad($xrs, 3, 0);
     ++$high[$wildcard - 1];
     return [Version::fromString(implode('.', $low) . $qualifier), $high, $xrs];
 }
Beispiel #8
0
 /**
  * @return Primitive A primitive matching all versions.
  */
 public static function getWildcard()
 {
     return new self(Version::fromString('0'), self::OPERATOR_LT, true);
 }
Beispiel #9
0
 public function comparisonProvider()
 {
     $versions = json_decode(file_get_contents(FIXTURES_PATH . '/Semver2/IncrementalVersions.json'), JSON_OBJECT_AS_ARRAY);
     for ($i = 0; $i < count($versions) - 1; ++$i) {
         $low = $versions[$i];
         $high = $versions[$i + 1];
         (yield "{$low} < {$high}" => [Version::fromString($low), Version::fromString($high)]);
     }
 }
Beispiel #10
0
 /**
  * @expectedException \Omines\Semver\Exception\SemverException
  * @expectedExceptionMessage Invalid primitive operator "invalid"
  */
 public function testInvalidOperatorThrows()
 {
     $primitive = new Primitive('1.0.0', 'invalid');
     $primitive->matches(Version::fromString('1.2.0'));
 }