public function compareMethodArraysProvider()
 {
     return ['VersionComponent[]' => [[VersionComponent::parse("0-4-g"), VersionComponent::parse("1-4-g"), VersionComponent::parse("2-3-g"), VersionComponent::parse("2-3-g726356"), VersionComponent::parse("2-4-g"), VersionComponent::parse("4-3-g"), VersionComponent::parse("4-3-gsh4hajk7"), VersionComponent::parse("4-3-gsh4hbjk7"), VersionComponent::parse("11-4-g")]], 'VersionComponent[] + integer[]' => [[1, new VersionComponent(2, '-alpha')]], 'VersionComponent[] + string[]' => [[new VersionComponent(1, '-alpha'), '1-beta']], 'VersionComponent[] + string[] (non parseable)' => [['----------', new VersionComponent()]], 'VersionComponent[] + array[]' => [[[], [0, 1, 0], new VersionComponent(1, '-alpha')]]];
 }
 /**
  * @coverage VersionComponent::isNull
  * @coverage VersionComponent::isNotNull
  * @coverage VersionComponent::isDefault
  * @coverage VersionComponent::isNotDefault
  * @dataProvider nullOrDefaultStatesProvider
  */
 public function testCanCheckIfVersionComponentIsInDefaultOrNullState($expected, VersionComponent $versionComponent)
 {
     static $format = '$versionComponent->{method}(); // {actual}';
     $actuals['isDefault'] = $versionComponent->isDefault();
     $actuals['isNotDefault'] = $versionComponent->isNotDefault();
     $actuals['isNull'] = $versionComponent->isNull();
     $actuals['isNotNull'] = $versionComponent->isNotNull();
     $messages = [];
     foreach ($actuals as $method => $actual) {
         $messages[$method] = String::format($format, ['method' => $method, 'actual' => static::export($actual)]);
     }
     foreach ($actuals as $method => $actual) {
         // Pre-tests for returning type
         $this->assertInternalType('boolean', $actual, $messages[$method] . ' # Should return a boolean #');
     }
     // Pre-tests for different values
     $this->assertNotEquals($actuals['isDefault'], $actuals['isNotDefault'], $messages['isDefault'] . PHP_EOL . $messages['isNotDefault']);
     $this->assertNotEquals($actuals['isNull'], $actuals['isNotNull'], $messages['isNull'] . PHP_EOL . $messages['isNotNull']);
     // Test expected
     if ($expected === 'default') {
         $this->assertTrue($actuals['isDefault'], $messages['isDefault']);
         // Can't be null AND default
         $this->assertNotEquals($actuals['isNull'], $actuals['isDefault'], '#Can\'t be both, DEFAULT and NULL, at the same time' . PHP_EOL . $messages['isDefault'] . PHP_EOL . $messages['isNull']);
     } elseif ($expected === 'null') {
         $this->assertTrue($actuals['isNull'], $messages['isNull']);
         // Can't be null AND default
         $this->assertNotEquals($actuals['isNull'], $actuals['isDefault'], '#Can\'t be both, NULL and DEFAULT, at the same time' . PHP_EOL . $messages['isNull'] . PHP_EOL . $messages['isDefault']);
     } else {
         $this->assertTrue($actuals['isNotDefault'], $messages['isNotDefault']);
         $this->assertTrue($actuals['isNotNull'], $messages['isNotNull']);
     }
 }
Esempio n. 3
0
 /**
  * Convierte una cadena a su representación del tipo Version.
  *
  * @param Version|string|int|float|array $value Objeto a convertir.
  *
  * @return Version Objeto convertido desde $value.
  * */
 public static function parse($value)
 {
     if ($value instanceof Version) {
         return $value;
     }
     $version = [];
     // Try to convert into an array
     if (is_integer($value)) {
         // Integer for major value
         $version = [$value, 0];
     } elseif (is_float($value)) {
         // Integer part as major, and decimal part as minor
         $version = sprintf("%F", $value);
         $version = explode('.', $version);
     } elseif (is_array($value)) {
         // Implode first 4 places for major, minor, build and revision respectivally.
         $version = array_slice($value, 0, 4);
     } elseif (is_string($value)) {
         $version = explode('.', $value);
     } else {
         $msg = nml_msg('Unable to parse. Argument passed has an invalid type: "{0}".', typeof($value));
         throw new InvalidArgumentException($msg);
     }
     // $value ya debería ser un array.
     $c = count($version);
     if ($c > 4 || $c < 2) {
         $msg = nml_msg('Unable to parse. Argument passed has an invalid format: "{0}".', $value);
         //var_dump($version);
         throw new InvalidArgumentException($msg);
     }
     $major = (int) $version[0];
     $minor = (int) $version[1];
     $build = null;
     $revision = null;
     if (count($version) >= 3) {
         $build = VersionComponent::Parse($version[2]);
         if (count($version) == 4) {
             $revision = VersionComponent::Parse($version[3]);
         }
     }
     return new Version($major, $minor, $build, $revision);
 }